Skip to content

Commit

Permalink
Bugfix: date cells, lookup table definition permissions, boolean cells (
Browse files Browse the repository at this point in the history
#1578)

Co-authored-by: vburlachenko <slaboezveno3@gmail.com>
  • Loading branch information
AndreyNenashev and Vladysl committed Jan 11, 2024
1 parent 271d8b5 commit 60f2747
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,12 @@ public Mono<LookupTableRowList> updateLookupTableRow(final LookupTableDto table,
final Map<String, Object> 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(
Expand Down Expand Up @@ -369,8 +372,8 @@ private Mono<List<Integer>> getUniqueConstraintUpdateQuery(final ReferenceTableC
}

private Mono<List<Integer>> 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<Record1<String>> sequences =
Expand Down
1 change: 0 additions & 1 deletion odd-platform-specification/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3894,7 +3894,6 @@ components:
type: string
required:
- field_id
- value

LookupTableRowList:
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -15,19 +15,24 @@ const DatasetDataTableRowCellDate: React.FC<Props> = ({
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 ? (
<AppDatePicker
inputFormat={POSTGRES_DATE_FORMAT}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ const DatasetStructure: FC = () => {
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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,48 +83,44 @@ const DatasetFieldHeader = ({ field }: DatasetFieldHeaderProps) => {
</Grid>
{!field.isPrimaryKey && !!lookupTableField && lookupTableId && (
<Grid item display='flex' alignItems='center'>
<WithPermissions permissionTo={Permission.LOOKUP_TABLE_DEFINITION_UPDATE}>
<ColumnForm
btnEl={
<Button
text={t('Edit')}
buttonType='secondary-m'
startIcon={<EditIcon />}
/>
<ColumnForm
btnEl={
<Button
text={t('Edit')}
buttonType='secondary-m'
startIcon={<EditIcon />}
/>
}
lookupTableField={lookupTableField}
lookupTableId={lookupTableId}
/>
<AppPopover
renderOpenBtn={({ onClick, ariaDescribedBy }) => (
<Button
aria-describedby={ariaDescribedBy}
buttonType='secondary-m'
icon={<KebabIcon />}
onClick={onClick}
sx={{ ml: 1 }}
/>
)}
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
transformOrigin={{ vertical: -5, horizontal: 67 }}
>
<ConfirmationDialog
actionTitle={t('Are you sure you want to delete this column?')}
actionName={t('Delete column')}
actionText={
<>
&quot;{field.name}&quot; {t('will be deleted permanently')}
</>
}
lookupTableField={lookupTableField}
lookupTableId={lookupTableId}
onConfirm={() =>
handleColumnDelete(lookupTableId, lookupTableField.fieldId)
}
actionBtn={<AppMenuItem>{t('Delete')}</AppMenuItem>}
/>
</WithPermissions>
<WithPermissions permissionTo={Permission.LOOKUP_TABLE_DEFINITION_DELETE}>
<AppPopover
renderOpenBtn={({ onClick, ariaDescribedBy }) => (
<Button
aria-describedby={ariaDescribedBy}
buttonType='secondary-m'
icon={<KebabIcon />}
onClick={onClick}
sx={{ ml: 1 }}
/>
)}
anchorOrigin={{ vertical: 'bottom', horizontal: 'left' }}
transformOrigin={{ vertical: -5, horizontal: 67 }}
>
<ConfirmationDialog
actionTitle={t('Are you sure you want to delete this column?')}
actionName={t('Delete column')}
actionText={
<>
&quot;{field.name}&quot; {t('will be deleted permanently')}
</>
}
onConfirm={() =>
handleColumnDelete(lookupTableId, lookupTableField.fieldId)
}
actionBtn={<AppMenuItem>{t('Delete')}</AppMenuItem>}
/>
</AppPopover>
</WithPermissions>
</AppPopover>
</Grid>
)}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { type FC, useCallback, useEffect, useMemo, useRef } from 'react';
import { useVirtualizer } from '@tanstack/react-virtual';
import { Permission, type DataSetField } from 'generated-sources';
import { type DataSetField } from 'generated-sources';
import { useDataEntityRouteParams } from 'routes';
import { Box } from '@mui/material';
import { AddIcon } from 'components/shared/icons';
Expand All @@ -9,7 +9,6 @@ import { useTranslation } from 'react-i18next';
import ColumnForm from 'components/shared/elements/forms/ColumnForm';
import { getDataEntityDetails } from 'redux/selectors';
import { useAppSelector } from 'redux/lib/hooks';
import { WithPermissions } from 'components/shared/contexts';
import DatasetStructureItem from './DatasetStructureItem/DatasetStructureItem';
import * as S from './DatasetStructureList.styles';
import useStructure from '../../lib/useStructure';
Expand Down Expand Up @@ -66,32 +65,30 @@ const DatasetStructureList: FC = () => {
return (
<S.Scrollable ref={containerRef}>
<S.Container $height={virtualizer.getTotalSize()}>
<S.ItemContainer $translateY={items[0].start}>
<S.ItemContainer $translateY={items[0]?.start || 0}>
{items.map(({ key, index, size }) => (
<div key={key} data-index={index} ref={virtualizer.measureElement}>
{renderStructureItem(datasetStructureRoot[index], 0, size)}
</div>
))}
{lookupTableId && (
<WithPermissions permissionTo={Permission.LOOKUP_TABLE_DEFINITION_CREATE}>
<Box
display='flex'
alignItems='center'
pl={1}
height={theme => theme.spacing(6)}
>
<ColumnForm
btnEl={
<Button
text={t('Add column')}
buttonType='tertiary-m'
startIcon={<AddIcon />}
/>
}
lookupTableId={lookupTableId}
/>
</Box>
</WithPermissions>
<Box
display='flex'
alignItems='center'
pl={1}
height={theme => theme.spacing(6)}
>
<ColumnForm
btnEl={
<Button
text={t('Add column')}
buttonType='tertiary-m'
startIcon={<AddIcon />}
/>
}
lookupTableId={lookupTableId}
/>
</Box>
)}
</S.ItemContainer>
</S.Container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@ const ColumnForm = ({ btnEl, lookupTableId, lookupTableField }: ColumnFormProps)
renderValue={value => value as LookupTableFieldType}
>
{Object.values(LookupTableFieldType)
.filter(type => ['VARCHAR', 'INTEGER', 'DECIMAL', 'DATE'].includes(type))
.filter(type =>
['VARCHAR', 'INTEGER', 'DECIMAL', 'DATE', 'BOOLEAN'].includes(type)
)
.map(type => (
<AppMenuItem key={type} value={type}>
{type}
Expand Down

0 comments on commit 60f2747

Please sign in to comment.