Skip to content

Commit

Permalink
removed outdated use of useRef for editable paragraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
canptura committed Oct 24, 2024
1 parent 97c7a62 commit e50a4c6
Showing 1 changed file with 6 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,14 @@ const CustomField: React.FC<CustomFieldProps> = ({ keyId, parameter, editable, p
const [createFieldOpen, setCreateFieldOpen] = useState<boolean>(false);
const [deleteFieldOpen, setDeleteFieldOpen] = useState<boolean>(false);

// TODO: check if this actually works when given the newest data after refresh
const currentKeyRef = useRef(keyId);
useEffect(() => {
if (keyId !== currentKeyRef.current) currentKeyRef.current = keyId;
}, [keyId]);
const restoreKey = () => {
currentKeyRef.current = keyId;
};
const saveKey = async () => {
if (!currentKeyRef.current) return;
await updateParameter(parameter.id!, { key: currentKeyRef.current });
const handleKeyChange = async (newKey: string) => {
if (!newKey) return;
await updateParameter(parameter.id!, { key: newKey });
router.refresh();
};

const handleDeleteConfirm = async () => {
if (parameter.id) await removeParameter(parameter.id);

setCreateFieldOpen(false);
router.refresh();
};
Expand Down Expand Up @@ -177,14 +168,12 @@ const CustomField: React.FC<CustomFieldProps> = ({ keyId, parameter, editable, p
editable && {
icon: <EditOutlined style={{ color: 'rgba(0, 0, 0, 0.88)', margin: '0 10px' }} />,
tooltip: 'Edit Parameter Key',
onCancel: restoreKey,
onChange: (newValue) => (currentKeyRef.current = newValue),
onEnd: saveKey,
onChange: handleKeyChange,
enterIcon: <CheckOutlined />,
}
}
>
{currentKeyRef.current}
{keyId}
</Paragraph>
{editable && (
<Space.Compact size="small">
Expand All @@ -202,11 +191,7 @@ const CustomField: React.FC<CustomFieldProps> = ({ keyId, parameter, editable, p
</Col>

<Col span={21} className="gutter-row">
<Param
editingEnabled={editable}
field={parameter}
label={keyId[0].toUpperCase() + keyId.slice(1)}
/>
<Param editingEnabled={editable} field={parameter} label={keyId} />

{(editable || (parameter.linkedParameters && parameter.linkedParameters.length > 0)) && (
<Card style={cardStyle} size="small">
Expand Down

0 comments on commit e50a4c6

Please sign in to comment.