Skip to content

Commit

Permalink
feat(react): replace user urn with username (#2599)
Browse files Browse the repository at this point in the history
Co-authored-by: shubham.garg <[email protected]>
  • Loading branch information
shubham49 and gargshubham49 authored Jun 3, 2021
1 parent 47554d2 commit 4e73011
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.linkedin.datahub.graphql.generated.Entity;
import com.linkedin.datahub.graphql.generated.EntityRelationship;
import com.linkedin.datahub.graphql.generated.RelatedDataset;
import com.linkedin.datahub.graphql.generated.InstitutionalMemoryMetadata;
import com.linkedin.datahub.graphql.resolvers.load.EntityTypeResolver;
import com.linkedin.datahub.graphql.resolvers.load.LoadableTypeBatchResolver;
import com.linkedin.datahub.graphql.resolvers.mutate.MutableTypeResolver;
Expand Down Expand Up @@ -312,6 +313,13 @@ private static void configureDatasetResolvers(final RuntimeWiring.Builder builde
ENTITY_TYPES.stream().collect(Collectors.toList()),
(env) -> ((EntityRelationship) env.getSource()).getEntity()))
)
)
.type("InstitutionalMemoryMetadata", typeWiring -> typeWiring
.dataFetcher("author", new AuthenticatedResolver<>(
new LoadableTypeResolver<>(
CORP_USER_TYPE,
(env) -> ((InstitutionalMemoryMetadata) env.getSource()).getAuthor().getUrn()))
)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.linkedin.datahub.graphql.types.common.mappers;

import com.linkedin.datahub.graphql.generated.InstitutionalMemoryMetadata;
import com.linkedin.datahub.graphql.generated.CorpUser;
import com.linkedin.datahub.graphql.types.mappers.ModelMapper;

import javax.annotation.Nonnull;
Expand All @@ -18,8 +19,14 @@ public InstitutionalMemoryMetadata apply(@Nonnull final com.linkedin.common.Inst
final InstitutionalMemoryMetadata result = new InstitutionalMemoryMetadata();
result.setUrl(input.getUrl().toString());
result.setDescription(input.getDescription());
result.setAuthor(input.getCreateStamp().getActor().toString());
result.setAuthor(getAuthor(input.getCreateStamp().getActor().toString()));
result.setCreated(AuditStampMapper.map(input.getCreateStamp()));
return result;
}

private CorpUser getAuthor(String actor) {
CorpUser partialUser = new CorpUser();
partialUser.setUrn(actor);
return partialUser;
}
}
2 changes: 1 addition & 1 deletion datahub-graphql-core/src/main/resources/gms.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ type InstitutionalMemoryMetadata {
"""
The author of this metadata
"""
author: String!
author: CorpUser!

"""
An AuditStamp corresponding to the creation of this resource
Expand Down
2 changes: 1 addition & 1 deletion datahub-web-react/src/Mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const dataset3 = {
elements: [
{
url: 'https://www.google.com',
author: 'datahub',
author: { urn: 'urn:li:corpuser:datahub', username: 'datahub', type: EntityType.CorpUser },
description: 'This only points to Google',
created: {
actor: 'urn:li:corpuser:1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const DatasetProfile = ({ urn }: { urn: string }): JSX.Element => {
content: (
<DocumentsView
authenticatedUserUrn={user?.urn}
authenticatedUserUsername={user?.username}
documents={institutionalMemory?.elements || EMPTY_ARR}
updateDocumentation={(update) => {
analytics.event({
Expand Down
35 changes: 23 additions & 12 deletions datahub-web-react/src/app/entity/dataset/profile/Documentation.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { Button, Form, Input, Space, Table, Typography } from 'antd';
import React, { useEffect, useMemo, useState } from 'react';
import { Link } from 'react-router-dom';
import { EntityType, InstitutionalMemoryMetadata, InstitutionalMemoryUpdate } from '../../../../types.generated';
import {
CorpUser,
EntityType,
InstitutionalMemoryMetadata,
InstitutionalMemoryUpdate,
} from '../../../../types.generated';
import { useEntityRegistry } from '../../../useEntityRegistry';

export type Props = {
authenticatedUserUrn?: string;
authenticatedUserUsername?: string;
documents: Array<InstitutionalMemoryMetadata>;
updateDocumentation: (update: InstitutionalMemoryUpdate) => void;
};
Expand Down Expand Up @@ -35,7 +41,12 @@ function FormInput({ name, placeholder, type }: { name: string; placeholder: str
);
}

export default function Documentation({ authenticatedUserUrn, documents, updateDocumentation }: Props) {
export default function Documentation({
authenticatedUserUrn,
documents,
updateDocumentation,
authenticatedUserUsername,
}: Props) {
const entityRegistry = useEntityRegistry();

const [form] = Form.useForm();
Expand All @@ -50,7 +61,7 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD
() =>
stagedDocs.map((doc, index) => ({
key: index,
author: doc.author,
author: { urn: doc.author.urn, username: doc.author.username, type: EntityType.CorpUser },
url: doc.url,
description: doc.description,
createdAt: doc.created.time,
Expand All @@ -60,7 +71,7 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD

const isEditing = (record: any) => record.key === editingIndex;

const onAdd = (authorUrn: string) => {
const onAdd = (authorUrn: string, authorUsername: string) => {
setEditingIndex(stagedDocs.length);

form.setFieldsValue({
Expand All @@ -71,7 +82,7 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD
const newDoc = {
url: '',
description: '',
author: authorUrn,
author: { urn: authorUrn, username: authorUsername, type: EntityType.CorpUser },
created: {
time: Date.now(),
},
Expand All @@ -89,12 +100,12 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD
return {
url: row.url,
description: row.description,
author: doc.author,
author: doc.author.urn,
createdAt: doc.created.time,
};
}
return {
author: doc.author,
author: doc.author.urn,
url: doc.url,
description: doc.description,
createdAt: doc.created.time,
Expand All @@ -113,7 +124,7 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD
const onDelete = (index: number) => {
const newDocs = stagedDocs.filter((_, i) => !(index === i));
const updatedInstitutionalMemory = newDocs.map((doc) => ({
author: doc.author,
author: doc.author.urn,
url: doc.url,
description: doc.description,
}));
Expand Down Expand Up @@ -147,8 +158,8 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD
{
title: 'Author',
dataIndex: 'author',
render: (authorUrn: string) => (
<Link to={`/${entityRegistry.getPathName(EntityType.CorpUser)}/${authorUrn}`}>{authorUrn}</Link>
render: (user: CorpUser) => (
<Link to={`/${entityRegistry.getPathName(EntityType.CorpUser)}/${user.urn}`}>{user.username}</Link>
),
},
{
Expand Down Expand Up @@ -185,8 +196,8 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD
<Form form={form} component={false}>
<Table pagination={false} columns={tableColumns} dataSource={tableData} />
</Form>
{authenticatedUserUrn && editingIndex < 0 && (
<Button type="link" onClick={() => onAdd(authenticatedUserUrn)}>
{authenticatedUserUrn && authenticatedUserUsername && editingIndex < 0 && (
<Button type="link" onClick={() => onAdd(authenticatedUserUrn, authenticatedUserUsername)}>
<b> + </b> Add a link
</Button>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ describe('Documentation', () => {
<TestPageContainer>
<Documentation
authenticatedUserUrn="urn:li:corpuser:1"
authenticatedUserUsername="1"
documents={sampleDocs}
updateDocumentation={(_) => undefined}
/>
,
</TestPageContainer>,
);
expect(getByText('Documentation')).toBeInTheDocument();
expect(getByText('urn:li:corpuser:1')).toBeInTheDocument();
expect(getByText('1')).toBeInTheDocument();
expect(getByText('https://www.google.com')).toBeInTheDocument();
expect(getByText('Add a link')).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { EntityType } from '../../../../../types.generated';

export const sampleDocs = [
{
url: 'https://www.google.com',
description: 'This doc spans the internet web',
author: 'urn:li:corpuser:1',
author: { urn: 'urn:li:corpuser:1', username: '1', type: EntityType.CorpUser },
created: {
time: 0,
actor: 'urn:li:corpuser:1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const sampleDataset: Dataset = {
elements: [
{
url: 'https://www.google.com',
author: 'datahub',
author: { urn: 'urn:li:corpuser:datahub', username: 'datahub', type: EntityType.CorpUser },
description: 'This only points to Google',
created: {
actor: 'urn:li:corpuser:1',
Expand Down Expand Up @@ -76,7 +76,7 @@ export const sampleDeprecatedDataset: Dataset = {
elements: [
{
url: 'https://www.google.com',
author: 'datahub',
author: { urn: 'urn:li:corpuser:datahub', username: 'datahub', type: EntityType.CorpUser },
description: 'This only points to Google',
created: {
actor: 'urn:li:corpuser:1',
Expand Down
5 changes: 4 additions & 1 deletion datahub-web-react/src/graphql/dataset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ query getDataset($urn: String!) {
institutionalMemory {
elements {
url
author
author {
urn
username
}
description
created {
actor
Expand Down
5 changes: 4 additions & 1 deletion datahub-web-react/src/graphql/fragments.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ fragment nonRecursiveDatasetFields on Dataset {
institutionalMemory {
elements {
url
author
author {
urn
username
}
description
created {
actor
Expand Down

0 comments on commit 4e73011

Please sign in to comment.