Skip to content

Commit 74ab021

Browse files
fix: Refactor data grids to preserve incomplete rows (#223)
* fix: refactor data grids to preserve incomplete rows * fix: preserve rows when toggling Primary checkbox
1 parent fae1e08 commit 74ab021

8 files changed

+22
-38
lines changed

packages/react-model-ui/src/views/common/AttributeMappingSourcesDataGrid.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,10 @@ export function AttributeMappingSourcesDataGrid({
253253
// For uncommitted rows, check if anything actually changed
254254
const hasChanges = sourceToUpdate.value !== defaultEntry.value;
255255

256-
// Check if the value is valid (not empty or default value)
257-
const isValidValue =
258-
sourceToUpdate.value && sourceToUpdate.value.trim() !== '' && sourceToUpdate.value !== '_' && sourceToUpdate.value !== '-';
256+
259257

260-
if (!hasChanges || !isValidValue) {
261-
// Remove the row if no changes or invalid value
258+
if (!hasChanges) {
259+
// Remove the row if no changes
262260
setGridData(current => current.filter(row => row.id !== sourceToUpdate.id));
263261
setEditingRows({});
264262
return;

packages/react-model-ui/src/views/common/CustomPropertiesDataGrid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ export function CustomPropertiesDataGrid({
7272
customProperty.value !== defaultEntry.value ||
7373
customProperty.description !== defaultEntry.description;
7474

75-
if (!hasChanges || !customProperty.name) {
76-
// Remove the row if no changes or no name
75+
if (!hasChanges) {
76+
// Remove the row if no changes
7777
setGridData(current => current.filter(row => row.id !== customProperty.id));
7878
setEditingRows({});
7979
return;

packages/react-model-ui/src/views/common/DataModelDependenciesDataGrid.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { DataTableRowEditEvent } from 'primereact/datatable';
77
import * as React from 'react';
88
import { useDataModel, useDiagnosticsManager, useModelDispatch, useModelQueryApi, useReadonly } from '../../ModelContext';
99
import { ErrorView } from '../ErrorView';
10-
import { handleGridEditorKeyDown, wasSaveTriggeredByEnter } from './gridKeydownHandler';
1110
import { EditorProperty, GenericTextEditor } from './GenericEditors';
11+
import { handleGridEditorKeyDown, wasSaveTriggeredByEnter } from './gridKeydownHandler';
1212
import { GridColumn, PrimeDataGrid } from './PrimeDataGrid';
1313

1414
export interface DataModelDependencyRow extends DataModelDependency {
@@ -228,12 +228,9 @@ export function DataModelDependenciesDataGrid(): React.ReactElement {
228228
// For uncommitted rows, check if anything actually changed
229229
const hasChanges = dependency.datamodel !== defaultEntry.datamodel || dependency.version !== defaultEntry.version;
230230

231-
// Also check if the datamodel is valid
232-
const isValidDatamodel =
233-
dependency.datamodel && dependency.datamodel.trim() !== '' && dependency.datamodel !== '_' && dependency.datamodel !== '-';
234231

235-
if (!hasChanges || !isValidDatamodel) {
236-
// Remove the row if no changes or invalid datamodel
232+
if (!hasChanges) {
233+
// Remove the row if no changes
237234
setGridData(current => current.filter(row => row.id !== dependency.id));
238235
setEditingRows({});
239236
return;

packages/react-model-ui/src/views/common/EntityAttributesDataGrid.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,11 @@ export function EntityAttributesDataGrid(): React.ReactElement {
298298
const hasChanges =
299299
attribute.name !== defaultEntry.name ||
300300
attribute.datatype !== defaultEntry.datatype ||
301-
attribute.description !== defaultEntry.description;
301+
attribute.description !== defaultEntry.description ||
302+
!!attribute.identifier;
302303

303-
if (!hasChanges || !attribute.name) {
304-
// Remove the row if no changes or no name
304+
if (!hasChanges) {
305+
// Remove the row if no changes
305306
setGridData(current => current.filter(row => row.id !== attribute.id));
306307
setEditingRows({});
307308
return;

packages/react-model-ui/src/views/common/EntityIdentifiersDataGrid.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ export function EntityIdentifiersDataGrid(): React.ReactElement {
203203
const hasChanges =
204204
identifier.name !== defaultEntry.name ||
205205
identifier.description !== defaultEntry.description ||
206-
identifier.attributeIds.length > 0;
206+
identifier.attributeIds.length > 0 ||
207+
identifier.primary !== defaultEntry.primary;
207208

208-
if (!hasChanges || !identifier.name) {
209-
// Remove the row if no changes or no name
209+
if (!hasChanges) {
210+
// Remove the row if no changes
210211
setGridData(current => current.filter(row => row.id !== identifier.id));
211212
setEditingRows({});
212213
return;

packages/react-model-ui/src/views/common/RelationshipAttributesDataGrid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ export function RelationshipAttributesDataGrid(): React.ReactElement {
231231
// For uncommitted rows, check if anything actually changed
232232
const hasChanges = attribute.parent !== defaultEntry.parent || attribute.child !== defaultEntry.child;
233233

234-
if (!hasChanges || !attribute.parent || !attribute.child) {
235-
// Remove the row if no changes or incomplete data
234+
if (!hasChanges) {
235+
// Remove the row if no changes
236236
setGridData(current => current.filter(row => row.id !== attribute.id));
237237
setEditingRows({});
238238
return;

packages/react-model-ui/src/views/common/SourceObjectConditionDataGrid.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -335,17 +335,8 @@ export function SourceObjectConditionDataGrid({ mapping, sourceObjectIdx }: Sour
335335
condition.operator !== defaultEntry.operator ||
336336
condition.right.value !== defaultEntry.right.value;
337337

338-
// Check if required fields are valid
339-
const isValid =
340-
condition.left.value?.trim() &&
341-
condition.right.value?.trim() &&
342-
condition.left.value !== '_' &&
343-
condition.left.value !== '-' &&
344-
condition.right.value !== '_' &&
345-
condition.right.value !== '-';
346-
347-
if (!hasChanges || !isValid) {
348-
// Remove the row if no changes or invalid
338+
if (!hasChanges) {
339+
// Remove the row if no changes
349340
setGridData(current => current.filter(row => row.id !== condition.id));
350341
setEditingRows({});
351342
return;

packages/react-model-ui/src/views/common/SourceObjectDependencyDataGrid.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,8 @@ export function SourceObjectDependencyDataGrid({ mapping, sourceObjectIdx }: Sou
231231
// For uncommitted rows, check if anything actually changed
232232
const hasChanges = dependency.source !== defaultEntry.source;
233233

234-
// Check if the source is valid (not empty or default value)
235-
const isValidSource =
236-
dependency.source && dependency.source.trim() !== '' && dependency.source !== '_' && dependency.source !== '-';
237-
238-
if (!hasChanges || !isValidSource) {
239-
// Remove the row if no changes or invalid source
234+
if (!hasChanges) {
235+
// Remove the row if no changes
240236
setGridData(current => current.filter(row => row.id !== dependency.id));
241237
setEditingRows({});
242238
return;

0 commit comments

Comments
 (0)