Skip to content
Open
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 @@ -28,6 +28,7 @@ import { EntityType, GlossaryNode, SearchResult } from '@types';
const headerDropdownItems = new Set([
EntityMenuItems.MOVE,
EntityMenuItems.SHARE,
EntityMenuItems.CLONE,
EntityMenuItems.DELETE,
EntityMenuItems.ANNOUNCE,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const headerDropdownItems = new Set([
EntityMenuItems.MOVE,
EntityMenuItems.SHARE,
EntityMenuItems.UPDATE_DEPRECATION,
EntityMenuItems.CLONE,
EntityMenuItems.DELETE,
EntityMenuItems.ANNOUNCE,
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { EditOutlined } from '@ant-design/icons';
import { Collapse, Form, Input, Modal, Typography, message } from 'antd';
import DOMPurify from 'dompurify';
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components/macro';

import analytics, { EventType } from '@app/analytics';
Expand Down Expand Up @@ -39,6 +39,7 @@ interface Props {
// acryl-main only prop
canCreateGlossaryEntity: boolean;
canSelectParentUrn?: boolean;
isCloning?: boolean;
}

function CreateGlossaryEntityModal(props: Props) {
Expand All @@ -49,7 +50,7 @@ function CreateGlossaryEntityModal(props: Props) {
const entityRegistry = useEntityRegistry();
const [stagedId, setStagedId] = useState<string | undefined>(undefined);
const [stagedName, setStagedName] = useState('');
const [selectedParentUrn, setSelectedParentUrn] = useState(entityData.urn);
const [selectedParentUrn, setSelectedParentUrn] = useState(props.isCloning ? '' : entityData.urn);
const [documentation, setDocumentation] = useState('');
const [isDocumentationModalVisible, setIsDocumentationModalVisible] = useState(false);
const [createButtonDisabled, setCreateButtonDisabled] = useState(true);
Expand All @@ -58,6 +59,21 @@ function CreateGlossaryEntityModal(props: Props) {
const [createGlossaryTermMutation] = useCreateGlossaryTermMutation();
const [createGlossaryNodeMutation] = useCreateGlossaryNodeMutation();

useEffect(() => {
if (props.isCloning && entityData.entityData) {
const { properties } = entityData.entityData;

if (properties?.name) {
setStagedName(properties.name);
form.setFieldValue('name', properties.name);
}
Comment on lines +67 to +69
Copy link
Collaborator

Choose a reason for hiding this comment

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

what do you think about doing ${properties.name} (copy) here? for both of these setters


if (properties?.description) {
setDocumentation(properties.description);
}
}
}, [props.isCloning, entityData.entityData, form]);

function createGlossaryEntity() {
const mutation =
entityType === EntityType.GlossaryTerm ? createGlossaryTermMutation : createGlossaryNodeMutation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const EntityDropdown = (props: Props) => {

const [isCreateTermModalVisible, setIsCreateTermModalVisible] = useState(false);
const [isCreateNodeModalVisible, setIsCreateNodeModalVisible] = useState(false);
const [isCloneEntityModalVisible, setIsCloneEntityModalVisible] = useState(false);
const [isDeprecationModalVisible, setIsDeprecationModalVisible] = useState(false);
const [isEntityAnnouncementModalVisible, setIsEntityAnnouncementModalVisible] = useState(false);
const [isMoveModalVisible, setIsMoveModalVisible] = useState(false);
Expand Down Expand Up @@ -288,6 +289,18 @@ const EntityDropdown = (props: Props) => {
});
}

if (menuItems.has(EntityMenuItems.CLONE)) {
menuItemsList.push({
type: 'item' as const,
key: '10',
title: 'Clone',
icon: 'Copy',
disabled: !entityData?.privileges?.canManageEntity,
onClick: () => setIsCloneEntityModalVisible(true),
'data-testid': 'entity-menu-clone-button',
});
}

if (menuItems.has(EntityMenuItems.RAISE_INCIDENT)) {
menuItemsList.push({
type: 'item' as const,
Expand Down Expand Up @@ -463,6 +476,15 @@ const EntityDropdown = (props: Props) => {
refetchData={refetchForNodes}
/>
)}
{isCloneEntityModalVisible && (
<CreateGlossaryEntityModal
entityType={entityType}
canCreateGlossaryEntity
onClose={() => setIsCloneEntityModalVisible(false)}
refetchData={entityType === EntityType.GlossaryTerm ? refetchForTerms : refetchForNodes}
isCloning
/>
)}
{isDeprecationModalVisible && (
<UpdateDeprecationModal
urns={[urn]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export enum EntityMenuItems {
ANNOUNCE, // acryl-main only
RAISE_INCIDENT,
LINK_VERSION,
CLONE,
}

export const MenuIcon = styled(MoreOutlined)<{ fontSize?: number }>`
Expand Down
Loading