feat(react): replace user urn with username (#2599)

Co-authored-by: shubham.garg <shubham.garg@thoughtworks.com>
This commit is contained in:
shubham garg 2021-06-03 23:40:03 +05:30 committed by GitHub
parent 47554d2d4a
commit 4e73011bb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 57 additions and 21 deletions

View File

@ -10,6 +10,7 @@ import com.linkedin.datahub.graphql.generated.Dataset;
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;
@ -312,6 +313,13 @@ public class GmsGraphQLEngine {
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()))
)
);
}

View File

@ -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;
@ -18,8 +19,14 @@ public class InstitutionalMemoryMetadataMapper implements ModelMapper<com.linked
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;
}
}

View File

@ -508,7 +508,7 @@ type InstitutionalMemoryMetadata {
"""
The author of this metadata
"""
author: String!
author: CorpUser!
"""
An AuditStamp corresponding to the creation of this resource

View File

@ -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',

View File

@ -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({

View File

@ -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;
};
@ -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();
@ -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,
@ -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({
@ -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(),
},
@ -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,
@ -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,
}));
@ -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>
),
},
{
@ -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>
)}

View File

@ -10,6 +10,7 @@ describe('Documentation', () => {
<TestPageContainer>
<Documentation
authenticatedUserUrn="urn:li:corpuser:1"
authenticatedUserUsername="1"
documents={sampleDocs}
updateDocumentation={(_) => undefined}
/>
@ -17,7 +18,7 @@ describe('Documentation', () => {
</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();
});

View File

@ -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',

View File

@ -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',
@ -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',

View File

@ -36,7 +36,10 @@ query getDataset($urn: String!) {
institutionalMemory {
elements {
url
author
author {
urn
username
}
description
created {
actor

View File

@ -116,7 +116,10 @@ fragment nonRecursiveDatasetFields on Dataset {
institutionalMemory {
elements {
url
author
author {
urn
username
}
description
created {
actor