-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: UILD-299: STORY: Repeatable fields | Delete function (#38)
* feat: UILD-299: STORY: Repeatable fields | Delete function * minor refactor * unit tests
- Loading branch information
Showing
24 changed files
with
425 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,38 @@ | ||
import { useRecoilState, useSetRecoilState } from 'recoil'; | ||
import state from '@state'; | ||
import { useServicesContext } from './useServicesContext'; | ||
import { deleteFromSetImmutable } from '@common/helpers/common.helper'; | ||
|
||
export const useProfileSchema = () => { | ||
const { selectedEntriesService, schemaWithDuplicatesService } = useServicesContext() as Required<ServicesParams>; | ||
const [schema, setSchema] = useRecoilState(state.config.schema); | ||
const setSelectedEntries = useSetRecoilState(state.config.selectedEntries); | ||
const setClonePrototypes = useSetRecoilState(state.config.clonePrototypes); | ||
const setCollapsibleEntries = useSetRecoilState(state.ui.collapsibleEntries); | ||
const setIsEdited = useSetRecoilState(state.status.recordIsEdited); | ||
const setUserValues = useSetRecoilState(state.inputs.userValues); | ||
|
||
const getSchemaWithCopiedEntries = (entry: SchemaEntry, selectedEntries: string[]) => { | ||
selectedEntriesService.set(selectedEntries); | ||
schemaWithDuplicatesService.set(schema); | ||
schemaWithDuplicatesService.duplicateEntry(entry); | ||
const newUuid = schemaWithDuplicatesService.duplicateEntry(entry); | ||
|
||
setSelectedEntries(selectedEntriesService.get()); | ||
setClonePrototypes(prev => [...prev, entry.uuid]); | ||
setCollapsibleEntries(prev => new Set(newUuid ? [...prev, entry.uuid, newUuid] : [...prev, entry.uuid])); | ||
setSchema(schemaWithDuplicatesService.get()); | ||
|
||
setIsEdited(true); | ||
}; | ||
|
||
const getSchemaWithDeletedEntries = (entry: SchemaEntry) => { | ||
schemaWithDuplicatesService.set(schema); | ||
const deletedUuids = schemaWithDuplicatesService.deleteEntry(entry); | ||
|
||
setCollapsibleEntries(prev => deleteFromSetImmutable(prev, [entry.uuid])); | ||
setSchema(schemaWithDuplicatesService.get()); | ||
setUserValues(prev => Object.fromEntries(Object.entries(prev).filter(([key]) => !deletedUuids?.includes(key)))); | ||
|
||
setIsEdited(true); | ||
}; | ||
|
||
return { getSchemaWithCopiedEntries }; | ||
return { getSchemaWithCopiedEntries, getSchemaWithDeletedEntries }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,41 @@ | ||
import { FC, memo } from 'react'; | ||
import classNames from 'classnames'; | ||
import { Button, ButtonType } from '@components/Button'; | ||
import { IS_DISABLED_FOR_ALPHA } from '@common/constants/feature.constants'; | ||
import Plus16 from '@src/assets/plus-16.svg?react'; | ||
import Trash16 from '@src/assets/trash-16.svg?react'; | ||
import { getHtmlIdForSchemaControl } from '@common/helpers/schema.helper'; | ||
import { SchemaControlType } from '@common/constants/uiControls.constants'; | ||
import './DuplicateGroup.scss'; | ||
|
||
interface Props { | ||
onClick?: VoidFunction; | ||
onClickDuplicate?: VoidFunction; | ||
onClickDelete?: VoidFunction; | ||
hasDeleteButton?: boolean; | ||
deleteDisabled?: boolean; | ||
className?: string; | ||
htmlId?: string; | ||
} | ||
|
||
export const DuplicateGroup: FC<Props> = memo(({ onClick, hasDeleteButton = true, className, htmlId }) => ( | ||
<div className={classNames(['duplicate-group', className])}> | ||
<Button | ||
data-testid={getHtmlIdForSchemaControl(SchemaControlType.Duplicate, htmlId)} | ||
type={ButtonType.Icon} | ||
onClick={onClick} | ||
> | ||
<Plus16 /> | ||
</Button> | ||
{hasDeleteButton && ( | ||
export const DuplicateGroup: FC<Props> = memo( | ||
({ onClickDuplicate, onClickDelete, hasDeleteButton = true, className, htmlId, deleteDisabled = true }) => ( | ||
<div className={classNames(['duplicate-group', className])}> | ||
<Button | ||
data-testid={getHtmlIdForSchemaControl(SchemaControlType.RemoveDuplicate, htmlId)} | ||
data-testid={getHtmlIdForSchemaControl(SchemaControlType.Duplicate, htmlId)} | ||
type={ButtonType.Icon} | ||
disabled={IS_DISABLED_FOR_ALPHA} | ||
onClick={onClickDuplicate} | ||
> | ||
<Trash16 /> | ||
<Plus16 /> | ||
</Button> | ||
)} | ||
</div> | ||
)); | ||
{hasDeleteButton && ( | ||
<Button | ||
data-testid={getHtmlIdForSchemaControl(SchemaControlType.RemoveDuplicate, htmlId)} | ||
type={ButtonType.Icon} | ||
disabled={deleteDisabled} | ||
onClick={onClickDelete} | ||
> | ||
<Trash16 /> | ||
</Button> | ||
)} | ||
</div> | ||
), | ||
); |
Oops, something went wrong.