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(ui): allow removing parentNodes of Glossary Nodes and Glossary Terms #7135

Merged
merged 3 commits into from
Jan 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,25 @@ public CompletableFuture<Boolean> get(DataFetchingEnvironment environment) throw
throw new IllegalArgumentException(String.format("Failed to update %s. %s does not exist.", targetUrn, targetUrn));
}

GlossaryNodeUrn parentNodeUrn = GlossaryNodeUrn.createFromString(input.getParentNode());
if (!_entityService.exists(parentNodeUrn) || !parentNodeUrn.getEntityType().equals(Constants.GLOSSARY_NODE_ENTITY_NAME)) {
throw new IllegalArgumentException(String.format("Failed to update %s. %s either does not exist or is not a glossaryNode.", targetUrn, parentNodeUrn));
GlossaryNodeUrn parentNodeUrn = null;
if (input.getParentNode() != null) {
parentNodeUrn = GlossaryNodeUrn.createFromString(input.getParentNode());
if (!_entityService.exists(parentNodeUrn) || !parentNodeUrn.getEntityType().equals(Constants.GLOSSARY_NODE_ENTITY_NAME)) {
throw new IllegalArgumentException(String.format("Failed to update %s. %s either does not exist or is not a glossaryNode.", targetUrn, parentNodeUrn));
}
}

GlossaryNodeUrn finalParentNodeUrn = parentNodeUrn;
jjoyce0510 marked this conversation as resolved.
Show resolved Hide resolved
return CompletableFuture.supplyAsync(() -> {
Urn currentParentUrn = GlossaryUtils.getParentUrn(targetUrn, context, _entityClient);
// need to be able to manage current parent node and new parent node
if (GlossaryUtils.canManageChildrenEntities(context, currentParentUrn, _entityClient)
&& GlossaryUtils.canManageChildrenEntities(context, parentNodeUrn, _entityClient)) {
&& GlossaryUtils.canManageChildrenEntities(context, finalParentNodeUrn, _entityClient)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it okay that final Parent Node is null going into this method?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like the case is covered!

switch (targetUrn.getEntityType()) {
case Constants.GLOSSARY_TERM_ENTITY_NAME:
return updateGlossaryTermParentNode(targetUrn, parentNodeUrn, input, environment.getContext());
return updateGlossaryTermParentNode(targetUrn, finalParentNodeUrn, input, environment.getContext());
case Constants.GLOSSARY_NODE_ENTITY_NAME:
return updateGlossaryNodeParentNode(targetUrn, parentNodeUrn, input, environment.getContext());
return updateGlossaryNodeParentNode(targetUrn, finalParentNodeUrn, input, environment.getContext());
default:
throw new RuntimeException(
String.format("Failed to update parentNode. Unsupported resource type %s provided.", targetUrn));
Expand All @@ -77,7 +82,12 @@ private Boolean updateGlossaryTermParentNode(
// If there is no info aspect for the term already, then we should throw since the model also requires a name.
throw new IllegalArgumentException("Info for this Glossary Term does not yet exist!");
}
glossaryTermInfo.setParentNode(parentNodeUrn);

if (parentNodeUrn != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

glossaryTermInfo.setParentNode(parentNodeUrn);
} else {
glossaryTermInfo.removeParentNode();
}
Urn actor = CorpuserUrn.createFromString(context.getActorUrn());
persistAspect(targetUrn, Constants.GLOSSARY_TERM_INFO_ASPECT_NAME, glossaryTermInfo, actor, _entityService);

Expand All @@ -100,7 +110,12 @@ private Boolean updateGlossaryNodeParentNode(
if (glossaryNodeInfo == null) {
throw new IllegalArgumentException("Info for this Glossary Node does not yet exist!");
}
glossaryNodeInfo.setParentNode(parentNodeUrn);

if (parentNodeUrn != null) {
glossaryNodeInfo.setParentNode(parentNodeUrn);
} else {
glossaryNodeInfo.removeParentNode();
}
Urn actor = CorpuserUrn.createFromString(context.getActorUrn());
persistAspect(targetUrn, Constants.GLOSSARY_NODE_INFO_ASPECT_NAME, glossaryNodeInfo, actor, _entityService);

Expand Down
4 changes: 2 additions & 2 deletions datahub-graphql-core/src/main/resources/entity.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7254,9 +7254,9 @@ Input for updating the parent node of a resource. Currently only GlossaryNodes a
"""
input UpdateParentNodeInput {
"""
The new parent node urn
The new parent node urn. If parentNode is null, this will remove the parent from this entity
Copy link
Collaborator

Choose a reason for hiding this comment

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

nice!

"""
parentNode: String!
parentNode: String

"""
The primary key of the resource to update the parent node for
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import styled from 'styled-components/macro';
import { message, Button, Modal, Typography, Form } from 'antd';
import { useEntityData, useRefetch } from '../EntityContext';
Expand All @@ -10,6 +10,10 @@ const StyledItem = styled(Form.Item)`
margin-bottom: 0;
`;

const OptionalWrapper = styled.span`
font-weight: normal;
`;

interface Props {
onClose: () => void;
refetchData?: () => void;
Expand All @@ -21,25 +25,16 @@ function MoveGlossaryEntityModal(props: Props) {
const [form] = Form.useForm();
const entityRegistry = useEntityRegistry();
const [selectedParentUrn, setSelectedParentUrn] = useState('');
const [createButtonEnabled, setCreateButtonEnabled] = useState(false);
const refetch = useRefetch();

const [updateParentNode] = useUpdateParentNodeMutation();

useEffect(() => {
if (selectedParentUrn) {
setCreateButtonEnabled(true);
} else {
setCreateButtonEnabled(false);
}
}, [selectedParentUrn]);

function moveGlossaryEntity() {
updateParentNode({
variables: {
input: {
resourceUrn: entityDataUrn,
parentNode: selectedParentUrn,
parentNode: selectedParentUrn || null,
},
},
})
Expand Down Expand Up @@ -73,14 +68,18 @@ function MoveGlossaryEntityModal(props: Props) {
<Button onClick={onClose} type="text">
Cancel
</Button>
<Button onClick={moveGlossaryEntity} disabled={!createButtonEnabled}>
Move
</Button>
<Button onClick={moveGlossaryEntity}>Move</Button>
</>
}
>
<Form form={form} initialValues={{}} layout="vertical">
<Form.Item label={<Typography.Text strong>Move To</Typography.Text>}>
<Form.Item
label={
<Typography.Text strong>
Move To <OptionalWrapper>(optional)</OptionalWrapper>
</Typography.Text>
}
>
<StyledItem name="parent">
<NodeParentSelect
selectedParentUrn={selectedParentUrn}
Expand Down