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 4 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
10 changes: 9 additions & 1 deletion datahub-web-react/src/app/entity/user/UserOwnership.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ export default ({ ownerships, entityPath }: Props) => {
</Typography.Title>
}
renderItem={(item) => {
return entityRegistry.renderPreview(entityType, PreviewType.PREVIEW, item);
return (
<div
style={{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: can we extract out styles into a const variable at the top of the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed inline style

marginTop: '10px',
}}
>
{entityRegistry.renderPreview(entityType, PreviewType.PREVIEW, item)}
</div>
);
}}
/>
</ListContainer>
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 { useGetEachEntitySearchResults } from '../../../utils/customGraphQL/useGetEachEntitySearchResults';

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 = useGetEachEntitySearchResults({
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,44 @@
import { EntityType } from '../../types.generated';
import { useGetSearchResultsQuery } from '../../graphql/search.generated';

export function useGetEachEntitySearchResults(input: any) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

very minor nit:

can we call this "useGetAllEntitySearchResults"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

const result: any = {};

result[EntityType.Chart] = useGetSearchResultsQuery({
variables: {
input: {
type: EntityType.Chart,
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we pass a "start" and "count" variable into this method and add it here? That way we can control how many results we get for each entity easily. I will likely replace my current entity loading in the "all" tab with what you've added here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is already handled by the input object passed in to keep it generic, i.e. if we pass an object with start and count, then this query will get it. Do we want to explicitly mark these 2 parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see latest change, I have implemented the input using Partial<SearchInput> so that start and count are checked when compile

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thank you! Looks great.

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