Skip to content

Commit

Permalink
feat(ui): allow removing parentNodes of Glossary Nodes and Glossary T…
Browse files Browse the repository at this point in the history
…erms (datahub-project#7135)

Co-authored-by: John Joyce <[email protected]>
  • Loading branch information
2 people authored and Oleg Ruban committed Feb 28, 2023
1 parent 2a3b8c7 commit 60cccf3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
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;
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)) {
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) {
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
"""
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

0 comments on commit 60cccf3

Please sign in to comment.