Skip to content

Commit

Permalink
Enable discard/undiscard entry
Browse files Browse the repository at this point in the history
- Disallow duplicate entries creation.
- Remove selection of entry after creation from auto draft entries
  • Loading branch information
subinasr authored and AdityaKhatri committed Dec 18, 2023
1 parent 531ea17 commit b58b6bd
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 81 deletions.
1 change: 1 addition & 0 deletions app/components/entry/EntryInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,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
3 changes: 3 additions & 0 deletions app/components/entry/EntryInput/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
&.compact {
border-bottom: var(--dui-width-separator-thin) solid var(--dui-color-separator);
}
&.horizontal {
border-bottom: unset;
}
}

.secondary-tagging {
Expand Down
37 changes: 4 additions & 33 deletions app/views/EntryEdit/LeftPane/AssistItem/AssistPopup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@ import {
Kraken,
Container,
Message,
QuickActionButton,
} from '@the-deep/deep-ui';
import {
SetValueArg,
Error,
} from '@togglecorp/toggle-form';
import {
IoClose,
} from 'react-icons/io5';
import { FiEdit2 } from 'react-icons/fi';

import EntryInput from '#components/entry/EntryInput';
import { GeoArea } from '#components/GeoMultiSelectInput';
Expand All @@ -34,12 +29,9 @@ interface Props<NAME extends string | number | undefined> {
value: PartialEntryType;
onChange: (val: SetValueArg<PartialEntryType>, name: NAME) => void;
error: Error<PartialEntryType> | undefined;
onEntryCreateButtonClick: () => void;
variant?: 'normal' | 'compact' | 'nlp';
// NOTE: Normal entry creation refers to entry created without use of
// recommendations
onNormalEntryCreateButtonClick: () => void;
onEntryDiscardButtonClick: () => void;
geoAreaOptions: GeoArea[] | undefined | null;
onGeoAreaOptionsChange: React.Dispatch<React.SetStateAction<GeoArea[] | undefined | null>>;
predictionsLoading?: boolean;
Expand All @@ -50,6 +42,8 @@ interface Props<NAME extends string | number | undefined> {
messageText: string | undefined;
excerptShown?: boolean;
displayHorizontally?: boolean;

footerActions: React.ReactNode;
}

function AssistPopup<NAME extends string | number | undefined>(props: Props<NAME>) {
Expand All @@ -63,9 +57,6 @@ function AssistPopup<NAME extends string | number | undefined>(props: Props<NAME
name,
error,
frameworkDetails,
onEntryCreateButtonClick,
onNormalEntryCreateButtonClick,
onEntryDiscardButtonClick,
geoAreaOptions,
onGeoAreaOptionsChange,
predictionsLoading,
Expand All @@ -75,6 +66,7 @@ function AssistPopup<NAME extends string | number | undefined>(props: Props<NAME
recommendations,
excerptShown = false,
displayHorizontally = false,
footerActions,
} = props;

const allWidgets = useMemo(() => {
Expand All @@ -99,28 +91,7 @@ function AssistPopup<NAME extends string | number | undefined>(props: Props<NAME
// heading="Assisted Tagging"
headingSize="extraSmall"
spacing="compact"
footerQuickActions={(
<>
<QuickActionButton
name={undefined}
onClick={onEntryDiscardButtonClick}
title="Discard Entry"
variant="nlp-secondary"
>
<IoClose />
</QuickActionButton>
<QuickActionButton
name={undefined}
onClick={(predictionsErrored || !!messageText)
? onNormalEntryCreateButtonClick : onEntryCreateButtonClick}
disabled={predictionsLoading}
variant="nlp-primary"
title="Create Entry"
>
<FiEdit2 />
</QuickActionButton>
</>
)}
footerQuickActions={footerActions}
contentClassName={styles.body}
>
{isMessageShown ? (
Expand Down
39 changes: 35 additions & 4 deletions app/views/EntryEdit/LeftPane/AssistItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Container,
} from '@the-deep/deep-ui';
import { IoClose } from 'react-icons/io5';
import { FiEdit2 } from 'react-icons/fi';

import { GeoArea } from '#components/GeoMultiSelectInput';
import brainIcon from '#resources/img/brain.svg';
Expand Down Expand Up @@ -152,7 +153,11 @@ interface Props {
className?: string;
text: string;
onAssistedEntryAdd: (
(newEntry: EntryInput, locations?: GeoArea[]) => void
(
newEntry: EntryInput,
locations?: GeoArea[],
selectCreatedEntry?: boolean,
) => void
) | undefined;
frameworkDetails?: Framework;
leadId: string;
Expand Down Expand Up @@ -641,6 +646,7 @@ function AssistItem(props: Props) {
draftEntry: data?.project?.assistedTagging?.draftEntry?.id,
},
geoAreaOptions ?? undefined,
true,
);
}
},
Expand Down Expand Up @@ -746,9 +752,6 @@ function AssistItem(props: Props) {
leadId={leadId}
hints={allHints}
recommendations={allRecommendations}
onEntryDiscardButtonClick={handleDiscardButtonClick}
onEntryCreateButtonClick={handleEntryCreateButtonClick}
onNormalEntryCreateButtonClick={handleNormalEntryCreateButtonClick}
geoAreaOptions={geoAreaOptions}
onGeoAreaOptionsChange={setGeoAreaOptions}
predictionsLoading={
Expand All @@ -758,6 +761,34 @@ function AssistItem(props: Props) {
}
predictionsErrored={!!fetchErrors || !!createErrors || isErrored}
messageText={messageText}
footerActions={(
<>
<QuickActionButton
name={undefined}
onClick={handleDiscardButtonClick}
title="Discard Entry"
variant="nlp-secondary"
>
<IoClose />
</QuickActionButton>
<QuickActionButton
name={undefined}
onClick={
(
(!!fetchErrors || !!createErrors || isErrored)
|| !!messageText
)
? handleNormalEntryCreateButtonClick
: handleEntryCreateButtonClick
}
disabled={predictionsLoading}
variant="nlp-primary"
title="Create Entry"
>
<FiEdit2 />
</QuickActionButton>
</>
)}
/>
)}
</QuickActionDropdownMenu>
Expand Down
Loading

0 comments on commit b58b6bd

Please sign in to comment.