Skip to content

Commit 60f2747

Browse files
Bugfix: date cells, lookup table definition permissions, boolean cells (#1578)
Co-authored-by: vburlachenko <[email protected]>
1 parent 271d8b5 commit 60f2747

File tree

8 files changed

+88
-92
lines changed

8 files changed

+88
-92
lines changed

odd-platform-api/src/main/java/org/opendatadiscovery/oddplatform/repository/reactive/ReferenceDataRepositoryImpl.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,12 @@ public Mono<LookupTableRowList> updateLookupTableRow(final LookupTableDto table,
249249
final Map<String, Object> columnWithValues = new HashMap<>();
250250

251251
for (final LookupTablesDefinitionsPojo targetColumn : columnNames) {
252+
final LookupTableColumnTypes dataType =
253+
LookupTableColumnTypes.resolveByTypeString(targetColumn.getColumnType());
254+
252255
columnWithValues.put(targetColumn.getColumnName().toLowerCase(),
253-
getColumnInputData(item, targetColumn,
254-
LookupTableColumnTypes.resolveByTypeString(targetColumn.getColumnType())));
256+
DSL.val(getColumnInputData(item, targetColumn, dataType),
257+
dataType.getDataType()));
255258
}
256259

257260
return jooqReactiveOperationsCustomTables.mono(
@@ -369,8 +372,8 @@ private Mono<List<Integer>> getUniqueConstraintUpdateQuery(final ReferenceTableC
369372
}
370373

371374
private Mono<List<Integer>> renameSequencesUpdateQuery(final String newColumnName,
372-
final LookupTablesDefinitionsPojo column,
373-
final String tableName) {
375+
final LookupTablesDefinitionsPojo column,
376+
final String tableName) {
374377
final String template = buildSequenceNameTemplate(tableName, column.getColumnName());
375378

376379
final SelectConditionStep<Record1<String>> sequences =

odd-platform-specification/components.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3894,7 +3894,6 @@ components:
38943894
type: string
38953895
required:
38963896
- field_id
3897-
- value
38983897

38993898
LookupTableRowList:
39003899
type: object

odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@ const DatasetDataTableRowCell = ({
2727
const { meta: tableMeta } = table.options;
2828
const isEditing = row.getIsSelected();
2929

30-
const onChange = useCallback(
31-
(v: unknown) => {
32-
tableMeta?.setEditedRowsData(prev => ({
33-
...prev,
34-
[row.id]: {
35-
...prev[row.id],
36-
[column.id]: v,
37-
},
38-
}));
39-
},
40-
[row.id, column.id]
41-
);
30+
const onChange = useCallback((v: unknown) => {
31+
tableMeta?.setEditedRowsData(prev => ({
32+
...prev,
33+
[row.id]: {
34+
...prev[row.id],
35+
[column.id]: v,
36+
},
37+
}));
38+
}, []);
4239

4340
const renderCell = (type?: LookupTableFieldType) => {
4441
const value = getValue();

odd-platform-ui/src/components/DataEntityDetails/DatasetData/DatasetDataTable/DatasetDataTableRowCell/DatasetDataTableRowCellDate.tsx

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Box, Typography } from '@mui/material';
2-
import React, { useCallback, useMemo } from 'react';
2+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
33
import { AppDatePicker } from 'components/shared/elements';
44
import { format, isValid } from 'date-fns';
55
import type { RowCellProps } from './interfaces';
@@ -15,19 +15,24 @@ const DatasetDataTableRowCellDate: React.FC<Props> = ({
1515
isEditing,
1616
onChange,
1717
}) => {
18-
const handleChange = useCallback((date: typeof initialValue) => {
19-
if (date && isValid(date)) {
20-
onChange(format(date, POSTGRES_DATE_FORMAT));
21-
return;
22-
}
23-
onChange(null);
18+
const [date, setDate] = useState(initialValue);
19+
const handleChange = useCallback((v: typeof initialValue) => {
20+
setDate(v);
2421
}, []);
2522

2623
const defaultDate = useMemo(
27-
() => (initialValue ? format(initialValue, POSTGRES_DATE_FORMAT) : undefined),
28-
[initialValue]
24+
() => (date ? format(date, POSTGRES_DATE_FORMAT) : undefined),
25+
[date]
2926
);
3027

28+
useEffect(() => {
29+
if (date && isValid(date) && isEditing) {
30+
onChange(format(date, POSTGRES_DATE_FORMAT));
31+
return;
32+
}
33+
onChange(null);
34+
}, [date, isEditing]);
35+
3136
return isEditing ? (
3237
<AppDatePicker
3338
inputFormat={POSTGRES_DATE_FORMAT}

odd-platform-ui/src/components/DataEntityDetails/DatasetStructure/DatasetStructure.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ const DatasetStructure: FC = () => {
3535
Permission.DATASET_FIELD_ADD_TERM,
3636
Permission.DATASET_FIELD_DELETE_TERM,
3737
Permission.DATASET_FIELD_INTERNAL_NAME_UPDATE,
38-
Permission.LOOKUP_TABLE_DEFINITION_CREATE,
39-
Permission.LOOKUP_TABLE_DEFINITION_UPDATE,
40-
Permission.LOOKUP_TABLE_DEFINITION_DELETE,
4138
]}
4239
resourcePermissions={resourcePermissions}
4340
Component={DatasetStructureOverview}

odd-platform-ui/src/components/DataEntityDetails/DatasetStructure/DatasetStructureOverview/DatasetStructureView/DatasetFieldOverview/DatasetFieldHeader/DatasetFieldHeader.tsx

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -83,48 +83,44 @@ const DatasetFieldHeader = ({ field }: DatasetFieldHeaderProps) => {
8383
</Grid>
8484
{!field.isPrimaryKey && !!lookupTableField && lookupTableId && (
8585
<Grid item display='flex' alignItems='center'>
86-
<WithPermissions permissionTo={Permission.LOOKUP_TABLE_DEFINITION_UPDATE}>
87-
<ColumnForm
88-
btnEl={
89-
<Button
90-
text={t('Edit')}
91-
buttonType='secondary-m'
92-
startIcon={<EditIcon />}
93-
/>
86+
<ColumnForm
87+
btnEl={
88+
<Button
89+
text={t('Edit')}
90+
buttonType='secondary-m'
91+
startIcon={<EditIcon />}
92+
/>
93+
}
94+
lookupTableField={lookupTableField}
95+
lookupTableId={lookupTableId}
96+
/>
97+
<AppPopover
98+
renderOpenBtn={({ onClick, ariaDescribedBy }) => (
99+
<Button
100+
aria-describedby={ariaDescribedBy}
101+
buttonType='secondary-m'
102+
icon={<KebabIcon />}
103+
onClick={onClick}
104+
sx={{ ml: 1 }}
105+
/>
106+
)}
107+
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
108+
transformOrigin={{ vertical: -5, horizontal: 67 }}
109+
>
110+
<ConfirmationDialog
111+
actionTitle={t('Are you sure you want to delete this column?')}
112+
actionName={t('Delete column')}
113+
actionText={
114+
<>
115+
&quot;{field.name}&quot; {t('will be deleted permanently')}
116+
</>
94117
}
95-
lookupTableField={lookupTableField}
96-
lookupTableId={lookupTableId}
118+
onConfirm={() =>
119+
handleColumnDelete(lookupTableId, lookupTableField.fieldId)
120+
}
121+
actionBtn={<AppMenuItem>{t('Delete')}</AppMenuItem>}
97122
/>
98-
</WithPermissions>
99-
<WithPermissions permissionTo={Permission.LOOKUP_TABLE_DEFINITION_DELETE}>
100-
<AppPopover
101-
renderOpenBtn={({ onClick, ariaDescribedBy }) => (
102-
<Button
103-
aria-describedby={ariaDescribedBy}
104-
buttonType='secondary-m'
105-
icon={<KebabIcon />}
106-
onClick={onClick}
107-
sx={{ ml: 1 }}
108-
/>
109-
)}
110-
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
111-
transformOrigin={{ vertical: -5, horizontal: 67 }}
112-
>
113-
<ConfirmationDialog
114-
actionTitle={t('Are you sure you want to delete this column?')}
115-
actionName={t('Delete column')}
116-
actionText={
117-
<>
118-
&quot;{field.name}&quot; {t('will be deleted permanently')}
119-
</>
120-
}
121-
onConfirm={() =>
122-
handleColumnDelete(lookupTableId, lookupTableField.fieldId)
123-
}
124-
actionBtn={<AppMenuItem>{t('Delete')}</AppMenuItem>}
125-
/>
126-
</AppPopover>
127-
</WithPermissions>
123+
</AppPopover>
128124
</Grid>
129125
)}
130126
</Grid>

odd-platform-ui/src/components/DataEntityDetails/DatasetStructure/DatasetStructureOverview/DatasetStructureView/DatasetStructureList/DatasetStructureList.tsx

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { type FC, useCallback, useEffect, useMemo, useRef } from 'react';
22
import { useVirtualizer } from '@tanstack/react-virtual';
3-
import { Permission, type DataSetField } from 'generated-sources';
3+
import { type DataSetField } from 'generated-sources';
44
import { useDataEntityRouteParams } from 'routes';
55
import { Box } from '@mui/material';
66
import { AddIcon } from 'components/shared/icons';
@@ -9,7 +9,6 @@ import { useTranslation } from 'react-i18next';
99
import ColumnForm from 'components/shared/elements/forms/ColumnForm';
1010
import { getDataEntityDetails } from 'redux/selectors';
1111
import { useAppSelector } from 'redux/lib/hooks';
12-
import { WithPermissions } from 'components/shared/contexts';
1312
import DatasetStructureItem from './DatasetStructureItem/DatasetStructureItem';
1413
import * as S from './DatasetStructureList.styles';
1514
import useStructure from '../../lib/useStructure';
@@ -66,32 +65,30 @@ const DatasetStructureList: FC = () => {
6665
return (
6766
<S.Scrollable ref={containerRef}>
6867
<S.Container $height={virtualizer.getTotalSize()}>
69-
<S.ItemContainer $translateY={items[0].start}>
68+
<S.ItemContainer $translateY={items[0]?.start || 0}>
7069
{items.map(({ key, index, size }) => (
7170
<div key={key} data-index={index} ref={virtualizer.measureElement}>
7271
{renderStructureItem(datasetStructureRoot[index], 0, size)}
7372
</div>
7473
))}
7574
{lookupTableId && (
76-
<WithPermissions permissionTo={Permission.LOOKUP_TABLE_DEFINITION_CREATE}>
77-
<Box
78-
display='flex'
79-
alignItems='center'
80-
pl={1}
81-
height={theme => theme.spacing(6)}
82-
>
83-
<ColumnForm
84-
btnEl={
85-
<Button
86-
text={t('Add column')}
87-
buttonType='tertiary-m'
88-
startIcon={<AddIcon />}
89-
/>
90-
}
91-
lookupTableId={lookupTableId}
92-
/>
93-
</Box>
94-
</WithPermissions>
75+
<Box
76+
display='flex'
77+
alignItems='center'
78+
pl={1}
79+
height={theme => theme.spacing(6)}
80+
>
81+
<ColumnForm
82+
btnEl={
83+
<Button
84+
text={t('Add column')}
85+
buttonType='tertiary-m'
86+
startIcon={<AddIcon />}
87+
/>
88+
}
89+
lookupTableId={lookupTableId}
90+
/>
91+
</Box>
9592
)}
9693
</S.ItemContainer>
9794
</S.Container>

odd-platform-ui/src/components/shared/elements/forms/ColumnForm.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ const ColumnForm = ({ btnEl, lookupTableId, lookupTableField }: ColumnFormProps)
171171
renderValue={value => value as LookupTableFieldType}
172172
>
173173
{Object.values(LookupTableFieldType)
174-
.filter(type => ['VARCHAR', 'INTEGER', 'DECIMAL', 'DATE'].includes(type))
174+
.filter(type =>
175+
['VARCHAR', 'INTEGER', 'DECIMAL', 'DATE', 'BOOLEAN'].includes(type)
176+
)
175177
.map(type => (
176178
<AppMenuItem key={type} value={type}>
177179
{type}

0 commit comments

Comments
 (0)