Skip to content

Commit

Permalink
fix: fixed bug where first open of editor dialog displayed old value (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
chesterkmr authored Aug 3, 2024
1 parent 9e44840 commit 971a3b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IWorkflowDefinition } from '@/domains/workflow-definitions';

export const getStateOptions = (workflowDefinition: IWorkflowDefinition) => {
//@ts-ignore
return Object.keys(workflowDefinition.definition?.states || {});
return Object.keys(workflowDefinition?.definition?.states || {});
};

export interface IEventDropdownOption {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Card, CardContent, CardHeader } from '@/components/atoms/Card';
import { Dialog, DialogContent, DialogTrigger } from '@/components/atoms/Dialog';
import { JSONEditorComponent } from '@/components/organisms/JsonEditor';
import { Pencil } from 'lucide-react';
import { FunctionComponent, useCallback, useMemo, useState } from 'react';
import { FunctionComponent, useCallback, useEffect, useMemo, useState } from 'react';

interface IEditorCardProps {
value: object;
Expand All @@ -27,6 +27,10 @@ export const EditorCard: FunctionComponent<IEditorCardProps> = ({
const [valueSnapshot, setSnapshot] = useState(value);
const [internalValue, setInternalValue] = useState(valueSnapshot);

useEffect(() => {
setInternalValue(value);
}, [value]);

const hasChanges = useMemo(() => {
return JSON.stringify(internalValue) !== JSON.stringify(valueSnapshot);
}, [internalValue, valueSnapshot]);
Expand Down

0 comments on commit 971a3b3

Please sign in to comment.