Skip to content

Commit

Permalink
Support primary and sort keys flags (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
DementevNikita authored Jun 30, 2022
1 parent 5497c74 commit ad56e85
Show file tree
Hide file tree
Showing 14 changed files with 185 additions and 26 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
spring-webflux = '5.3.19'
reactor-extra = '3.4.8'
micrometer-registry-prometheus = '1.9.0'
ingestion-contract-server = '0.1.11'
ingestion-contract-server = '0.1.14'
oddrn-generator-java = '0.1.10'
apache-collections = '4.4'
apache-lang = '3.12.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public DatasetFieldPojo mapField(final DataSetField field) {
.setOddrn(field.getOddrn())
.setParentFieldOddrn(field.getParentFieldOddrn())
.setFieldOrder(0)
.setIsPrimaryKey(field.getIsPrimaryKey() != null ? field.getIsPrimaryKey() : false)
.setIsSortKey(field.getIsSortKey() != null ? field.getIsSortKey() : false)
.setStats(JSONB.jsonb(JSONSerDeUtils.serializeJson(field.getStats())))
.setType(JSONB.jsonb(JSONSerDeUtils.serializeJson(field.getType())))
.setIsKey(field.getIsKey())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private DataSetField mapDatasetField(final DatasetFieldDto dto, final Long paren
.type(mapDatasetFieldType(pojo.getType().data()))
.isKey(pojo.getIsKey())
.isValue(pojo.getIsValue())
.isPrimaryKey(pojo.getIsPrimaryKey())
.isSortKey(pojo.getIsSortKey())
.externalDescription(pojo.getExternalDescription())
.internalDescription(pojo.getInternalDescription())
.labels(mapLabels(dto.getLabelPojos()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE dataset_field
ADD COLUMN is_primary_key BOOLEAN NOT NULL DEFAULT FALSE,
ADD COLUMN is_sort_key BOOLEAN NOT NULL DEFAULT FALSE;
4 changes: 4 additions & 0 deletions odd-platform-specification/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1130,6 +1130,10 @@ components:
type: boolean
is_value:
type: boolean
is_primary_key:
type: boolean
is_sort_key:
type: boolean
default_value:
type: string
external_description:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import type { DatasetFieldKeyType } from './DatasetStructureKeyFieldLabelStyles';
import * as S from './DatasetStructureKeyFieldLabelStyles';

interface DatasetStructureKeyFieldLabelProps {
keyType: DatasetFieldKeyType;
}

const DatasetStructureKeyFieldLabel: React.FC<
DatasetStructureKeyFieldLabelProps
> = ({ keyType }) => (
<S.Container title={keyType}>
<S.FilledContainer $keyType={keyType}>{keyType} key</S.FilledContainer>
</S.Container>
);

export default DatasetStructureKeyFieldLabel;
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import styled from 'styled-components';

export type DatasetFieldKeyType = 'primary' | 'sort';

interface FilledContainerProps {
$keyType: DatasetFieldKeyType;
}

export const Container = styled('div')(({ theme }) => ({
display: 'inline-flex',
alignItems: 'center',
marginTop: theme.spacing(0.3),
whiteSpace: 'nowrap',
}));
export const FilledContainer = styled('span')<FilledContainerProps>(
({ theme, $keyType }) => ({
fontSize: theme.typography.body2.fontSize,
lineHeight: theme.typography.body2.lineHeight,
borderRadius: '12px',
border: '1px solid',
padding: theme.spacing(0, 1),
backgroundColor: theme.palette.datasetFieldKey[$keyType].background,
borderColor: theme.palette.datasetFieldKey[$keyType].border,
marginLeft: '10px',
})
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from 'react';
import { ButtonProps, Collapse, Grid, Typography } from '@mui/material';
import {
Box,
ButtonProps,
Collapse,
Grid,
Typography,
} from '@mui/material';
import round from 'lodash/round';
import {
DataSetField,
Expand All @@ -12,9 +18,9 @@ import {
DatasetStatsLabelMap,
} from 'redux/interfaces/datasetStructure';
import { format } from 'date-fns';
import DatasetStructureKeyFieldLabel from 'components/DataEntityDetails/DatasetStructure/DatasetStructureKeyFieldLabel/DatasetStructureKeyFieldLabel';
import NumberFormatted from 'components/shared/NumberFormatted/NumberFormatted';
import LabeledInfoItem from 'components/shared/LabeledInfoItem/LabeledInfoItem';
import LabelItem from 'components/shared/LabelItem/LabelItem';
import PlusIcon from 'components/shared/Icons/PlusIcon';
import MinusIcon from 'components/shared/Icons/MinusIcon';
import LineBreakIcon from 'components/shared/Icons/LineBreakIcon';
Expand All @@ -23,6 +29,8 @@ import DatasetStructureFieldTypeLabel from 'components/DataEntityDetails/Dataset
import AppTooltip from 'components/shared/AppTooltip/AppTooltip';
import AppIconButton from 'components/shared/AppIconButton/AppIconButton';
import AppButton from 'components/shared/AppButton/AppButton';
import TruncatedLabel from 'components/shared/TruncatedLabel/TruncatedLabel';

import DatasetFieldInfoEditFormContainer from 'components/DataEntityDetails/DatasetStructure/DatasetStructureTable/DatasetStructureList/DatasetStructureItem/DatasetFieldInfoEditForm/DatasetFieldInfoEditFormContainer';
import DatasetFieldEnumsEditFormContainer from 'components/DataEntityDetails/DatasetStructure/DatasetStructureTable/DatasetStructureList/DatasetStructureItem/DatasetFieldEnumsEditForm/DatasetFieldEnumsEditFormContainer';
import { ButtonColors } from 'components/shared/AppButton/AppButtonStyles';
Expand Down Expand Up @@ -53,7 +61,6 @@ const DatasetStructureItem: React.FC<DatasetStructureItemProps> = ({
onSizeChange,
}) => {
const [open, setOpen] = React.useState<boolean>(initialStateOpen);

let fieldStats = {} as DataSetFormattedStats;
switch (datasetField.type.type) {
case DataSetFieldTypeTypeEnum.STRING:
Expand Down Expand Up @@ -110,7 +117,6 @@ const DatasetStructureItem: React.FC<DatasetStructureItemProps> = ({
const nestedBlockStyle = {
paddingLeft: `${Math.min(nesting, 10) * 20 + 8}px`,
};

let collapseBlock;
if (childFields?.length) {
collapseBlock = (
Expand Down Expand Up @@ -147,7 +153,6 @@ const DatasetStructureItem: React.FC<DatasetStructureItemProps> = ({
</AppButton>
);
}, [datasetField.enumValueCount]);

return (
<Grid container>
<Grid item container>
Expand All @@ -169,28 +174,26 @@ const DatasetStructureItem: React.FC<DatasetStructureItemProps> = ({
<Grid item sx={{ mr: 0.75 }}>
{collapseBlock}
</Grid>
<Grid item container>
<Grid
item
xs={12}
container
alignItems="center"
justifyContent="flex-start"
sx={{ pr: 9 }}
>
<Grid item container alignItems="center">
<Box sx={{ display: 'flex', alignItems: 'start' }}>
<AppTooltip title={() => datasetField.name}>
<Typography noWrap>
{(datasetField.isKey && 'Key') ||
(datasetField.isValue && 'Value') ||
datasetField.name}
</Typography>
</AppTooltip>
<div>
{datasetField.labels?.map(label => (
<LabelItem key={label.id} labelName={label.name} />
))}
</div>
</Grid>
<TruncatedLabel
onSizeChange={onSizeChange}
labelList={datasetField.labels}
/>
{datasetField.isPrimaryKey && (
<DatasetStructureKeyFieldLabel keyType="primary" />
)}
{datasetField.isSortKey && (
<DatasetStructureKeyFieldLabel keyType="sort" />
)}
</Box>
<Grid item xs={12} sx={{ pr: 2.5 }}>
<AppTooltip
title={() => datasetField.internalDescription}
Expand Down
12 changes: 7 additions & 5 deletions odd-platform-ui/src/components/shared/AppPopover/AppPopover.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import React from 'react';
import { PopoverProps } from '@mui/material';
import { Box, PopoverProps, Theme } from '@mui/material';
import { SxProps } from '@mui/system';
import * as S from './AppPopoverStyles';

interface AppPopoverProps extends Omit<PopoverProps, 'open'> {
renderOpenBtn: (props: {
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
ariaDescribedBy: string | undefined;
}) => React.ReactElement;
childrenSx?: SxProps<Theme>;
}

const AppPopover: React.FC<AppPopoverProps> = ({
children,
anchorOrigin,
renderOpenBtn,
sx,
childrenSx,
...props
}) => {
const [anchorEl, setAnchorEl] = React.useState<HTMLButtonElement | null>(
Expand All @@ -35,10 +38,9 @@ const AppPopover: React.FC<AppPopoverProps> = ({
const id = open ? 'appPopover' : undefined;

return (
<div>
<>
{renderOpenBtn({ onClick: handleClick, ariaDescribedBy: id })}
<S.AppPopover
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
sx={sx}
id={id}
Expand All @@ -48,9 +50,9 @@ const AppPopover: React.FC<AppPopoverProps> = ({
anchorOrigin={anchorOrigin}
disableRestoreFocus
>
{children}
<Box sx={childrenSx}>{children}</Box>
</S.AppPopover>
</div>
</>
);
};
export default AppPopover;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import TruncateMarkup from 'react-truncate-markup';
import { Label } from 'generated-sources';
import LabelItem from 'components/shared/LabelItem/LabelItem';
import TruncatedLabelMenu from './TruncatedLabelMenu/TruncatedLabelMenu';

interface TruncatedLabelProps {
labelList?: Label[];
onSizeChange: () => void;
}

const TruncatedLabel: React.FC<TruncatedLabelProps> = ({
labelList,
onSizeChange,
}) => (
<div>
<TruncateMarkup
lines={1}
onTruncate={() => onSizeChange()}
ellipsis={<TruncatedLabelMenu labelList={labelList} />}
>
<div>
{labelList?.map(label => (
<TruncateMarkup.Atom key={label.id}>
<LabelItem labelName={label.name} />
</TruncateMarkup.Atom>
))}
</div>
</TruncateMarkup>
</div>
);
export default TruncatedLabel;
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import LabelItem from 'components/shared/LabelItem/LabelItem';
import { Label } from 'generated-sources';
import AppIconButton from 'components/shared/AppIconButton/AppIconButton';
import MoreIcon from 'components/shared/Icons/MoreIcon';
import AppPopover from 'components/shared/AppPopover/AppPopover';

interface TruncatedLabelMenuProps {
labelList?: Label[];
}

const TruncatedLabelMenu: React.FC<TruncatedLabelMenuProps> = ({
labelList,
}) => (
<AppPopover
childrenSx={{ width: '280px' }}
renderOpenBtn={({ onClick, ariaDescribedBy }) => (
<AppIconButton
sx={{ ml: 0.5 }}
ariaDescribedBy={ariaDescribedBy}
color="expand"
icon={<MoreIcon />}
onClick={onClick}
/>
)}
anchorOrigin={{ vertical: 'bottom', horizontal: 24 }}
transformOrigin={{ vertical: -4, horizontal: 'right' }}
>
{labelList?.map(label => (
<LabelItem key={label.id} labelName={label.name} />
))}
</AppPopover>
);

export default TruncatedLabelMenu;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { TypographyProps } from '@mui/material';
import styled from 'styled-components';

export const TruncatedList = styled('span')(({ theme }) => ({
marginBottom: theme.spacing(0.5),
marginLeft: theme.spacing(0.5),
'& > *': {
margin: theme.spacing(0, 0.25),
},
}));

export const LinkContent = styled('div')<TypographyProps>(() => ({
display: 'inline-flex',
}));
7 changes: 7 additions & 0 deletions odd-platform-ui/src/theme/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ interface TagType {

type AlertType = Record<AlertStatus, ItemColors>;

interface DatasetFieldKeyType {
primary: ItemColors;
sort: ItemColors;
}

declare module '@mui/material/styles' {
interface Palette {
entityClass: EntityClasses;
Expand All @@ -77,6 +82,7 @@ declare module '@mui/material/styles' {
tag: TagType;
structureLabel: StructureLabelType;
alert: AlertType;
datasetFieldKey: DatasetFieldKeyType;
backgrounds: Partial<BackgroundType>;
texts: TextType;
textField: ItemCondition;
Expand All @@ -90,6 +96,7 @@ declare module '@mui/material/styles' {
tag?: TagType;
structureLabel?: StructureLabelType;
alert?: AlertType;
datasetFieldKey?: DatasetFieldKeyType;
backgrounds?: Partial<BackgroundType>;
texts?: TextType;
textField?: ItemCondition;
Expand Down
12 changes: 12 additions & 0 deletions odd-platform-ui/src/theme/palette.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,18 @@ export const palette = createPalette({
TYPE_DURATION: { border: colors.blue40 },
TYPE_UNKNOWN: { border: colors.black10 },
},
datasetFieldKey: {
primary: {
background: colors.blue10,
color: colors.black70,
border: colors.blue30,
},
sort: {
background: colors.blue10,
color: colors.black70,
border: colors.blue10,
},
},
alert: {
OPEN: {
background: colors.red10,
Expand Down

0 comments on commit ad56e85

Please sign in to comment.