Skip to content

Commit

Permalink
Fix bug note editor caching value (#1598)
Browse files Browse the repository at this point in the history
* Fix WfoInlineNoteEdit showing cached value from the previous page on the next one

* add changeset
  • Loading branch information
Georgi2704 authored Nov 27, 2024
1 parent c592740 commit d39017a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-monkeys-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@orchestrator-ui/orchestrator-ui-components': patch
---

Fix WfoInlineNoteEdit showing cached value from the previous page on the next one
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useState } from 'react';
import type { ChangeEvent, FC } from 'react';

import { EuiInlineEditText } from '@elastic/eui';
Expand All @@ -20,8 +20,7 @@ export const WfoInlineNoteEdit: FC<WfoInlineNoteEditProps> = ({
onlyShowOnHover = false,
}) => {
const { theme } = useOrchestratorTheme();
const initialNote = useMemo(() => value || '', [value]);
const [note, setNote] = useState<string>(initialNote);
const [note, setNote] = useState<string>(value ?? '');
const [isTooltipVisible, setIsTooltipVisible] = useState<boolean>(true);

const [startProcess] = useStartProcessMutation();
Expand All @@ -42,15 +41,15 @@ export const WfoInlineNoteEdit: FC<WfoInlineNoteEditProps> = ({
};

const handleCancel = () => {
setNote(initialNote);
setNote(value ?? '');
setIsTooltipVisible(true);
};

// This useEffect makes sure the note is updated when a new value property is passed in
// for example by a parent component that is update through a websocket event
useEffect(() => {
setNote(initialNote);
}, [initialNote]);
setNote(value ?? '');
}, [value]);

return (
<div
Expand Down

0 comments on commit d39017a

Please sign in to comment.