Skip to content

Commit

Permalink
feat(React): Ownership component of user profile (#2173)
Browse files Browse the repository at this point in the history
Co-authored-by: Brendan Sun <[email protected]>
  • Loading branch information
brendansun93 and brendansun authored Mar 8, 2021
1 parent 7043138 commit e3ad0ed
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 8 deletions.
15 changes: 9 additions & 6 deletions datahub-web-react/src/app/entity/user/UserOwnership.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { List, Typography } from 'antd';
import { List, Typography, Divider } from 'antd';
import styled from 'styled-components';

import { EntityType } from '../../../types.generated';
Expand All @@ -16,6 +16,10 @@ const ListContainer = styled.div`
flex-grow: default;
`;

const TitleContainer = styled.div`
margin-bottom: 30px;
`;

export default ({ ownerships, entityPath }: Props) => {
const entityRegistry = useEntityRegistry();

Expand All @@ -27,13 +31,12 @@ export default ({ ownerships, entityPath }: Props) => {

return (
<ListContainer>
<TitleContainer>
<Typography.Title level={3}>{entityRegistry.getCollectionName(entityType)} they own</Typography.Title>
<Divider />
</TitleContainer>
<List
dataSource={entitiesToShow}
header={
<Typography.Title level={3}>
{entityRegistry.getCollectionName(entityType)} they own
</Typography.Title>
}
renderItem={(item) => {
return entityRegistry.renderPreview(entityType, PreviewType.PREVIEW, item);
}}
Expand Down
26 changes: 24 additions & 2 deletions datahub-web-react/src/app/entity/user/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import UserHeader from './UserHeader';
import UserDetails from './UserDetails';
import useUserParams from './routingUtils/useUserParams';
import { useGetUserQuery } from '../../../graphql/user.generated';
import { useGetAllEntitySearchResults } from '../../../utils/customGraphQL/useGetAllEntitySearchResults';

const PageContainer = styled.div`
background-color: white;
Expand All @@ -19,14 +20,35 @@ export default function UserProfile() {
const { urn, subview, item } = useUserParams();
const { loading, error, data } = useGetUserQuery({ variables: { urn } });

if (loading) {
const username = data?.corpUser?.username;

const ownershipResult = useGetAllEntitySearchResults({
query: `owners:${username}`,
});

const contentLoading =
Object.keys(ownershipResult).some((type) => {
return ownershipResult[type].loading;
}) || loading;

if (contentLoading) {
return <Alert type="info" message="Loading" />;
}

if (error || (!loading && !error && !data)) {
return <Alert type="error" message={error?.message || 'Entity failed to load'} />;
}

Object.keys(ownershipResult).forEach((type) => {
const entities = ownershipResult[type].data?.search?.entities;

if (!entities || entities.length === 0) {
delete ownershipResult[type];
} else {
ownershipResult[type] = ownershipResult[type].data?.search?.entities;
}
});

return (
<PageContainer>
<UserHeader
Expand All @@ -38,7 +60,7 @@ export default function UserProfile() {
teams={data?.corpUser?.editableInfo?.teams}
/>
<Divider />
<UserDetails urn={urn} subview={subview} item={item} ownerships={{}} />
<UserDetails urn={urn} subview={subview} item={item} ownerships={ownershipResult} />
</PageContainer>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { EntityType, SearchInput } from '../../types.generated';
import { useGetSearchResultsQuery } from '../../graphql/search.generated';

type AllEntityInput<T, K> = Pick<T, Exclude<keyof T, keyof K>> & K;

export function useGetAllEntitySearchResults(input: AllEntityInput<SearchInput, { type?: EntityType }>) {
const result: any = {};

result[EntityType.Chart] = useGetSearchResultsQuery({
variables: {
input: {
type: EntityType.Chart,
...input,
},
},
});

result[EntityType.Dashboard] = useGetSearchResultsQuery({
variables: {
input: {
type: EntityType.Dashboard,
...input,
},
},
});

result[EntityType.DataPlatform] = useGetSearchResultsQuery({
variables: {
input: {
type: EntityType.DataPlatform,
...input,
},
},
});

result[EntityType.Dataset] = useGetSearchResultsQuery({
variables: {
input: {
type: EntityType.Dataset,
...input,
},
},
});

return result;
}

0 comments on commit e3ad0ed

Please sign in to comment.