Skip to content

Commit f884eb8

Browse files
authored
feat(siblings): hiding non-existant siblings in FE (#8528)
1 parent 1a47a51 commit f884eb8

File tree

6 files changed

+201
-6
lines changed

6 files changed

+201
-6
lines changed

datahub-web-react/src/app/entity/shared/__tests__/siblingsUtils.test.ts

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ const searchResultWithSiblings = [
195195
{
196196
entity: {
197197
urn: 'urn:li:dataset:(urn:li:dataPlatform:bigquery,cypress_project.jaffle_shop.raw_orders,PROD)',
198+
exists: true,
198199
type: 'DATASET',
199200
name: 'cypress_project.jaffle_shop.raw_orders',
200201
origin: 'PROD',
@@ -328,6 +329,7 @@ const searchResultWithSiblings = [
328329
siblings: [
329330
{
330331
urn: 'urn:li:dataset:(urn:li:dataPlatform:dbt,cypress_project.jaffle_shop.raw_orders,PROD)',
332+
exists: true,
331333
type: 'DATASET',
332334
platform: {
333335
urn: 'urn:li:dataPlatform:dbt',
@@ -376,6 +378,7 @@ const searchResultWithSiblings = [
376378
{
377379
entity: {
378380
urn: 'urn:li:dataset:(urn:li:dataPlatform:dbt,cypress_project.jaffle_shop.raw_orders,PROD)',
381+
exists: true,
379382
type: 'DATASET',
380383
name: 'cypress_project.jaffle_shop.raw_orders',
381384
origin: 'PROD',
@@ -513,6 +516,169 @@ const searchResultWithSiblings = [
513516
},
514517
];
515518

519+
const searchResultWithGhostSiblings = [
520+
{
521+
entity: {
522+
urn: 'urn:li:dataset:(urn:li:dataPlatform:bigquery,cypress_project.jaffle_shop.raw_orders,PROD)',
523+
exists: true,
524+
type: 'DATASET',
525+
name: 'cypress_project.jaffle_shop.raw_orders',
526+
origin: 'PROD',
527+
uri: null,
528+
platform: {
529+
urn: 'urn:li:dataPlatform:bigquery',
530+
type: 'DATA_PLATFORM',
531+
name: 'bigquery',
532+
properties: {
533+
type: 'RELATIONAL_DB',
534+
displayName: 'BigQuery',
535+
datasetNameDelimiter: '.',
536+
logoUrl: '/assets/platforms/bigquerylogo.png',
537+
__typename: 'DataPlatformProperties',
538+
},
539+
displayName: null,
540+
info: null,
541+
__typename: 'DataPlatform',
542+
},
543+
dataPlatformInstance: null,
544+
editableProperties: null,
545+
platformNativeType: null,
546+
properties: {
547+
name: 'raw_orders',
548+
description: null,
549+
qualifiedName: null,
550+
customProperties: [],
551+
__typename: 'DatasetProperties',
552+
},
553+
ownership: null,
554+
globalTags: null,
555+
glossaryTerms: null,
556+
subTypes: {
557+
typeNames: ['table'],
558+
__typename: 'SubTypes',
559+
},
560+
domain: null,
561+
container: {
562+
urn: 'urn:li:container:348c96555971d3f5c1ffd7dd2e7446cb',
563+
platform: {
564+
urn: 'urn:li:dataPlatform:bigquery',
565+
type: 'DATA_PLATFORM',
566+
name: 'bigquery',
567+
properties: {
568+
type: 'RELATIONAL_DB',
569+
displayName: 'BigQuery',
570+
datasetNameDelimiter: '.',
571+
logoUrl: '/assets/platforms/bigquerylogo.png',
572+
__typename: 'DataPlatformProperties',
573+
},
574+
displayName: null,
575+
info: null,
576+
__typename: 'DataPlatform',
577+
},
578+
properties: {
579+
name: 'jaffle_shop',
580+
__typename: 'ContainerProperties',
581+
},
582+
subTypes: {
583+
typeNames: ['Dataset'],
584+
__typename: 'SubTypes',
585+
},
586+
deprecation: null,
587+
__typename: 'Container',
588+
},
589+
parentContainers: {
590+
count: 2,
591+
containers: [
592+
{
593+
urn: 'urn:li:container:348c96555971d3f5c1ffd7dd2e7446cb',
594+
platform: {
595+
urn: 'urn:li:dataPlatform:bigquery',
596+
type: 'DATA_PLATFORM',
597+
name: 'bigquery',
598+
properties: {
599+
type: 'RELATIONAL_DB',
600+
displayName: 'BigQuery',
601+
datasetNameDelimiter: '.',
602+
logoUrl: '/assets/platforms/bigquerylogo.png',
603+
__typename: 'DataPlatformProperties',
604+
},
605+
displayName: null,
606+
info: null,
607+
__typename: 'DataPlatform',
608+
},
609+
properties: {
610+
name: 'jaffle_shop',
611+
__typename: 'ContainerProperties',
612+
},
613+
subTypes: {
614+
typeNames: ['Dataset'],
615+
__typename: 'SubTypes',
616+
},
617+
deprecation: null,
618+
__typename: 'Container',
619+
},
620+
{
621+
urn: 'urn:li:container:b5e95fce839e7d78151ed7e0a7420d84',
622+
platform: {
623+
urn: 'urn:li:dataPlatform:bigquery',
624+
type: 'DATA_PLATFORM',
625+
name: 'bigquery',
626+
properties: {
627+
type: 'RELATIONAL_DB',
628+
displayName: 'BigQuery',
629+
datasetNameDelimiter: '.',
630+
logoUrl: '/assets/platforms/bigquerylogo.png',
631+
__typename: 'DataPlatformProperties',
632+
},
633+
displayName: null,
634+
info: null,
635+
__typename: 'DataPlatform',
636+
},
637+
properties: {
638+
name: 'cypress_project',
639+
__typename: 'ContainerProperties',
640+
},
641+
subTypes: {
642+
typeNames: ['Project'],
643+
__typename: 'SubTypes',
644+
},
645+
deprecation: null,
646+
__typename: 'Container',
647+
},
648+
],
649+
__typename: 'ParentContainersResult',
650+
},
651+
deprecation: null,
652+
siblings: {
653+
isPrimary: false,
654+
siblings: [
655+
{
656+
urn: 'urn:li:dataset:(urn:li:dataPlatform:dbt,cypress_project.jaffle_shop.raw_orders,PROD)',
657+
exists: false,
658+
type: 'DATASET',
659+
},
660+
],
661+
__typename: 'SiblingProperties',
662+
},
663+
__typename: 'Dataset',
664+
},
665+
matchedFields: [
666+
{
667+
name: 'name',
668+
value: 'raw_orders',
669+
__typename: 'MatchedField',
670+
},
671+
{
672+
name: 'id',
673+
value: 'cypress_project.jaffle_shop.raw_orders',
674+
__typename: 'MatchedField',
675+
},
676+
],
677+
insights: [],
678+
__typename: 'SearchResult',
679+
},
680+
];
681+
516682
describe('siblingUtils', () => {
517683
describe('combineEntityDataWithSiblings', () => {
518684
it('combines my metadata with my siblings as primary', () => {
@@ -564,6 +730,18 @@ describe('siblingUtils', () => {
564730
expect(result?.[0]?.matchedEntities?.[1]?.urn).toEqual(
565731
'urn:li:dataset:(urn:li:dataPlatform:bigquery,cypress_project.jaffle_shop.raw_orders,PROD)',
566732
);
733+
734+
expect(result?.[0]?.matchedEntities).toHaveLength(2);
735+
});
736+
737+
it('will not combine an entity with a ghost node', () => {
738+
const result = combineSiblingsInSearchResults(searchResultWithGhostSiblings as any);
739+
740+
expect(result).toHaveLength(1);
741+
expect(result?.[0]?.matchedEntities?.[0]?.urn).toEqual(
742+
'urn:li:dataset:(urn:li:dataPlatform:bigquery,cypress_project.jaffle_shop.raw_orders,PROD)',
743+
);
744+
expect(result?.[0]?.matchedEntities).toHaveLength(1);
567745
});
568746
});
569747

datahub-web-react/src/app/entity/shared/containers/profile/sidebar/SidebarSiblingsSection.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import styled from 'styled-components';
44
import { useDataNotCombinedWithSiblings, useEntityData } from '../../../EntityContext';
55
import { SidebarHeader } from './SidebarHeader';
66
import { CompactEntityNameList } from '../../../../../recommendations/renderer/component/CompactEntityNameList';
7-
import { Entity } from '../../../../../../types.generated';
7+
import { Dataset, Entity } from '../../../../../../types.generated';
88
import { SEPARATE_SIBLINGS_URL_PARAM, stripSiblingsFromEntity, useIsSeparateSiblingsMode } from '../../../siblingUtils';
99
import { GetDatasetQuery } from '../../../../../../graphql/dataset.generated';
1010

@@ -36,14 +36,22 @@ export const SidebarSiblingsSection = () => {
3636
const siblingEntities = entityData?.siblings?.siblings || [];
3737
const entityDataWithoutSiblings = stripSiblingsFromEntity(dataNotCombinedWithSiblings.dataset);
3838

39-
const allSiblingsInGroup = [...siblingEntities, entityDataWithoutSiblings] as Entity[];
39+
const allSiblingsInGroup = [...siblingEntities, entityDataWithoutSiblings] as Dataset[];
40+
41+
const allSiblingsInGroupThatExist = allSiblingsInGroup.filter((sibling) => sibling.exists);
42+
43+
// you are always going to be in the sibling group, so if the sibling group is just you do not render.
44+
// The less than case is likely not neccessary but just there as a safety case for unexpected scenarios
45+
if (allSiblingsInGroupThatExist.length <= 1) {
46+
return <></>;
47+
}
4048

4149
return (
4250
<div>
4351
<SidebarHeader title="Composed Of" />
4452
<EntityListContainer>
4553
<CompactEntityNameList
46-
entities={allSiblingsInGroup}
54+
entities={allSiblingsInGroupThatExist}
4755
linkUrlParams={{ [SEPARATE_SIBLINGS_URL_PARAM]: true }}
4856
showTooltips
4957
/>

datahub-web-react/src/app/entity/shared/siblingUtils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import merge from 'deepmerge';
22
import { unionBy, keyBy, values } from 'lodash';
33
import { useLocation } from 'react-router-dom';
44
import * as QueryString from 'query-string';
5-
import { Entity, MatchedField, Maybe, SiblingProperties } from '../../../types.generated';
5+
import { Dataset, Entity, MatchedField, Maybe, SiblingProperties } from '../../../types.generated';
66

77
export function stripSiblingsFromEntity(entity: any) {
88
return {
@@ -235,6 +235,11 @@ export function combineSiblingsInSearchResults(
235235
combinedResult.matchedEntities = entity.siblings.isPrimary
236236
? [stripSiblingsFromEntity(entity), ...entity.siblings.siblings]
237237
: [...entity.siblings.siblings, stripSiblingsFromEntity(entity)];
238+
239+
combinedResult.matchedEntities = combinedResult.matchedEntities.filter(
240+
(resultToFilter) => (resultToFilter as Dataset).exists,
241+
);
242+
238243
siblingUrns.forEach((urn) => {
239244
siblingsToPair[urn] = combinedResult;
240245
});

datahub-web-react/src/app/search/SearchResultList.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ export const SearchResultList = ({
151151
)}
152152
{entityRegistry.renderSearchResult(item.entity.type, item)}
153153
</ListItem>
154-
{item.matchedEntities && item.matchedEntities.length > 0 && (
154+
{/* an entity is always going to be inserted in the sibling group, so if the sibling group is just one do not
155+
render. */}
156+
{item.matchedEntities && item.matchedEntities.length > 1 && (
155157
<SiblingResultContainer className="test-search-result-sibling-section">
156158
<CompactEntityNameList
157159
linkUrlParams={{ [SEPARATE_SIBLINGS_URL_PARAM]: true }}

datahub-web-react/src/graphql/dataset.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ query getDataProfiles($urn: String!, $limit: Int, $startTime: Long, $endTime: Lo
2525

2626
query getDataset($urn: String!) {
2727
dataset(urn: $urn) {
28-
exists
2928
...nonSiblingDatasetFields
3029
siblings {
3130
isPrimary
@@ -40,6 +39,7 @@ query getDataset($urn: String!) {
4039

4140
fragment nonSiblingDatasetFields on Dataset {
4241
...nonRecursiveDatasetFields
42+
exists
4343
deprecation {
4444
actor
4545
deprecated

datahub-web-react/src/graphql/search.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ fragment searchResultFields on Entity {
254254
urn
255255
type
256256
... on Dataset {
257+
exists
257258
name
258259
origin
259260
uri
@@ -311,6 +312,7 @@ fragment searchResultFields on Entity {
311312
urn
312313
type
313314
... on Dataset {
315+
exists
314316
platform {
315317
...platformFields
316318
}

0 commit comments

Comments
 (0)