Skip to content

Commit 46431fc

Browse files
committed
refactor: data model tree style improvement
1 parent 14a968b commit 46431fc

File tree

5 files changed

+149
-248
lines changed

5 files changed

+149
-248
lines changed

frontend/src/app/components/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export { ListItem } from './ListItem';
1111
export { ListNav, ListPane } from './ListNav';
1212
export { ListSwitch } from './ListSwitch';
1313
export { ListTitle } from './ListTitle';
14+
export type { ListTitleProps } from './ListTitle';
1415
export { LoadingMask } from './LoadingMask';
1516
export { ModalForm } from './ModalForm';
1617
export type { ModalFormProps } from './ModalForm';

frontend/src/app/pages/MainPage/pages/ViewPage/Main/Properties/Container.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,26 @@
1717
*/
1818

1919
import { Skeleton } from 'antd';
20-
import { ListTitle } from 'app/components';
20+
import { ListTitle, ListTitleProps } from 'app/components';
2121
import useI18NPrefix from 'app/hooks/useI18NPrefix';
22-
import { FC, memo } from 'react';
22+
import { FC, memo, ReactNode } from 'react';
2323
import styled from 'styled-components/macro';
2424
import { SPACE_TIMES } from 'styles/StyleConstants';
2525

26-
const Container: FC<any> = memo(props => {
26+
interface ContainerProps extends ListTitleProps {
27+
title: string;
28+
loading?: boolean;
29+
children?: ReactNode;
30+
}
31+
32+
const Container: FC<ContainerProps> = memo(props => {
2733
const t = useI18NPrefix('view.properties');
28-
const { title, children, isLoading, ...rest } = props;
34+
const { title, children, loading, ...rest } = props;
2935

3036
return (
3137
<StyledContainer>
3238
<ListTitle title={t(title)} {...rest} />
33-
<Skeleton active loading={isLoading}>
39+
<Skeleton active loading={loading}>
3440
{children}
3541
</Skeleton>
3642
</StyledContainer>

frontend/src/app/pages/MainPage/pages/ViewPage/Main/Properties/DataModelTree/DataModelBranch.tsx

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ import {
2121
EditOutlined,
2222
FolderOpenOutlined,
2323
} from '@ant-design/icons';
24-
import { Tooltip } from 'antd';
25-
import { IW, ToolbarButton } from 'app/components';
24+
import { Button, Tooltip } from 'antd';
25+
import { IW } from 'app/components';
2626
import useI18NPrefix from 'app/hooks/useI18NPrefix';
2727
import { FC, memo, useState } from 'react';
2828
import { Draggable, Droppable } from 'react-beautiful-dnd';
2929
import styled from 'styled-components/macro';
3030
import {
3131
FONT_SIZE_BASE,
3232
FONT_SIZE_HEADING,
33-
INFO,
34-
SPACE_UNIT,
33+
SPACE,
34+
SPACE_MD,
35+
SPACE_XS,
3536
YELLOW,
3637
} from 'styles/StyleConstants';
3738
import { Column } from '../../../slice/types';
@@ -40,19 +41,19 @@ import DataModelNode from './DataModelNode';
4041

4142
const DataModelBranch: FC<{
4243
node: Column;
43-
getPermissionButton: (name) => JSX.Element;
4444
onNodeTypeChange: (type: any, name: string) => void;
4545
onMoveToHierarchy: (node: Column) => void;
4646
onEditBranch;
4747
onDelete: (node: Column) => void;
48+
onDeleteFromHierarchy: (parent: Column) => (node: Column) => void;
4849
}> = memo(
4950
({
5051
node,
51-
getPermissionButton,
5252
onNodeTypeChange,
5353
onMoveToHierarchy,
5454
onEditBranch,
5555
onDelete,
56+
onDeleteFromHierarchy,
5657
}) => {
5758
const t = useI18NPrefix('view.model');
5859
const [isHover, setIsHover] = useState(false);
@@ -78,23 +79,19 @@ const DataModelBranch: FC<{
7879
<div className="action">
7980
{isHover && !isDragging && (
8081
<Tooltip title={t('rename')}>
81-
<ToolbarButton
82-
size="small"
83-
iconSize={FONT_SIZE_BASE}
84-
className="suffix"
82+
<Button
83+
type="link"
8584
onClick={() => onEditBranch(node)}
86-
icon={<EditOutlined style={{ color: INFO }} />}
85+
icon={<EditOutlined />}
8786
/>
8887
</Tooltip>
8988
)}
9089
{isHover && !isDragging && (
9190
<Tooltip title={t('delete')}>
92-
<ToolbarButton
93-
size="small"
94-
iconSize={FONT_SIZE_BASE}
95-
className="suffix"
91+
<Button
92+
type="link"
9693
onClick={() => onDelete(node)}
97-
icon={<DeleteOutlined style={{ color: INFO }} />}
94+
icon={<DeleteOutlined />}
9895
/>
9996
</Tooltip>
10097
)}
@@ -103,11 +100,12 @@ const DataModelBranch: FC<{
103100
<div className="children">
104101
{node?.children?.map(childNode => (
105102
<DataModelNode
103+
className="in-hierarchy"
106104
node={childNode}
107105
key={childNode.name}
108-
getPermissionButton={getPermissionButton}
109106
onMoveToHierarchy={onMoveToHierarchy}
110107
onNodeTypeChange={onNodeTypeChange}
108+
onDeleteFromHierarchy={onDeleteFromHierarchy(node)}
111109
/>
112110
))}
113111
</div>
@@ -152,23 +150,23 @@ const DataModelBranch: FC<{
152150
export default DataModelBranch;
153151

154152
const StyledDataModelBranch = styled.div<{}>`
153+
margin: ${SPACE} ${SPACE_MD};
154+
font-size: ${FONT_SIZE_BASE};
155155
line-height: 32px;
156-
margin: ${SPACE_UNIT};
157156
user-select: 'none';
158-
font-size: ${FONT_SIZE_BASE};
159157
160158
& .content {
161159
display: flex;
162160
}
163161
164162
& .children {
165-
margin-left: 40px;
163+
margin-left: ${SPACE_MD};
166164
}
167165
168166
& .action {
169167
display: flex;
170168
flex: 1;
171169
justify-content: flex-end;
172-
padding-right: ${FONT_SIZE_BASE}px;
170+
padding-right: ${SPACE_XS};
173171
}
174172
`;

frontend/src/app/pages/MainPage/pages/ViewPage/Main/Properties/DataModelTree/DataModelNode.tsx

Lines changed: 83 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,27 @@
1919
import {
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';
3030
import { DataViewFieldType } from 'app/constants';
3131
import useI18NPrefix from 'app/hooks/useI18NPrefix';
3232
import { FC, memo, useState } from 'react';
3333
import { Draggable } from 'react-beautiful-dnd';
3434
import styled from 'styled-components/macro';
3535
import {
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

4750
const 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;
206209
const 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

Comments
 (0)