Skip to content

Commit

Permalink
Fix LinkedUrlList for DataQualityTests (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
DementevNikita authored Jan 25, 2023
1 parent 92ae09b commit dfc8de7
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.opendatadiscovery.oddplatform.dto.attributes.DataEntityAttributes;
import org.opendatadiscovery.oddplatform.dto.attributes.LinkedUrlAttribute;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DataEntityPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DataEntityTaskRunPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DataSourcePojo;
Expand Down Expand Up @@ -64,7 +65,7 @@ public record DataTransformerDetailsDto(Collection<DataEntityPojo> sourceList,
public record DataQualityTestDetailsDto(String suiteName,
String suiteUrl,
Collection<DataEntityPojo> datasetList,
List<String> linkedUrlList,
List<LinkedUrlAttribute> linkedUrlList,
String expectationType,
DataEntityTaskRunPojo latestTaskRun,
Map<String, String> expectationParameters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DataQualityTestAttributes extends DataEntityAttributes {
private Set<String> datasetOddrnList;

@JsonProperty("linked_url_list")
private List<String> linkedUrlList;
private List<LinkedUrlAttribute> linkedUrlList;

@JsonProperty("expectation")
private DataQualityTestExpectationAttributes expectation;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.opendatadiscovery.oddplatform.dto.attributes;

public record LinkedUrlAttribute(String name, String url) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntity;
import org.opendatadiscovery.oddplatform.api.contract.model.DataEntityClass;
Expand All @@ -28,13 +29,15 @@
import org.opendatadiscovery.oddplatform.api.contract.model.DataQualityTestExpectation;
import org.opendatadiscovery.oddplatform.api.contract.model.DataQualityTestSeverity;
import org.opendatadiscovery.oddplatform.api.contract.model.DataSetStats;
import org.opendatadiscovery.oddplatform.api.contract.model.LinkedUrl;
import org.opendatadiscovery.oddplatform.api.contract.model.PageInfo;
import org.opendatadiscovery.oddplatform.dto.DataEntityClassDto;
import org.opendatadiscovery.oddplatform.dto.DataEntityDetailsDto;
import org.opendatadiscovery.oddplatform.dto.DataEntityDimensionsDto;
import org.opendatadiscovery.oddplatform.dto.DataEntityDto;
import org.opendatadiscovery.oddplatform.dto.DataEntityTypeDto;
import org.opendatadiscovery.oddplatform.dto.DataSourceDto;
import org.opendatadiscovery.oddplatform.dto.attributes.LinkedUrlAttribute;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DataEntityPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DataEntityStatisticsPojo;
import org.opendatadiscovery.oddplatform.model.tables.pojos.DataQualityTestSeverityPojo;
Expand Down Expand Up @@ -96,7 +99,9 @@ public DataEntity mapPojo(final DataEntityDimensionsDto dto) {
}

if (entityClasses.contains(DataEntityClassDto.DATA_QUALITY_TEST)) {
entity.datasetsList(dto.getDataQualityTestDetailsDto()
entity.setLinkedUrlList(mapLinkedUrlList(dto.getDataQualityTestDetailsDto().linkedUrlList()));

entity.setDatasetsList(dto.getDataQualityTestDetailsDto()
.datasetList()
.stream()
.distinct()
Expand Down Expand Up @@ -251,7 +256,7 @@ public DataEntityDetails mapDtoDetails(final DataEntityDetailsDto dto) {
.distinct()
.map(this::mapReference)
.collect(Collectors.toList()))
.linkedUrlList(dto.getDataQualityTestDetailsDto().linkedUrlList())
.linkedUrlList(mapLinkedUrlList(dto.getDataQualityTestDetailsDto().linkedUrlList()))
.latestRun(dataEntityRunMapper.mapDataEntityRun(
dto.getDataEntity().getId(),
dto.getDataQualityTestDetailsDto().latestTaskRun())
Expand Down Expand Up @@ -302,7 +307,7 @@ public DataEntity mapDataQualityTest(final DataEntityDimensionsDto dto,
.suiteUrl(dqDto.suiteUrl())
.expectation(mapDataQualityTestExpectation(dqDto))
.latestRun(latestRun)
.linkedUrlList(dqDto.linkedUrlList())
.linkedUrlList(mapLinkedUrlList(dqDto.linkedUrlList()))
.severity(severity != null ? DataQualityTestSeverity.valueOf(severity) : null)
.datasetsList(dqDto
.datasetList()
Expand Down Expand Up @@ -404,6 +409,18 @@ public DataEntityUsageInfo mapUsageInfo(final DataEntityStatisticsPojo pojo,
);
}

private LinkedUrl mapLinkedUrl(final LinkedUrlAttribute linkedUrlAttribute) {
return new LinkedUrl()
.url(linkedUrlAttribute.url())
.name(linkedUrlAttribute.name());
}

private List<LinkedUrl> mapLinkedUrlList(final Collection<LinkedUrlAttribute> linkedUrlAttributes) {
return CollectionUtils.emptyIfNull(linkedUrlAttributes)
.stream()
.map(this::mapLinkedUrl).toList();
}

private DataEntityRef mapReference(final DataEntityDto dto) {
return mapReference(dto.getDataEntity()).hasAlerts(dto.isHasAlerts());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -236,6 +237,8 @@ public void failedDQTestAlertIngestionTest() {
expectedDetails.setLatestRun(
buildExpectedDataEntityRun(ingestionMap.get(dataQualityTest.getOddrn()), dataQualityTestRun));

expectedDetails.setLinkedUrlList(Collections.emptyList());

assertDataEntityDetailsEqual(expectedDetails, (expected, actual) ->
assertThat(actual.getDatasetsList())
.usingRecursiveFieldByFieldElementComparatorIgnoringFields("entityClasses")
Expand Down
13 changes: 12 additions & 1 deletion odd-platform-specification/components.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,17 @@ components:
- MAJOR
- CRITICAL

LinkedUrl:
type: object
properties:
url:
type: string
name:
type: string
required:
- url
- name

DataQualityTest:
allOf:
- $ref: '#/components/schemas/DataEntityBaseObject'
Expand All @@ -780,7 +791,7 @@ components:
linked_url_list:
type: array
items:
type: string
$ref: '#/components/schemas/LinkedUrl'
latest_run:
$ref: '#/components/schemas/DataEntityRun'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React from 'react';
import { DataQualityTestExpectation } from 'generated-sources';
import type { DataQualityTestExpectation, LinkedUrl } from 'generated-sources';
import { Grid, Typography } from '@mui/material';
import { AppButton } from 'components/shared';
import { DropdownIcon } from 'components/shared/Icons';
import * as S from './OverviewExpectationsStyles';

interface OverviewExpectationsProps {
parameters: DataQualityTestExpectation | undefined;
linkedUrlList: string[] | undefined;
linkedUrlList: LinkedUrl[] | undefined;
}

const OverviewExpectations: React.FC<OverviewExpectationsProps> = ({
Expand Down Expand Up @@ -40,16 +40,17 @@ const OverviewExpectations: React.FC<OverviewExpectationsProps> = ({
<S.Divider />
<Typography variant='h4'>Links</Typography>
<Grid container flexDirection='column'>
{linkedUrlList?.map(link => (
{linkedUrlList?.map(({ name, url }) => (
<AppButton
to={{ pathname: link }}
key={link}
to={{ pathname: url }}
key={url}
sx={{ my: 0.25 }}
size='medium'
color='tertiary'
linkTarget='_blank'
truncate
>
{link}
{name}
</AppButton>
))}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from 'react';
import { Box, Grid, SelectChangeEvent, Typography } from '@mui/material';
import type { SelectChangeEvent } from '@mui/material';
import { Box, Grid, Typography } from '@mui/material';
import { AppButton, AppMenuItem, AppSelect, LabeledInfoItem } from 'components/shared';
import {
DataQualityTestExpectation,
DataQualityTestSeverity,
Permission,
} from 'generated-sources';
import type { DataQualityTestExpectation } from 'generated-sources';
import { DataQualityTestSeverity, Permission } from 'generated-sources';
import {
getDatasetTestListFetchingStatuses,
getQualityTestByTestId,
Expand Down Expand Up @@ -128,19 +126,17 @@ const TestReportDetailsOverview: React.FC = () => {
<Grid item sx={{ mt: 2.25 }} xs={12}>
<Typography variant='h4'>Links</Typography>
<Grid container sx={{ mt: 1 }}>
{qualityTest.linkedUrlList.map(link => (
{qualityTest.linkedUrlList.map(({ name, url }) => (
<AppButton
to={{ pathname: link }}
key={link}
sx={{
py: 0.25,
}}
to={{ pathname: url }}
key={url}
sx={{ py: 0.25 }}
size='medium'
color='tertiary'
linkTarget='_blank'
truncate
>
{link}
{name}
</AppButton>
))}
</Grid>
Expand Down
57 changes: 26 additions & 31 deletions odd-platform-ui/src/components/shared/AppButton/AppButton.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, { HTMLAttributeAnchorTarget } from 'react';
import { Box, ButtonProps, Theme } from '@mui/material';
import type { HTMLAttributeAnchorTarget } from 'react';
import React from 'react';
import type { ButtonProps } from '@mui/material';
import { Link } from 'react-router-dom';
import { SxProps } from '@mui/system';
import { ButtonColors, Loader, StyledAppButton } from './AppButtonStyles';
import type { ButtonColors } from './AppButtonStyles';
import { Loader, StyledAppButton } from './AppButtonStyles';

interface AppButtonProps
extends Pick<
Expand All @@ -27,48 +28,42 @@ interface AppButtonProps
truncate?: boolean;
linkTarget?: HTMLAttributeAnchorTarget;
isLoading?: boolean;
containerSx?: SxProps<Theme>;
}

const AppButton: React.FC<AppButtonProps> = React.forwardRef(
(
{ color, children, truncate, to, linkTarget, isLoading, containerSx, ...props },
ref
) => {
({ color, children, truncate, to, linkTarget, isLoading, ...props }, ref) => {
const [isOverflowed, setIsOverflowed] = React.useState(truncate);
const buttonRef = React.useRef<HTMLButtonElement>(null);

React.useEffect(() => {
const element = buttonRef.current;
if (element) {
if (element && !truncate) {
const { scrollWidth, clientWidth } = element;
setIsOverflowed(scrollWidth > clientWidth);
}
}, [buttonRef.current]);
}, [buttonRef]);

if (to) {
return (
<Box sx={containerSx}>
<Link
to={to}
style={{
width: 'inherit',
pointerEvents: props.disabled ? 'none' : undefined,
}}
target={linkTarget}
<Link
to={to}
style={{
inlineSize: 'inherit',
pointerEvents: props.disabled ? 'none' : undefined,
}}
target={linkTarget}
>
<StyledAppButton
{...props}
focusRipple
$color={color}
ref={ref || buttonRef}
disableRipple
$isOverflowed={isOverflowed}
>
<StyledAppButton
{...props}
focusRipple
$color={color}
ref={ref || buttonRef}
disableRipple
$isOverflowed={isOverflowed}
>
{isLoading ? <Loader /> : children}
</StyledAppButton>
</Link>
</Box>
{isLoading ? <Loader /> : children}
</StyledAppButton>
</Link>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export const StyledAppButton = styled(Button)<AppButtonStyleProps>(
textOverflow: 'ellipsis',
overflow: 'hidden',
...breakpointDownLgBody2,
...($isOverflowed && { width: 'inherit', display: 'block' }),
...($isOverflowed && {
width: 'inherit',
maxWidth: 'fit-content',
display: 'block',
}),
},
[`&.${buttonClasses.text}`]: {
padding: isTertiary($color) ? theme.spacing(0, 0.5) : theme.spacing(0.25, 1.5),
Expand Down
Loading

0 comments on commit dfc8de7

Please sign in to comment.