Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix aggregation sorting in browsev2 sidebar #8276

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions datahub-web-react/src/app/search/sidebar/EntityNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const EntityNode = () => {
});

const showEnvironments =
environmentAggregations.length > 1 || (hasEnvironmentFilter && !!environmentAggregations.length);
environmentAggregations &&
(environmentAggregations.length > 1 || (hasEnvironmentFilter && !!environmentAggregations.length));
const color = count > 0 ? '#000' : ANTD_GRAY[8];

return (
Expand Down Expand Up @@ -75,7 +76,7 @@ const EntityNode = () => {
body={
<ExpandableNode.Body>
{showEnvironments
? environmentAggregations.map((environmentAggregation) => (
? environmentAggregations?.map((environmentAggregation) => (
<BrowseProvider
key={environmentAggregation.value}
entityAggregation={entityAggregation}
Expand All @@ -84,7 +85,7 @@ const EntityNode = () => {
<EnvironmentNode />
</BrowseProvider>
))
: platformAggregations.map((platformAggregation) => (
: platformAggregations?.map((platformAggregation) => (
<BrowseProvider
key={platformAggregation.value}
entityAggregation={entityAggregation}
Expand Down
3 changes: 2 additions & 1 deletion datahub-web-react/src/app/search/sidebar/EnvironmentNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import useSidebarAnalytics from './useSidebarAnalytics';
const Count = styled(Typography.Text)`
font-size: 12px;
color: ${(props) => props.color};
padding-right: 8px;
`;

const EnvironmentNode = () => {
Expand Down Expand Up @@ -64,7 +65,7 @@ const EnvironmentNode = () => {
}
body={
<ExpandableNode.Body>
{platformAggregations.map((platformAggregation) => (
{platformAggregations?.map((platformAggregation) => (
<BrowseProvider
key={platformAggregation.value}
entityAggregation={entityAggregation}
Expand Down
2 changes: 1 addition & 1 deletion datahub-web-react/src/app/search/sidebar/PlatformNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ const PlatformIconContainer = styled.div`
const Count = styled(Typography.Text)`
font-size: 12px;
color: ${(props) => props.color};
padding-right: 8px;
`;

const BrowseGroupListContainer = styled.div`
background: white;
border-radius: 8px;
padding-bottom: 8px;
padding-right: 8px;
`;

Expand Down
26 changes: 17 additions & 9 deletions datahub-web-react/src/app/search/sidebar/useAggregationsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,25 @@ const useAggregationsQuery = ({ facets, skip }: Props) => {
const type = aggregation.value as EntityType;
return registry.getEntity(type).isBrowseEnabled() && !GLOSSARY_ENTITY_TYPES.includes(type);
})
.sort((a, b) => a.value.localeCompare(b.value));
.sort((a, b) => {
const nameA = registry.getCollectionName(a.value as EntityType);
const nameB = registry.getCollectionName(b.value as EntityType);
return nameA.localeCompare(nameB);
});

const environmentAggregations =
data?.aggregateAcrossEntities?.facets
?.find((facet) => facet.field === ORIGIN_FILTER_NAME)
?.aggregations.filter((aggregation) => aggregation.count) ?? [];
const environmentAggregations = data?.aggregateAcrossEntities?.facets
?.find((facet) => facet.field === ORIGIN_FILTER_NAME)
?.aggregations.filter((aggregation) => aggregation.count)
.sort((a, b) => a.value.localeCompare(b.value));

const platformAggregations =
data?.aggregateAcrossEntities?.facets
?.find((facet) => facet.field === PLATFORM_FILTER_NAME)
?.aggregations.filter((aggregation) => aggregation.count) ?? [];
const platformAggregations = data?.aggregateAcrossEntities?.facets
?.find((facet) => facet.field === PLATFORM_FILTER_NAME)
?.aggregations.filter((aggregation) => aggregation.count)
.sort((a, b) => {
const nameA = registry.getDisplayName(EntityType.DataPlatform, a.entity);
const nameB = registry.getDisplayName(EntityType.DataPlatform, b.entity);
return nameA.localeCompare(nameB);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safe to assume these will always have an entity? I suppose we could fallback to sorting by the agg value if the entity wasn't present for some reason.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do think falling back to the agg value if the entity isn't present is safer here.. sometimes we see data get ingested on a platform where the platform entity has not been ingested (this is a bad state, but it does happen)

});

return {
loading,
Expand Down