Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/entries list #2799

Closed
wants to merge 11 commits into from
9 changes: 8 additions & 1 deletion app/components/entry/EntryInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ interface EntryInputProps<T extends string | number | undefined> {
allWidgets: Widget[] | undefined | null;
rightComponent?: React.ReactNode;
noPaddingInWidgetContainer?: boolean;

excerptShown?: boolean;
displayHorizontally?: boolean;
}

function EntryInput<T extends string | number | undefined>(props: EntryInputProps<T>) {
Expand Down Expand Up @@ -111,6 +114,8 @@ function EntryInput<T extends string | number | undefined>(props: EntryInputProp
onApplyToAll,
rightComponent,
noPaddingInWidgetContainer = false,
excerptShown = false,
displayHorizontally = false,
} = props;

const error = getErrorObject(riskyError);
Expand Down Expand Up @@ -194,11 +199,12 @@ function EntryInput<T extends string | number | undefined>(props: EntryInputProp
className={_cs(
className,
compactMode && styles.compact,
displayHorizontally && styles.horizontal,
styles.entryInput,
)}
>
<NonFieldError error={error} />
{!compactMode && (
{(!compactMode || excerptShown) && (
<Container
className={styles.excerpt}
heading={(
Expand Down Expand Up @@ -244,6 +250,7 @@ function EntryInput<T extends string | number | undefined>(props: EntryInputProp
styles.section,
sectionContainerClassName,
compactMode && styles.compact,
displayHorizontally && styles.horizontal,
)}
renderer={CompactSection}
keySelector={sectionKeySelector}
Expand Down
11 changes: 11 additions & 0 deletions app/components/entry/EntryInput/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,24 @@
}
}

&.horizontal {
flex-direction: row;
.excerpt {
width: 100%;
max-width: 30rem;
}
}

.section {
background-color: var(--dui-color-foreground);
width: var(--inner-width);

&.compact {
border-bottom: var(--dui-width-separator-thin) solid var(--dui-color-separator);
}
&.horizontal {
border-bottom: unset;
}
}

.secondary-tagging {
Expand Down
2 changes: 2 additions & 0 deletions app/components/general/ExportHistory/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ const PROJECT_EXPORTS = gql`
widgetKey
}
excelDecoupled
dateFormat
reportCitationStyle
reportExportingWidgets
reportLevels {
id
Expand Down
2 changes: 1 addition & 1 deletion app/components/leadFilters/SourcesAppliedFilters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function SourcesAppliedFilters(props: Props) {
keySelector={organizationKeySelector}
/>
<DismissableListOutput
label="Source Organization"
label="Publishing Organization"
name="sourceOrganizations"
onDismiss={onChange}
value={value.sourceOrganizations}
Expand Down
2 changes: 1 addition & 1 deletion app/components/leadFilters/SourcesFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ function SourcesFilter(props: Props) {
options={sourceOrganizationOptions}
onOptionsChange={setSourceOrganizationOptions}
disabled={disabled || optionsLoading}
label="Source Organization"
label="Publishing Organization"
error={getErrorString(error?.sourceOrganizations)}
usedInProject={projectId}
/>
Expand Down
145 changes: 145 additions & 0 deletions app/components/selections/FrameworkTagSelectInput/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import React, { useMemo, useCallback } from 'react';
import {
Button,
BadgeInput,
BadgeInputProps,
} from '@the-deep/deep-ui';
import { useQuery, gql } from '@apollo/client';

import {
FrameworkTagOptionsQuery,
FrameworkTagOptionsQueryVariables,
} from '#generated/types';

import styles from './styles.css';

const FRAMEWORK_TAGS = gql`
query FrameworkTagOptions(
$page: Int,
$pageSize: Int,
) {
analysisFrameworkTags(
page: $page,
pageSize: $pageSize,
) {
page
pageSize
results {
description
id
title
icon {
name
url
}
}
totalCount
}
}
`;

const PAGE_SIZE = 10;

type BasicFrameworkTag = NonNullable<NonNullable<NonNullable<FrameworkTagOptionsQuery>['analysisFrameworkTags']>['results']>[number];
const keySelector = (item: BasicFrameworkTag) => item.id;
const labelSelector = (item: BasicFrameworkTag) => item.title;
const titleSelector = (item: BasicFrameworkTag) => item.description;
function iconSelector(item: BasicFrameworkTag) {
if (!item.icon?.url) {
return undefined;
}
return (
<img
className={styles.icon}
src={item.icon.url}
alt={item.icon.url}
/>
);
}

type Props<N extends string> = Omit<
BadgeInputProps<BasicFrameworkTag, N, string>,
'options' | 'keySelector' | 'labelSelector'
>;

function FrameworkTagSelectInput<N extends string>(
props: Props<N>,
) {
const variables = useMemo(() => ({
page: 1,
pageSize: PAGE_SIZE,
}), []);

const {
data,
fetchMore,
} = useQuery<FrameworkTagOptionsQuery, FrameworkTagOptionsQueryVariables>(
FRAMEWORK_TAGS,
{
variables,
},
);

const handleShowMoreClick = useCallback(() => {
fetchMore({
variables: {
...variables,
page: (data?.analysisFrameworkTags?.page ?? 1) + 1,
},
updateQuery: (previousResult, { fetchMoreResult }) => {
if (!previousResult.analysisFrameworkTags) {
return previousResult;
}

const oldFrameworkTags = previousResult.analysisFrameworkTags;
const newFrameworkTags = fetchMoreResult?.analysisFrameworkTags;

if (!newFrameworkTags) {
return previousResult;
}

return ({
...previousResult,
analysisFrameworkTags: {
...newFrameworkTags,
results: [
...(oldFrameworkTags.results ?? []),
...(newFrameworkTags.results ?? []),
],
},
});
},
});
}, [
data?.analysisFrameworkTags?.page,
fetchMore,
variables,
]);

return (
<>
<BadgeInput
{...props}
keySelector={keySelector}
labelSelector={labelSelector}
titleSelector={titleSelector}
iconSelector={iconSelector}
options={data?.analysisFrameworkTags?.results ?? undefined}
smallButtons
/>
{(data?.analysisFrameworkTags?.totalCount ?? 0)
> (data?.analysisFrameworkTags?.results ?? []).length && (
<Button
onClick={handleShowMoreClick}
name={undefined}
spacing="compact"
variant="transparent"
>
Show more tags
</Button>
)}
</>
);
}

export default FrameworkTagSelectInput;
5 changes: 5 additions & 0 deletions app/components/selections/FrameworkTagSelectInput/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.icon {
width: auto;
height: 1rem;
object-fit: contain;
}
4 changes: 2 additions & 2 deletions app/types/user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ export interface Assignment {
displayName: string;
email: string;
};
contentObjectDetails: {
contentObjectDetails?: {
id: number;
title: string;
lead?: string;
entry?: string;
};
} | undefined;
isDone: boolean;
contentObjectType: 'lead' | 'entryreviewcomment' | 'entrycomment';
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function Matrix2dTagInput(props: Props) {

const subColumnMappings = useMemo(() => (
mappings?.filter((mappingItem): mappingItem is SubColumnMappingItem => (
mappingItem.association.type === 'SUB_ROW'
mappingItem.association.type === 'SUB_COLUMN'
))
), [
mappings,
Expand Down
Loading