fix: workitem description input inital load (#8617)
This commit is contained in:
parent
c93f9fc865
commit
dbe059b7b5
1 changed files with 11 additions and 2 deletions
|
|
@ -119,6 +119,8 @@ export const DescriptionInput = observer(function DescriptionInput(props: Props)
|
||||||
});
|
});
|
||||||
// ref to track if there are unsaved changes
|
// ref to track if there are unsaved changes
|
||||||
const hasUnsavedChanges = useRef(false);
|
const hasUnsavedChanges = useRef(false);
|
||||||
|
// ref to track last saved content (to skip onChange when content hasn't actually changed)
|
||||||
|
const lastSavedContent = useRef(initialValue?.trim() === "" ? "<p></p>" : (initialValue ?? "<p></p>"));
|
||||||
// store hooks
|
// store hooks
|
||||||
const { getWorkspaceBySlug } = useWorkspace();
|
const { getWorkspaceBySlug } = useWorkspace();
|
||||||
const { uploadEditorAsset, duplicateEditorAsset } = useEditorAsset();
|
const { uploadEditorAsset, duplicateEditorAsset } = useEditorAsset();
|
||||||
|
|
@ -139,6 +141,8 @@ export const DescriptionInput = observer(function DescriptionInput(props: Props)
|
||||||
const handleDescriptionFormSubmit = useCallback(
|
const handleDescriptionFormSubmit = useCallback(
|
||||||
async (formData: TFormData) => {
|
async (formData: TFormData) => {
|
||||||
await onSubmit(formData.description_html, formData.isMigrationUpdate);
|
await onSubmit(formData.description_html, formData.isMigrationUpdate);
|
||||||
|
// Update lastSavedContent after successful save
|
||||||
|
lastSavedContent.current = formData.description_html;
|
||||||
},
|
},
|
||||||
[onSubmit]
|
[onSubmit]
|
||||||
);
|
);
|
||||||
|
|
@ -146,14 +150,17 @@ export const DescriptionInput = observer(function DescriptionInput(props: Props)
|
||||||
// reset form values
|
// reset form values
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!entityId) return;
|
if (!entityId) return;
|
||||||
|
const normalizedValue = initialValue?.trim() === "" ? "<p></p>" : (initialValue ?? "<p></p>");
|
||||||
|
// Update last saved content when entity/initialValue changes
|
||||||
|
lastSavedContent.current = normalizedValue;
|
||||||
reset({
|
reset({
|
||||||
id: entityId,
|
id: entityId,
|
||||||
description_html: initialValue?.trim() === "" ? "<p></p>" : (initialValue ?? "<p></p>"),
|
description_html: normalizedValue,
|
||||||
isMigrationUpdate: false,
|
isMigrationUpdate: false,
|
||||||
});
|
});
|
||||||
setLocalDescription({
|
setLocalDescription({
|
||||||
id: entityId,
|
id: entityId,
|
||||||
description_html: initialValue?.trim() === "" ? "<p></p>" : (initialValue ?? "<p></p>"),
|
description_html: normalizedValue,
|
||||||
isMigrationUpdate: false,
|
isMigrationUpdate: false,
|
||||||
});
|
});
|
||||||
// Reset unsaved changes flag when form is reset
|
// Reset unsaved changes flag when form is reset
|
||||||
|
|
@ -219,6 +226,8 @@ export const DescriptionInput = observer(function DescriptionInput(props: Props)
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
dragDropEnabled
|
dragDropEnabled
|
||||||
onChange={(_description, description_html, options) => {
|
onChange={(_description, description_html, options) => {
|
||||||
|
// Skip if content hasn't actually changed (handles editor normalization on init)
|
||||||
|
if (description_html === lastSavedContent.current) return;
|
||||||
setIsSubmitting("submitting");
|
setIsSubmitting("submitting");
|
||||||
onChange(description_html);
|
onChange(description_html);
|
||||||
setValue("isMigrationUpdate", options?.isMigrationUpdate ?? false);
|
setValue("isMigrationUpdate", options?.isMigrationUpdate ?? false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue