Skip to content

Commit 640af38

Browse files
committed
fix record edit
1 parent 59419c2 commit 640af38

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

src/components/projects/projectId/edit-records/EditField.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import { DataTypeEnum } from "@/src/types/shared/general";
44
import { ModalEnum } from "@/src/types/shared/modal";
55
import { buildAccessKey } from "@/src/util/components/projects/projectId/edit-records-helper";
66
import { jsonCopy } from "@/submodules/javascript-functions/general";
7-
import { useRef, useState } from "react";
7+
import { useEffect, useRef, useState } from "react";
88
import { useDispatch } from "react-redux";
99

1010
export default function EditField(props: EditFieldProps) {
1111
const dispatch = useDispatch();
1212

13-
const [inputValue, setInputValue] = useState(props.record.data[props.attribute.name]);
13+
14+
const [inputValue, setInputValue] = useState(null);
1415

1516
const inputRef = useRef(null);
1617

@@ -67,6 +68,14 @@ export default function EditField(props: EditFieldProps) {
6768
}
6869
}
6970

71+
useEffect(() => {
72+
if (props.subKey == undefined) setInputValue(props.record.data[props.attribute.name]);
73+
else setInputValue(props.record.data[props.attribute.name][props.subKey]);
74+
}, [props.record.data[props.attribute.name], props.subKey]);
75+
76+
if (!inputValue) return null;
77+
78+
7079
return (<>
7180
{(props.attribute.dataType == DataTypeEnum.TEXT || props.attribute.dataType == DataTypeEnum.LLM_RESPONSE) &&
7281
<textarea value={inputValue} ref={inputRef}

src/components/projects/projectId/edit-records/EditRecords.tsx

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export default function EditRecords() {
8989
}} id={record.id == erdData.data.selectedRecordId ? 'flash-it' : null}>
9090
<div className="px-4 py-5 sm:p-6">
9191
{erdData.data.attributes.map((attribute) => (<Fragment key={attribute.id}>
92+
9293
<div>
9394
<div className="font-semibold text-sm text-gray-800">
9495
<div className="flex flex-row items-center">
@@ -98,26 +99,32 @@ export default function EditRecords() {
9899
<div className="text-gray-800 text-sm mb-4 overflow-anywhere flex">
99100
{attribute.dataType == DataTypeEnum.EMBEDDING_LIST ? (<div className="flex flex-col gap-y-1 divide-y w-full">
100101
{record.data[attribute.name].map((item, subKey) => (<div key={subKey} className="pt-1">
101-
{(record.id == erdData.editRecordId && !attribute.isPrimaryKey) ? <EditField attribute={attribute} record={record} subKey={subKey} erdData={erdData} setErdData={(erdData) => setErdData(erdData)} /> : <>
102-
{item != null && item !== '' ? (<span className="whitespace-pre-wrap">
103-
<span>{item}</span>
104-
</span>) : (<NotPresentInRecord />)}
105-
</>}
102+
{(record.id == erdData.editRecordId && !attribute.isPrimaryKey) ?
103+
<EditField attribute={attribute} record={record} subKey={subKey} erdData={erdData} setErdData={(erdData) => setErdData(erdData)} /> : <>
104+
{item != null && item !== '' ? (<span className="whitespace-pre-wrap" style={{ wordBreak: 'break-word' }}>
105+
<span>{item}</span>
106+
</span>) : (<NotPresentInRecord />)}
107+
</>}
106108
</div>))}
107-
</div>) : (<>
108-
{(record.id == erdData.editRecordId && !attribute.isPrimaryKey) ? <EditField attribute={attribute} record={record} erdData={erdData} setErdData={(erdData) => setErdData(erdData)} /> : <>
109-
{record.data[attribute.name] != null && record.data[attribute.name] !== '' ? (<span className="whitespace-pre-wrap relative">
110-
<span>{`${record.data[attribute.name]}`}</span>
111-
{erdData.cachedRecordChanges[buildAccessKey(record.id, attribute.name)] && <div className="absolute -left-5 top-0 text-yellow-500">
112-
<Tooltip content={TOOLTIPS_DICT.EDIT_RECORDS.CACHED_VALUES} color="invert" placement="right" className="cursor-auto">
113-
<MemoIconAlertTriangleFilled size={16} stroke={2} />
114-
</Tooltip>
115-
</div>}
116-
</span>) : <NotPresentInRecord />}
117-
</>}
118-
</>)}
109+
</div>) :
110+
attribute.dataType == DataTypeEnum.PERMISSION ? <span className="font-dmMono">Permissions are not editable</span> :
111+
(
112+
<>
113+
{(record.id == erdData.editRecordId && !attribute.isPrimaryKey) ? <EditField attribute={attribute} record={record} erdData={erdData} setErdData={(erdData) => setErdData(erdData)} /> : <>
114+
{record.data[attribute.name] != null && record.data[attribute.name] !== '' ? (<span className="whitespace-pre-wrap relative" style={{ wordBreak: 'break-word' }}>
115+
<span>{`${record.data[attribute.name]}`}</span>
116+
{erdData.cachedRecordChanges[buildAccessKey(record.id, attribute.name)] && <div className="absolute -left-5 top-0 text-yellow-500">
117+
<Tooltip content={TOOLTIPS_DICT.EDIT_RECORDS.CACHED_VALUES} color="invert" placement="right" className="cursor-auto">
118+
<MemoIconAlertTriangleFilled size={16} stroke={2} />
119+
</Tooltip>
120+
</div>}
121+
</span>) : <NotPresentInRecord />}
122+
</>}
123+
</>)}
124+
119125
</div>
120126
</div>
127+
121128
</Fragment>))}
122129
<div className="absolute top-2 right-2 flex flex-row flex-nowrap items-center gap-x-2">
123130
{record.rla_data && <Tooltip content={TOOLTIPS_DICT.EDIT_RECORDS.LABEL_ASSOCIATIONS} color="invert" placement="left" className="cursor-auto">

0 commit comments

Comments
 (0)