Fixed Undo bug adding Skip Snapshot to function that resets inputs when disabled

This commit is contained in:
Lucas Oliveira 2024-05-15 13:59:50 +02:00
commit d42925c16c
10 changed files with 26 additions and 25 deletions

View file

@ -18,12 +18,12 @@ export default function CodeAreaComponent({
setOpen, setOpen,
}: CodeAreaComponentType) { }: CodeAreaComponentType) {
const [myValue, setMyValue] = useState( const [myValue, setMyValue] = useState(
typeof value == "string" ? value : JSON.stringify(value) typeof value == "string" ? value : JSON.stringify(value),
); );
useEffect(() => { useEffect(() => {
if (disabled && myValue !== "") { if (disabled && myValue !== "") {
setMyValue(""); setMyValue("");
onChange(""); onChange("", true);
} }
}, [disabled]); }, [disabled]);

View file

@ -16,7 +16,7 @@ export default function FloatComponent({
// Clear component state // Clear component state
useEffect(() => { useEffect(() => {
if (disabled && value !== "") { if (disabled && value !== "") {
onChange(""); onChange("", true);
} }
}, [disabled]); }, [disabled]);

View file

@ -48,7 +48,7 @@ export default function InputComponent({
// Clear component state // Clear component state
useEffect(() => { useEffect(() => {
if (disabled && value && onChange && value !== "") { if (disabled && value && onChange && value !== "") {
onChange(""); onChange("", true);
} }
}, [disabled]); }, [disabled]);

View file

@ -27,7 +27,7 @@ export default function InputFileComponent({
useEffect(() => { useEffect(() => {
if (disabled && value !== "") { if (disabled && value !== "") {
setMyValue(""); setMyValue("");
onChange(""); onChange("", true);
onFileChange(""); onFileChange("");
} }
}, [disabled, onChange]); }, [disabled, onChange]);
@ -106,8 +106,8 @@ export default function InputFileComponent({
editNode editNode
? "input-edit-node input-dialog text-muted-foreground" ? "input-edit-node input-dialog text-muted-foreground"
: disabled : disabled
? "input-disable input-dialog primary-input" ? "input-disable input-dialog primary-input"
: "input-dialog primary-input text-muted-foreground" : "input-dialog primary-input text-muted-foreground"
} }
> >
{myValue !== "" ? myValue : "No file"} {myValue !== "" ? myValue : "No file"}

View file

@ -19,15 +19,15 @@ export default function InputGlobalComponent({
editNode = false, editNode = false,
}: InputGlobalComponentType): JSX.Element { }: InputGlobalComponentType): JSX.Element {
const globalVariablesEntries = useGlobalVariablesStore( const globalVariablesEntries = useGlobalVariablesStore(
(state) => state.globalVariablesEntries (state) => state.globalVariablesEntries,
); );
const getVariableId = useGlobalVariablesStore((state) => state.getVariableId); const getVariableId = useGlobalVariablesStore((state) => state.getVariableId);
const unavaliableFields = useGlobalVariablesStore( const unavaliableFields = useGlobalVariablesStore(
(state) => state.unavaliableFields (state) => state.unavaliableFields,
); );
const removeGlobalVariable = useGlobalVariablesStore( const removeGlobalVariable = useGlobalVariablesStore(
(state) => state.removeGlobalVariable (state) => state.removeGlobalVariable,
); );
const setErrorData = useAlertStore((state) => state.setErrorData); const setErrorData = useAlertStore((state) => state.setErrorData);
@ -38,7 +38,7 @@ export default function InputGlobalComponent({
data.node?.template[name].load_from_db data.node?.template[name].load_from_db
) { ) {
setTimeout(() => { setTimeout(() => {
onChange(""); onChange("", true);
setDb(false); setDb(false);
}, 100); }, 100);
} }
@ -129,7 +129,7 @@ export default function InputGlobalComponent({
<ForwardedIconComponent <ForwardedIconComponent
name="Trash2" name="Trash2"
className={cn( className={cn(
"h-4 w-4 text-primary opacity-0 hover:text-status-red group-hover:opacity-100" "h-4 w-4 text-primary opacity-0 hover:text-status-red group-hover:opacity-100",
)} )}
aria-hidden="true" aria-hidden="true"
/> />
@ -146,8 +146,8 @@ export default function InputGlobalComponent({
onChange(value); onChange(value);
setDb(value !== "" ? true : false); setDb(value !== "" ? true : false);
}} }}
onChange={(value) => { onChange={(value, skipSnapshot) => {
onChange(value); onChange(value, skipSnapshot);
setDb(false); setDb(false);
}} }}
/> />

View file

@ -19,7 +19,7 @@ export default function IntComponent({
// Clear component state // Clear component state
useEffect(() => { useEffect(() => {
if (disabled && value !== "") { if (disabled && value !== "") {
onChange(""); onChange("", true);
} }
}, [disabled, onChange]); }, [disabled, onChange]);

View file

@ -18,7 +18,7 @@ export default function PromptAreaComponent({
}: PromptAreaComponentType): JSX.Element { }: PromptAreaComponentType): JSX.Element {
useEffect(() => { useEffect(() => {
if (disabled && value !== "") { if (disabled && value !== "") {
onChange(""); onChange("", true);
} }
}, [disabled]); }, [disabled]);

View file

@ -16,7 +16,7 @@ export default function TextAreaComponent({
// Clear text area // Clear text area
useEffect(() => { useEffect(() => {
if (disabled && value !== "") { if (disabled && value !== "") {
onChange(""); onChange("", true);
} }
}, [disabled]); }, [disabled]);

View file

@ -159,11 +159,12 @@ export default function ParameterComponent({
const handleOnNewValue = async ( const handleOnNewValue = async (
newValue: string | string[] | boolean | Object[], newValue: string | string[] | boolean | Object[],
skipSnapshot: boolean | undefined = false,
): Promise<void> => { ): Promise<void> => {
const nodeTemplate = data.node!.template[name]; const nodeTemplate = data.node!.template[name];
const currentValue = nodeTemplate.value; const currentValue = nodeTemplate.value;
if (currentValue !== newValue) { if (currentValue !== newValue && !skipSnapshot) {
takeSnapshot(); takeSnapshot();
} }

View file

@ -10,7 +10,7 @@ export type InputComponentType = {
onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void; onBlur?: (event: React.FocusEvent<HTMLInputElement>) => void;
value?: string; value?: string;
disabled?: boolean; disabled?: boolean;
onChange?: (value: string) => void; onChange?: (value: string, snapshot?: boolean) => void;
password: boolean; password: boolean;
required?: boolean; required?: boolean;
isForm?: boolean; isForm?: boolean;
@ -100,7 +100,7 @@ export type TextAreaComponentType = {
nodeClass?: APIClassType; nodeClass?: APIClassType;
setNodeClass?: (value: APIClassType) => void; setNodeClass?: (value: APIClassType) => void;
disabled: boolean; disabled: boolean;
onChange: (value: string[] | string) => void; onChange: (value: string[] | string, skipSnapshot?: boolean) => void;
value: string; value: string;
editNode?: boolean; editNode?: boolean;
id?: string; id?: string;
@ -112,7 +112,7 @@ export type PromptAreaComponentType = {
nodeClass?: APIClassType; nodeClass?: APIClassType;
setNodeClass?: (value: APIClassType, code?: string) => void; setNodeClass?: (value: APIClassType, code?: string) => void;
disabled: boolean; disabled: boolean;
onChange: (value: string[] | string) => void; onChange: (value: string[] | string, skipSnapshot?: boolean) => void;
value: string; value: string;
readonly?: boolean; readonly?: boolean;
editNode?: boolean; editNode?: boolean;
@ -122,7 +122,7 @@ export type PromptAreaComponentType = {
export type CodeAreaComponentType = { export type CodeAreaComponentType = {
setOpenModal?: (bool: boolean) => void; setOpenModal?: (bool: boolean) => void;
disabled: boolean; disabled: boolean;
onChange: (value: string[] | string) => void; onChange: (value: string[] | string, skipSnapshot?: boolean) => void;
value: string; value: string;
editNode?: boolean; editNode?: boolean;
nodeClass?: APIClassType; nodeClass?: APIClassType;
@ -137,7 +137,7 @@ export type CodeAreaComponentType = {
export type FileComponentType = { export type FileComponentType = {
IOInputProps?; IOInputProps?;
disabled: boolean; disabled: boolean;
onChange: (value: string[] | string) => void; onChange: (value: string[] | string, skipSnapshot?: boolean) => void;
value: string; value: string;
fileTypes: Array<string>; fileTypes: Array<string>;
onFileChange: (value: string) => void; onFileChange: (value: string) => void;
@ -170,7 +170,7 @@ export type IntComponentType = {
value: string; value: string;
disabled?: boolean; disabled?: boolean;
rangeSpec: RangeSpecType; rangeSpec: RangeSpecType;
onChange: (value: string) => void; onChange: (value: string, skipSnapshot?: boolean) => void;
editNode?: boolean; editNode?: boolean;
id?: string; id?: string;
}; };
@ -178,7 +178,7 @@ export type IntComponentType = {
export type FloatComponentType = { export type FloatComponentType = {
value: string; value: string;
disabled?: boolean; disabled?: boolean;
onChange: (value: string) => void; onChange: (value: string, skipSnapshot?: boolean) => void;
rangeSpec: RangeSpecType; rangeSpec: RangeSpecType;
editNode?: boolean; editNode?: boolean;
id?: string; id?: string;