Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug note editor caching value #1598

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading