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

feat(React): Ownership component of user profile #2173

Merged
merged 6 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion datahub-frontend/run/frontend.env
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ DATAHUB_PIWIK_URL="//piwik.corp.linkedin.com/piwik/"

# GMS configuration
DATAHUB_GMS_HOST=localhost
DATAHUB_GMS_PORT=8080
DATAHUB_GMS_PORT=8080
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 }>) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey just realized we should use the Entity Registry here. Will raise another PR...

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;
}