Skip to content

Commit 5e50457

Browse files
committed
fix we do not see duplicates now after adding
1 parent 02a3a24 commit 5e50457

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

frontend/src/components/metadata/widgets/MetadataTextField.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ export const MetadataTextField = (props) => {
2020
frozen,
2121
frozenVersionNum,
2222
} = props;
23-
const [localContent, setLocalContent] = useState(
24-
content && content[fieldName] ? content : {}
25-
);
23+
// FIX: Properly initialize localContent to always have the field
24+
const [localContent, setLocalContent] = useState(() => {
25+
if (content && content[fieldName] !== undefined) {
26+
return content;
27+
}
28+
return { [fieldName]: "" }; // Ensure the field always exists
29+
});
2630
const [readOnly, setReadOnly] = useState(initialReadOnly);
2731
const [inputChanged, setInputChanged] = useState(false);
2832

@@ -44,8 +48,25 @@ export const MetadataTextField = (props) => {
4448
return "null";
4549
};
4650

47-
// Get the value for the text field
4851
const getValue = () => {
52+
if (readOnly) {
53+
// Read-only mode: show content or "null"
54+
if (content && content[fieldName] !== undefined && content[fieldName] !== null) {
55+
return content[fieldName];
56+
}
57+
if (localContent && localContent[fieldName] !== undefined && localContent[fieldName] !== null) {
58+
return localContent[fieldName];
59+
}
60+
return "null";
61+
} else {
62+
// Edit mode: show localContent value (what user is typing)
63+
// FIX: This will now always return a string, never undefined
64+
return localContent[fieldName] || "";
65+
}
66+
};
67+
68+
// Get the value for the text field
69+
const getValue2 = () => {
4970
if (readOnly) {
5071
// Read-only mode: show content or "null"
5172
if (content && content[fieldName] !== undefined && content[fieldName] !== null) {

0 commit comments

Comments
 (0)