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): replace user urn with username #2599

Merged
merged 5 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ public InstitutionalMemoryMetadata apply(@Nonnull final com.linkedin.common.Inst
result.setUrl(input.getUrl().toString());
result.setDescription(input.getDescription());
result.setAuthor(input.getCreateStamp().getActor().toString());
result.setAuthorUsername(extractAuthorUsername(input.getCreateStamp().getActor().toString()));
result.setCreated(AuditStampMapper.map(input.getCreateStamp()));
return result;
}

private String extractAuthorUsername(String actor) {
if (actor.contains(":")) {
return actor.substring(actor.lastIndexOf(":") + 1);
}
return "";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we can get username by creating a OwnerUrn using OwnerUrn.createFromString() and then extracting name from there. Lets do that instead of string parsing.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gabe-lyons : will this stuff work after no-code?

Copy link
Contributor

Choose a reason for hiding this comment

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

OwnerUrn will still exist after no-code, but you're right that we will eventually deprecate and replace it with just the generic Urn class. To use the Urn class, you would create an instance of a generic urn using Urn.createFromString(rawUrn), then access the part of the key you are interested in using urn.getEntityKey().get(index)

}
5 changes: 5 additions & 0 deletions datahub-graphql-core/src/main/resources/gms.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,11 @@ type InstitutionalMemoryMetadata {
"""
author: String!

"""
The author's username of this metadata
"""
authorUsername: String!

"""
An AuditStamp corresponding to the creation of this resource
"""
Expand Down
3 changes: 2 additions & 1 deletion datahub-web-react/src/Mocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ export const dataset3 = {
elements: [
{
url: 'https://www.google.com',
author: 'datahub',
author: 'urn:li:corpuser:datahub',
authorUsername: 'datahub',
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
22 changes: 16 additions & 6 deletions datahub-web-react/src/app/entity/dataset/profile/Documentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useEntityRegistry } from '../../../useEntityRegistry';

export type Props = {
authenticatedUserUrn?: string;
authenticatedUserUsername?: string;
documents: Array<InstitutionalMemoryMetadata>;
updateDocumentation: (update: InstitutionalMemoryUpdate) => void;
};
Expand Down Expand Up @@ -35,7 +36,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 @@ -51,6 +57,7 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD
stagedDocs.map((doc, index) => ({
key: index,
author: doc.author,
authorUsername: doc.authorUsername,
url: doc.url,
description: doc.description,
createdAt: doc.created.time,
Expand All @@ -60,7 +67,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 @@ -72,6 +79,7 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD
url: '',
description: '',
author: authorUrn,
authorUsername,
created: {
time: Date.now(),
},
Expand Down Expand Up @@ -147,8 +155,10 @@ export default function Documentation({ authenticatedUserUrn, documents, updateD
{
title: 'Author',
dataIndex: 'author',
render: (authorUrn: string) => (
<Link to={`/${entityRegistry.getPathName(EntityType.CorpUser)}/${authorUrn}`}>{authorUrn}</Link>
render: (authorUrn: string, record: any) => (
<Link to={`/${entityRegistry.getPathName(EntityType.CorpUser)}/${authorUrn}`}>
{record.authorUsername}
</Link>
),
},
{
Expand Down Expand Up @@ -185,8 +195,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
Expand Up @@ -3,6 +3,7 @@ export const sampleDocs = [
url: 'https://www.google.com',
description: 'This doc spans the internet web',
author: 'urn:li:corpuser:1',
authorUsername: '1',
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,8 @@ export const sampleDataset: Dataset = {
elements: [
{
url: 'https://www.google.com',
author: 'datahub',
author: 'urn:li:corpuser:datahub',
authorUsername: 'datahub',
description: 'This only points to Google',
created: {
actor: 'urn:li:corpuser:1',
Expand Down Expand Up @@ -76,7 +77,8 @@ export const sampleDeprecatedDataset: Dataset = {
elements: [
{
url: 'https://www.google.com',
author: 'datahub',
author: 'urn:li:corpuser:datahub',
authorUsername: 'datahub',
description: 'This only points to Google',
created: {
actor: 'urn:li:corpuser:1',
Expand Down
1 change: 1 addition & 0 deletions datahub-web-react/src/graphql/dataset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ query getDataset($urn: String!) {
elements {
url
author
authorUsername
description
created {
actor
Expand Down
1 change: 1 addition & 0 deletions datahub-web-react/src/graphql/fragments.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ fragment nonRecursiveDatasetFields on Dataset {
elements {
url
author
authorUsername
description
created {
actor
Expand Down