From 60f2747b0e8829f28a8f79013baba8e1a787f3a7 Mon Sep 17 00:00:00 2001 From: Andrey Nenashev Date: Thu, 11 Jan 2024 18:21:08 +0100 Subject: [PATCH] Bugfix: date cells, lookup table definition permissions, boolean cells (#1578) Co-authored-by: vburlachenko --- .../reactive/ReferenceDataRepositoryImpl.java | 11 ++- odd-platform-specification/components.yaml | 1 - .../DatasetDataTableRowCell.tsx | 21 +++-- .../DatasetDataTableRowCellDate.tsx | 23 +++--- .../DatasetStructure/DatasetStructure.tsx | 3 - .../DatasetFieldHeader/DatasetFieldHeader.tsx | 76 +++++++++---------- .../DatasetStructureList.tsx | 41 +++++----- .../shared/elements/forms/ColumnForm.tsx | 4 +- 8 files changed, 88 insertions(+), 92 deletions(-) diff --git a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReferenceDataRepositoryImpl.java b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReferenceDataRepositoryImpl.java index 1cd124953..dfb47abd1 100644 --- a/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReferenceDataRepositoryImpl.java +++ b/odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReferenceDataRepositoryImpl.java @@ -249,9 +249,12 @@ public Mono updateLookupTableRow(final LookupTableDto table, final Map columnWithValues = new HashMap<>(); for (final LookupTablesDefinitionsPojo targetColumn : columnNames) { + final LookupTableColumnTypes dataType = + LookupTableColumnTypes.resolveByTypeString(targetColumn.getColumnType()); + columnWithValues.put(targetColumn.getColumnName().toLowerCase(), - getColumnInputData(item, targetColumn, - LookupTableColumnTypes.resolveByTypeString(targetColumn.getColumnType()))); + DSL.val(getColumnInputData(item, targetColumn, dataType), + dataType.getDataType())); } return jooqReactiveOperationsCustomTables.mono( @@ -369,8 +372,8 @@ private Mono> getUniqueConstraintUpdateQuery(final ReferenceTableC } private Mono> renameSequencesUpdateQuery(final String newColumnName, - final LookupTablesDefinitionsPojo column, - final String tableName) { + final LookupTablesDefinitionsPojo column, + final String tableName) { final String template = buildSequenceNameTemplate(tableName, column.getColumnName()); final SelectConditionStep> sequences = diff --git a/odd-platform-specification/components.yaml b/odd-platform-specification/components.yaml index cdee6a857..34b9f360d 100644 --- a/odd-platform-specification/components.yaml +++ b/odd-platform-specification/components.yaml @@ -3894,7 +3894,6 @@ components: type: string required: - field_id - - value LookupTableRowList: type: object diff --git a/odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell.tsx b/odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell.tsx index 77c64e5cd..d66e60d13 100644 --- a/odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell.tsx +++ b/odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell.tsx @@ -27,18 +27,15 @@ const DatasetDataTableRowCell = ({ const { meta: tableMeta } = table.options; const isEditing = row.getIsSelected(); - const onChange = useCallback( - (v: unknown) => { - tableMeta?.setEditedRowsData(prev => ({ - ...prev, - [row.id]: { - ...prev[row.id], - [column.id]: v, - }, - })); - }, - [row.id, column.id] - ); + const onChange = useCallback((v: unknown) => { + tableMeta?.setEditedRowsData(prev => ({ + ...prev, + [row.id]: { + ...prev[row.id], + [column.id]: v, + }, + })); + }, []); const renderCell = (type?: LookupTableFieldType) => { const value = getValue(); diff --git a/odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell/DatasetDataTableRowCellDate.tsx b/odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell/DatasetDataTableRowCellDate.tsx index 9eb4d6e0a..e4b3d28ee 100644 --- a/odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell/DatasetDataTableRowCellDate.tsx +++ b/odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell/DatasetDataTableRowCellDate.tsx @@ -1,5 +1,5 @@ import { Box, Typography } from '@mui/material'; -import React, { useCallback, useMemo } from 'react'; +import React, { useCallback, useEffect, useMemo, useState } from 'react'; import { AppDatePicker } from 'components/shared/elements'; import { format, isValid } from 'date-fns'; import type { RowCellProps } from './interfaces'; @@ -15,19 +15,24 @@ const DatasetDataTableRowCellDate: React.FC = ({ isEditing, onChange, }) => { - const handleChange = useCallback((date: typeof initialValue) => { - if (date && isValid(date)) { - onChange(format(date, POSTGRES_DATE_FORMAT)); - return; - } - onChange(null); + const [date, setDate] = useState(initialValue); + const handleChange = useCallback((v: typeof initialValue) => { + setDate(v); }, []); const defaultDate = useMemo( - () => (initialValue ? format(initialValue, POSTGRES_DATE_FORMAT) : undefined), - [initialValue] + () => (date ? format(date, POSTGRES_DATE_FORMAT) : undefined), + [date] ); + useEffect(() => { + if (date && isValid(date) && isEditing) { + onChange(format(date, POSTGRES_DATE_FORMAT)); + return; + } + onChange(null); + }, [date, isEditing]); + return isEditing ? ( { Permission.DATASET_FIELD_ADD_TERM, Permission.DATASET_FIELD_DELETE_TERM, Permission.DATASET_FIELD_INTERNAL_NAME_UPDATE, - Permission.LOOKUP_TABLE_DEFINITION_CREATE, - Permission.LOOKUP_TABLE_DEFINITION_UPDATE, - Permission.LOOKUP_TABLE_DEFINITION_DELETE, ]} resourcePermissions={resourcePermissions} Component={DatasetStructureOverview} diff --git a/odd-platform-ui/src/components/DataEntityDetails/DatasetStructure/DatasetStructureOverview/DatasetStructureView/DatasetFieldOverview/DatasetFieldHeader/DatasetFieldHeader.tsx b/odd-platform-ui/src/components/DataEntityDetails/DatasetStructure/DatasetStructureOverview/DatasetStructureView/DatasetFieldOverview/DatasetFieldHeader/DatasetFieldHeader.tsx index 4c9d5b78a..1f8d00ca3 100644 --- a/odd-platform-ui/src/components/DataEntityDetails/DatasetStructure/DatasetStructureOverview/DatasetStructureView/DatasetFieldOverview/DatasetFieldHeader/DatasetFieldHeader.tsx +++ b/odd-platform-ui/src/components/DataEntityDetails/DatasetStructure/DatasetStructureOverview/DatasetStructureView/DatasetFieldOverview/DatasetFieldHeader/DatasetFieldHeader.tsx @@ -83,48 +83,44 @@ const DatasetFieldHeader = ({ field }: DatasetFieldHeaderProps) => { {!field.isPrimaryKey && !!lookupTableField && lookupTableId && ( - - } - /> + } + /> + } + lookupTableField={lookupTableField} + lookupTableId={lookupTableId} + /> + ( +