Skip to content

Commit

Permalink
fix: optmize code #WIK-16192
Browse files Browse the repository at this point in the history
  • Loading branch information
huanhuanwa committed Jul 29, 2024
1 parent 9c2f1e6 commit 5509277
Showing 1 changed file with 31 additions and 20 deletions.
51 changes: 31 additions & 20 deletions packages/grid/src/core/action/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,55 @@ const apply = (aiTable: AITable, records: AITableRecords, fields: AITableFields,
switch (options.type) {
case ActionName.UpdateFieldValue: {
const [recordIndex, fieldIndex] = options.path;
const fieldId = aiTable.fields()[fieldIndex].id;
records[recordIndex].value[fieldId] = options.newFieldValue;
if (fieldIndex > -1 && recordIndex > -1) {
const fieldId = aiTable.fields()[fieldIndex].id;
records[recordIndex].value[fieldId] = options.newFieldValue;
}
break;
}
case ActionName.AddRecord: {
const [recordIndex] = options.path;
records.splice(recordIndex, 0, options.record);
if (recordIndex > -1) {
records.splice(recordIndex, 0, options.record);
}
break;
}
case ActionName.AddField: {
const [fieldIndex] = options.path;
const newField = options.field;
fields.splice(fieldIndex, 0, newField);
const newRecord = {
[newField.id]: ''
};
records.forEach((item) => {
item.value = {
...item.value,
...newRecord
if (fieldIndex > -1) {
const newField = options.field;
fields.splice(fieldIndex, 0, newField);
const newRecord = {
[newField.id]: ''
};
});
records.forEach((item) => {
item.value = {
...item.value,
...newRecord
};
});
}

break;
}
case ActionName.RemoveField: {
const [fieldIndex] = options.path;
const fieldId = aiTable.fields()[fieldIndex].id;
fields.splice(fieldIndex, 1);
records.forEach((item) => {
delete item.value[fieldId];
});
if (fieldIndex > -1) {
const fieldId = aiTable.fields()[fieldIndex].id;
fields.splice(fieldIndex, 1);
records.forEach((item) => {
delete item.value[fieldId];
});
}
break;
}
case ActionName.RemoveRecord: {
const [recordIndex] = options.path;
records.splice(recordIndex, 1);
if (recordIndex > -1) {
records.splice(recordIndex, 1);
}
break;
}
}
}
return {
records,
Expand Down

0 comments on commit 5509277

Please sign in to comment.