-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add reset to default value button to field title
- Loading branch information
1 parent
b1359b6
commit 3c43351
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...features/nodes/components/flow/nodes/Invocation/fields/FieldResetToDefaultValueButton.tsx
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { IconButton } from '@invoke-ai/ui-library'; | ||
import { useAppDispatch } from 'app/store/storeHooks'; | ||
import { useFieldInputTemplate } from 'features/nodes/hooks/useFieldInputTemplate'; | ||
import { useFieldValue } from 'features/nodes/hooks/useFieldValue'; | ||
import { fieldValueReset } from 'features/nodes/store/nodesSlice'; | ||
import { isEqual } from 'lodash-es'; | ||
import { memo, useCallback, useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { PiArrowCounterClockwiseBold } from 'react-icons/pi'; | ||
|
||
type Props = { | ||
nodeId: string; | ||
fieldName: string; | ||
}; | ||
|
||
const FieldResetToDefaultValueButton = ({ nodeId, fieldName }: Props) => { | ||
const dispatch = useAppDispatch(); | ||
const { t } = useTranslation(); | ||
const value = useFieldValue(nodeId, fieldName); | ||
const fieldTemplate = useFieldInputTemplate(nodeId, fieldName); | ||
const isDisabled = useMemo(() => { | ||
return isEqual(value, fieldTemplate.default); | ||
}, [value, fieldTemplate.default]); | ||
const onClick = useCallback(() => { | ||
dispatch(fieldValueReset({ nodeId, fieldName, value: fieldTemplate.default })); | ||
}, [dispatch, fieldName, fieldTemplate.default, nodeId]); | ||
|
||
return ( | ||
<IconButton | ||
variant="ghost" | ||
tooltip={t('nodes.resetToDefaultValue')} | ||
aria-label={t('nodes.resetToDefaultValue')} | ||
icon={<PiArrowCounterClockwiseBold />} | ||
onClick={onClick} | ||
isDisabled={isDisabled} | ||
pointerEvents="auto" | ||
size="xs" | ||
/> | ||
); | ||
}; | ||
|
||
export default memo(FieldResetToDefaultValueButton); |
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