-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: update template api, handleonnewvalue and handlenodeclass h…
…ooks (#2628) * Added Custom Component URL * Added Post Template Value mutation * Changed HandleOnNewValue hook to ParameterValue mutation * refactored some states * Added NumberInput component to replace input type=number. Added logic to maintain cursor at the same place when editing * Refactored post-template-value to remove all logic * Removed hooks from custom hook and removed mutation definition from parametercomponent * Added mutate-template helper to call debounced mutation * Changed handle new value to use the created function and update as requested. * Removed pDebounce from imports * Refactored FetchDataOnMount to only call mutateTemplate * Refactored ParameterComponent to use the new MutateTemplate and the loading from the mutation * removed handle refresh button * Changed handleOnNewValue to change the value of any parameter of a template field * Changed hooks to receive node instead of data, added HandleOnNewValue hook on tableNodeCellRender * added SetNodeClass to update internal table state of EditNodeModal * Removed other handle new value and node class, updated every component to use the same one * Updated parameter component to use the same nodeclass hook * FIxed hook to only assign value if code is present * Fixed type attribution on useHandleNodeClass
- Loading branch information
1 parent
f701d86
commit b3c1b94
Showing
19 changed files
with
964 additions
and
435 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { | ||
ERROR_UPDATING_COMPONENT, | ||
SAVE_DEBOUNCE_TIME, | ||
TITLE_ERROR_UPDATING_COMPONENT, | ||
} from "@/constants/constants"; | ||
import { | ||
APIClassType, | ||
APITemplateType, | ||
ResponseErrorDetailAPI, | ||
} from "@/types/api"; | ||
import { UseMutationResult } from "@tanstack/react-query"; | ||
import { cloneDeep, debounce } from "lodash"; | ||
|
||
export const mutateTemplate = debounce( | ||
async ( | ||
newValue, | ||
node: APIClassType, | ||
setNodeClass, | ||
postTemplateValue: UseMutationResult< | ||
APITemplateType | undefined, | ||
ResponseErrorDetailAPI, | ||
any | ||
>, | ||
setErrorData, | ||
) => { | ||
try { | ||
const newNode = cloneDeep(node); | ||
const newTemplate = await postTemplateValue.mutateAsync({ | ||
value: newValue, | ||
}); | ||
if (newTemplate) { | ||
newNode.template = newTemplate; | ||
} | ||
setNodeClass(newNode); | ||
} catch (e) { | ||
const error = e as ResponseErrorDetailAPI; | ||
setErrorData({ | ||
title: TITLE_ERROR_UPDATING_COMPONENT, | ||
list: [error.response?.data?.detail || ERROR_UPDATING_COMPONENT], | ||
}); | ||
} | ||
}, | ||
SAVE_DEBOUNCE_TIME, | ||
); |
63 changes: 24 additions & 39 deletions
63
src/frontend/src/CustomNodes/hooks/use-fetch-data-on-mount.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
Oops, something went wrong.