Skip to content

Commit

Permalink
Clean old values before a new one setting
Browse files Browse the repository at this point in the history
  • Loading branch information
vmonakhov committed Oct 1, 2023
1 parent 9e9a3d7 commit ccdc88b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/pages/CorpImport/ColumnMapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function Columns({ blob, index, fieldOptions, columnTypes, onSetColumnType }) {
const blobId = blob.get("id");
const values = blob.get("values");
const column = index ? "sentence" : "base sentence";
const columnIdStr = `${index}:${column}`;
const columnIdStr = `${index}:sentence`;
const value = values.get(columnIdStr);

return (
Expand Down
15 changes: 12 additions & 3 deletions src/pages/CorpImport/Linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ function valueColor(value) {
return "yellow";
}

function Columns({ blob, index, onUpdateColumn, onToggleColumn, onDelete }) {
function Columns({ blob, index, total, onUpdateColumn, onToggleColumn, onDelete }) {
const getTranslation = useContext(TranslationContext);
const value = index ? "secondary" : "base";
const column = index ? "sentence" : "base sentence";
const idStr = `${index}:${column}`;
const idStr = `${index}:sentence`;

useEffect(() => { onUpdateColumn(idStr, value, null); }, [idStr]);
/* Clean other values and set a fresh one.
/* In the interface after a blob removing another blobs change their index numbers,
/* but they still store old values with old index numbers. So it's needed to clean
/* old values at first and then set a new one. */
useEffect(() => {
for (let i=0; i<=total; i++)
onUpdateColumn(`${i}:sentence`, null, null);
onUpdateColumn(idStr, value, null);
}, [idStr]);

return (
<div className="blob">
Expand Down Expand Up @@ -74,6 +82,7 @@ function Linker({ blobs, state, onSelect, onDelete, onUpdateColumn, onToggleColu
key={id.join("/")}
blob={v}
index={i++}
total={state.size}
onUpdateColumn={onUpdateColumn(id)}
onToggleColumn={onToggleColumn(id)}
onDelete={onDelete}
Expand Down

0 comments on commit ccdc88b

Please sign in to comment.