mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-25 08:58:26 +00:00
feat(ui): allow removing parentNodes of Glossary Nodes and Glossary Terms (#7135)
Co-authored-by: John Joyce <john@acryl.io>
This commit is contained in:
parent
ca5c6c3811
commit
7ded44280d
@ -41,20 +41,25 @@ public class UpdateParentNodeResolver implements DataFetcher<CompletableFuture<B
|
||||
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));
|
||||
@ -77,7 +82,12 @@ public class UpdateParentNodeResolver implements DataFetcher<CompletableFuture<B
|
||||
// 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);
|
||||
|
||||
@ -100,7 +110,12 @@ public class UpdateParentNodeResolver implements DataFetcher<CompletableFuture<B
|
||||
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);
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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';
|
||||
@ -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;
|
||||
@ -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,
|
||||
},
|
||||
},
|
||||
})
|
||||
@ -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}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user