1919import {
2020 BranchesOutlined ,
2121 CalendarOutlined ,
22+ DeleteOutlined ,
2223 FieldStringOutlined ,
2324 FileUnknownOutlined ,
2425 NumberOutlined ,
2526 SisternodeOutlined ,
26- SwapOutlined ,
2727} from '@ant-design/icons' ;
28- import { Dropdown , Menu , Tooltip } from 'antd' ;
29- import { IW , ToolbarButton } from 'app/components' ;
28+ import { Button , Dropdown , Menu , Tooltip } from 'antd' ;
29+ import { IW } from 'app/components' ;
3030import { DataViewFieldType } from 'app/constants' ;
3131import useI18NPrefix from 'app/hooks/useI18NPrefix' ;
3232import { FC , memo , useState } from 'react' ;
3333import { Draggable } from 'react-beautiful-dnd' ;
3434import styled from 'styled-components/macro' ;
3535import {
3636 FONT_SIZE_BASE ,
37- FONT_SIZE_HEADING ,
37+ FONT_SIZE_TITLE ,
3838 INFO ,
3939 SPACE ,
40+ SPACE_MD ,
41+ SPACE_TIMES ,
42+ SPACE_XS ,
4043 SUCCESS ,
4144 WARNING ,
4245} from 'styles/StyleConstants' ;
@@ -46,17 +49,19 @@ import { ALLOW_COMBINE_COLUMN_TYPES } from './constant';
4649
4750const DataModelNode : FC < {
4851 node : Column ;
49- getPermissionButton : ( name ) => JSX . Element ;
52+ className ?: string ;
5053 onNodeTypeChange : ( type : any , name : string ) => void ;
5154 onMoveToHierarchy : ( node : Column ) => void ;
5255 onCreateHierarchy ?: ( node : Column ) => void ;
56+ onDeleteFromHierarchy ?: ( node : Column ) => void ;
5357} > = memo (
5458 ( {
5559 node,
56- getPermissionButton ,
60+ className ,
5761 onCreateHierarchy,
5862 onMoveToHierarchy,
5963 onNodeTypeChange,
64+ onDeleteFromHierarchy,
6065 } ) => {
6166 const t = useI18NPrefix ( 'view.model' ) ;
6267 const tg = useI18NPrefix ( 'global' ) ;
@@ -104,77 +109,74 @@ const DataModelNode: FC<{
104109 setIsHover ( false ) ;
105110 } }
106111 >
107- < IW fontSize = { FONT_SIZE_HEADING } > { icon } </ IW >
112+ < Dropdown
113+ trigger = { [ 'click' ] }
114+ overlay = {
115+ < Menu
116+ selectedKeys = { [ node . type , `category-${ node . category } ` ] }
117+ className = "datart-schema-table-header-menu"
118+ onClick = { ( { key } ) => onNodeTypeChange ( key , node ?. name ) }
119+ >
120+ { Object . values ( DataViewFieldType ) . map ( t => (
121+ < Menu . Item key = { t } >
122+ { tg ( `columnType.${ t . toLowerCase ( ) } ` ) }
123+ </ Menu . Item >
124+ ) ) }
125+ { hasCategory && (
126+ < >
127+ < Menu . Divider />
128+ < Menu . SubMenu
129+ key = "categories"
130+ title = { t ( 'category' ) }
131+ popupClassName = "datart-schema-table-header-menu"
132+ >
133+ { Object . values ( ColumnCategories ) . map ( t => (
134+ < Menu . Item key = { `category-${ t } ` } >
135+ { tg ( `columnCategory.${ t . toLowerCase ( ) } ` ) }
136+ </ Menu . Item >
137+ ) ) }
138+ </ Menu . SubMenu >
139+ </ >
140+ ) }
141+ </ Menu >
142+ }
143+ >
144+ < Tooltip
145+ title = { hasCategory ? t ( 'typeAndCategory' ) : t ( 'category' ) }
146+ placement = "left"
147+ >
148+ < StyledIW fontSize = { FONT_SIZE_TITLE } > { icon } </ StyledIW >
149+ </ Tooltip >
150+ </ Dropdown >
108151 < span > { node . name } </ span >
109152 < div className = "action" >
110- { isHover && ! isDragging && (
111- < Dropdown
112- trigger = { [ 'click' ] }
113- overlay = {
114- < Menu
115- selectedKeys = { [ node . type , `category-${ node . category } ` ] }
116- className = "datart-schema-table-header-menu"
117- onClick = { ( { key } ) => onNodeTypeChange ( key , node ?. name ) }
118- >
119- { Object . values ( DataViewFieldType ) . map ( t => (
120- < Menu . Item key = { t } >
121- { tg ( `columnType.${ t . toLowerCase ( ) } ` ) }
122- </ Menu . Item >
123- ) ) }
124- { hasCategory && (
125- < >
126- < Menu . Divider />
127- < Menu . SubMenu
128- key = "categories"
129- title = { t ( 'category' ) }
130- popupClassName = "datart-schema-table-header-menu"
131- >
132- { Object . values ( ColumnCategories ) . map ( t => (
133- < Menu . Item key = { `category-${ t } ` } >
134- { tg ( `columnCategory.${ t . toLowerCase ( ) } ` ) }
135- </ Menu . Item >
136- ) ) }
137- </ Menu . SubMenu >
138- </ >
139- ) }
140- </ Menu >
141- }
142- >
143- < Tooltip
144- title = { hasCategory ? t ( 'typeAndCategory' ) : t ( 'category' ) }
145- >
146- < ToolbarButton
147- size = "small"
148- iconSize = { FONT_SIZE_BASE }
149- className = "suffix"
150- icon = { < SwapOutlined style = { { color : INFO } } /> }
151- />
152- </ Tooltip >
153- </ Dropdown >
154- ) }
155- { isHover && ! isDragging && getPermissionButton ( node ?. name ) }
156153 { isHover &&
157154 ! isDragging &&
158155 isAllowCreateHierarchy ( node ) &&
159156 onCreateHierarchy && (
160157 < Tooltip title = { t ( 'newHierarchy' ) } >
161- < ToolbarButton
162- size = "small"
163- iconSize = { FONT_SIZE_BASE }
164- className = "suffix"
158+ < Button
159+ type = "link"
165160 onClick = { ( ) => onCreateHierarchy ( node ) }
166- icon = { < BranchesOutlined style = { { color : INFO } } /> }
161+ icon = { < BranchesOutlined /> }
167162 />
168163 </ Tooltip >
169164 ) }
170165 { isHover && ! isDragging && isAllowCreateHierarchy ( node ) && (
171166 < Tooltip title = { t ( 'addToHierarchy' ) } >
172- < ToolbarButton
173- size = "small"
174- iconSize = { FONT_SIZE_BASE }
175- className = "suffix"
167+ < Button
168+ type = "link"
176169 onClick = { ( ) => onMoveToHierarchy ( node ) }
177- icon = { < SisternodeOutlined style = { { color : INFO } } /> }
170+ icon = { < SisternodeOutlined /> }
171+ />
172+ </ Tooltip >
173+ ) }
174+ { isHover && ! isDragging && onDeleteFromHierarchy && (
175+ < Tooltip title = { t ( 'delete' ) } >
176+ < Button
177+ type = "link"
178+ onClick = { ( ) => onDeleteFromHierarchy ( node ) }
179+ icon = { < DeleteOutlined /> }
178180 />
179181 </ Tooltip >
180182 ) }
@@ -188,6 +190,7 @@ const DataModelNode: FC<{
188190 { ( draggableProvided , draggableSnapshot ) => (
189191 < StyledDataModelNode
190192 isDragging = { draggableSnapshot . isDragging }
193+ className = { className }
191194 style = { draggableProvided . draggableProps . style }
192195 ref = { draggableProvided . innerRef }
193196 { ...draggableProvided . draggableProps }
@@ -206,21 +209,35 @@ export default DataModelNode;
206209const StyledDataModelNode = styled . div < {
207210 isDragging : boolean ;
208211} > `
212+ margin: ${ SPACE } ${ SPACE_MD } ;
213+ font-size: ${ FONT_SIZE_BASE } ;
209214 line-height: 32px;
210- margin: ${ SPACE } ;
211215 user-select: 'none';
212216 background: ${ p =>
213217 p . isDragging ? p . theme . highlightBackground : 'transparent' } ;
214- font-size: ${ FONT_SIZE_BASE } ;
218+
219+ &.in-hierarchy {
220+ margin-right: 0;
221+ }
215222
216223 & .content {
217224 display: flex;
225+ align-items: center;
218226 }
219227
220228 & .action {
221229 display: flex;
222230 flex: 1;
223231 justify-content: flex-end;
224- padding-right: ${ FONT_SIZE_BASE } px ;
232+ padding-right: ${ SPACE_XS } ;
225233 }
226234` ;
235+
236+ const StyledIW = styled ( IW ) `
237+ width: ${ SPACE_TIMES ( 7 ) } ;
238+ height: ${ SPACE_TIMES ( 7 ) } ;
239+ margin-right: ${ SPACE_XS } ;
240+ cursor: pointer;
241+ border: 1px solid ${ p => p . theme . borderColorSplit } ;
242+ border-radius: 4px;
243+ ` ;
0 commit comments