= memo(() => {
ref={ref}
>
{sortedLayoutWidgets.length ? (
-
+ <>
= memo(() => {
{boardChildren}
- {!isEmptyArray(editingWidgetIds) &&
}
-
+ {!!editingWidgetIds &&
}
+ >
) : (
@@ -212,6 +211,7 @@ const Wrapper = styled.div<{}>`
`;
const StyledContainer = styled(StyledBackground)<{ curWH: number[] }>`
+ position: relative;
display: flex;
flex-direction: column;
min-height: 0;
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/AutoEditor/index.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/AutoEditor/index.tsx
index 1b5dd788e..1cd36231b 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/AutoEditor/index.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/AutoEditor/index.tsx
@@ -16,24 +16,46 @@
* limitations under the License.
*/
+import { SplitPane } from 'app/components/SplitPane';
+import { dispatchResize } from 'app/utils/dispatchResize';
import { memo, useContext } from 'react';
import styled from 'styled-components/macro';
-import { LEVEL_1 } from 'styles/StyleConstants';
import { WidgetActionContext } from '../../../components/ActionProvider/WidgetActionProvider';
import { BoardToolBar } from '../components/BoardToolBar/BoardToolBar';
import { LayerTreePanel } from '../components/LayerPanel/LayerTreePanel';
import SlideSetting from '../components/SlideSetting/SlideSetting';
import { AutoBoardEditor } from './AutoBoardEditor';
+
export const AutoEditor: React.FC<{}> = memo(() => {
const { onEditClearActiveWidgets } = useContext(WidgetActionContext);
+ const clearSelectedWidgets = e => {
+ e.stopPropagation();
+ onEditClearActiveWidgets();
+ };
+
return (
-
+
-
+
-
-
-
+
+
+
+
+
);
});
@@ -45,11 +67,3 @@ const Wrapper = styled.div`
min-height: 0;
overflow: hidden;
`;
-
-const Editor = styled.div`
- z-index: ${LEVEL_1};
- display: flex;
- flex: 1;
- min-height: 0;
- overflow-x: auto;
-`;
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/FreeBoardEditor.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/FreeBoardEditor.tsx
index 147bcf05c..48760381e 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/FreeBoardEditor.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/FreeBoardEditor.tsx
@@ -22,7 +22,6 @@ import { WidgetWrapProvider } from 'app/pages/DashBoardPage/components/WidgetPro
import { memo, useContext } from 'react';
import { useSelector } from 'react-redux';
import styled from 'styled-components/macro';
-import { isEmptyArray } from 'utils/object';
import SlideBackground from '../../../components/FreeBoardBackground';
import useClientRect from '../../../hooks/useClientRect';
import useSlideStyle from '../../../hooks/useSlideStyle';
@@ -76,7 +75,7 @@ export const FreeBoardEditor: React.FC<{}> = memo(() => {
))}
- {!isEmptyArray(editingWidgetIds) && }
+ {!!editingWidgetIds && }
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/WidgetOfFreeEdit.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/WidgetOfFreeEdit.tsx
index e89bb3013..a3bf0d4ed 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/WidgetOfFreeEdit.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/WidgetOfFreeEdit.tsx
@@ -73,7 +73,7 @@ export const WidgetOfFreeEdit: React.FC<{}> = () => {
}, [height, width, x, y]);
const move = useCallback(
- (selectedIds: string[], deltaX: number, deltaY: number) => {
+ (selectedIds: string, deltaX: number, deltaY: number) => {
if (!selectedIds.includes(widget.id)) return;
setCurXY(c => [c[0] + deltaX, c[1] + deltaY]);
},
@@ -115,7 +115,11 @@ export const WidgetOfFreeEdit: React.FC<{}> = () => {
(e, data) => {
e.stopPropagation();
const { deltaX, deltaY } = data;
- widgetMove.emit(selectedIds.concat(widget.id), deltaX, deltaY);
+ widgetMove.emit(
+ !!selectedIds ? `${selectedIds},${widget.id}` : widget.id,
+ deltaX,
+ deltaY,
+ );
},
[selectedIds, widget.id],
);
@@ -161,7 +165,7 @@ export const WidgetOfFreeEdit: React.FC<{}> = () => {
e.stopPropagation();
};
- if (editingWidgetIds?.includes(widget?.id)) {
+ if (editingWidgetIds.includes(widget?.id)) {
style['zIndex'] = LEVEL_DASHBOARD_EDIT_OVERLAY + 1;
}
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/index.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/index.tsx
index 762e5e374..5ebcef709 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/index.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/FreeEditor/index.tsx
@@ -16,36 +16,44 @@
* limitations under the License.
*/
-import { Layout } from 'antd';
-import { memo } from 'react';
-import { useDispatch } from 'react-redux';
+import { SplitPane } from 'app/components/SplitPane';
+import { WidgetActionContext } from 'app/pages/DashBoardPage/components/ActionProvider/WidgetActionProvider';
+import { memo, useContext } from 'react';
import styled from 'styled-components/macro';
import { BoardToolBar } from '../components/BoardToolBar/BoardToolBar';
import { LayerTreePanel } from '../components/LayerPanel/LayerTreePanel';
import SlideSetting from '../components/SlideSetting/SlideSetting';
-import { editDashBoardInfoActions, editWidgetInfoActions } from '../slice';
import { FreeBoardEditor } from './FreeBoardEditor';
export const FreeEditor: React.FC = memo(() => {
- const dispatch = useDispatch();
+ const { onEditClearActiveWidgets } = useContext(WidgetActionContext);
const clearSelectedWidgets = e => {
e.stopPropagation();
- dispatch(editWidgetInfoActions.clearSelectedWidgets());
- dispatch(editDashBoardInfoActions.changeShowBlockMask(true));
+ onEditClearActiveWidgets();
};
return (
-
-
-
-
- {/* */}
-
+
+
+
+
+
-
-
-
+
+
+
);
});
@@ -57,9 +65,3 @@ const Wrapper = styled.div`
min-height: 0;
overflow: hidden;
`;
-
-const Editor = styled.div`
- display: flex;
- flex: 1;
- min-height: 0;
-`;
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/BoardToolBar/CopyPaste/CopyPaste.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/BoardToolBar/CopyPaste/CopyPaste.tsx
index 0010528d6..2670e4dce 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/BoardToolBar/CopyPaste/CopyPaste.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/BoardToolBar/CopyPaste/CopyPaste.tsx
@@ -32,12 +32,12 @@ export const CopyBtn: FC<{
const selectedIds = useSelector(selectSelectedIds);
const onCopy = () => {
- fn(selectedIds);
+ fn();
};
return (
}
/>
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/BoardToolBar/DelWidgetsBtn.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/BoardToolBar/DelWidgetsBtn.tsx
index 0545210ae..57956c983 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/BoardToolBar/DelWidgetsBtn.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/BoardToolBar/DelWidgetsBtn.tsx
@@ -30,7 +30,7 @@ export const DelWidgetsBtn: FC<{
return (
}
/>
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTree.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTree.tsx
index 4bd309403..7c9e5fbbc 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTree.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTree.tsx
@@ -18,11 +18,11 @@
import { Tree } from 'app/components';
import { renderIcon } from 'app/hooks/useGetVizIcon';
+import useResizeObserver from 'app/hooks/useResizeObserver';
import { WidgetActionContext } from 'app/pages/DashBoardPage/components/ActionProvider/WidgetActionProvider';
import widgetManager from 'app/pages/DashBoardPage/components/WidgetManager';
import { FC, memo, useCallback, useContext } from 'react';
import { useDispatch, useSelector } from 'react-redux';
-import { isEmptyArray } from 'utils/object';
import { stopPPG } from 'utils/utils';
import { dropLayerNodeAction } from '../../slice/actions/actions';
import {
@@ -30,7 +30,7 @@ import {
selectLayerTree,
selectSelectedIds,
} from '../../slice/selectors';
-import { LayerTreeItem } from './LayerTreeItem';
+import { EventLayerNode, LayerTreeItem } from './LayerTreeItem';
export const LayerTree: FC<{}> = memo(() => {
const dispatch = useDispatch();
@@ -38,7 +38,12 @@ export const LayerTree: FC<{}> = memo(() => {
const renderTreeItem = useCallback(n => , []);
const { onEditSelectWidget } = useContext(WidgetActionContext);
const editingWidgetIds = useSelector(selectEditingWidgetIds);
- const selectedKeys = useSelector(selectSelectedIds);
+ const selectedIds = useSelector(selectSelectedIds);
+
+ const { height, ref } = useResizeObserver({
+ refreshMode: 'debounce',
+ refreshRate: 200,
+ });
const treeSelect = useCallback(
(_, { node, nativeEvent }) => {
@@ -57,14 +62,27 @@ export const LayerTree: FC<{}> = memo(() => {
);
const onDrop = useCallback(
- info => dispatch(dropLayerNodeAction(info)),
+ info => {
+ const dragNode = info.dragNode as EventLayerNode;
+ const targetNode = info.node as EventLayerNode;
+ let dropPosition = 'NORMAL';
+
+ if (targetNode.dragOverGapTop) {
+ dropPosition = 'TOP';
+ }
+ if (targetNode.dragOver && !targetNode.isLeaf) {
+ dropPosition = 'FOLDER';
+ }
+
+ dispatch(dropLayerNodeAction(dragNode, targetNode, dropPosition));
+ },
[dispatch],
);
return (
= memo(() => {
onClick={stopPPG}
onDrop={onDrop}
treeData={treeData}
- selectedKeys={selectedKeys}
+ selectedKeys={selectedIds ? selectedIds.split(',') : []}
+ height={height}
+ wrapperRef={ref}
defaultExpandAll
/>
);
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTreeItem.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTreeItem.tsx
index b9b7c07fc..a1044d196 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTreeItem.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTreeItem.tsx
@@ -29,7 +29,6 @@ import { stopPPG } from 'utils/utils';
export interface LayerNode extends TreeDataNode {
key: string;
parentId: string;
- selected: boolean;
children: LayerNode[];
content: any;
widgetIndex: number;
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTreePanel.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTreePanel.tsx
index c311a5e15..de93106d6 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTreePanel.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/LayerTreePanel.tsx
@@ -42,7 +42,7 @@ export const LayerTreePanel: FC<{}> = memo(() => {
const Panel = styled.div`
display: flex;
flex-direction: column;
- width: 200px;
+ height: 100%;
background-color: ${p => p.theme.componentBackground};
box-shadow: ${p => p.theme.shadowSider};
`;
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/utils.ts b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/utils.ts
index 49f5806e9..1ff1bc7e3 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/utils.ts
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/LayerPanel/utils.ts
@@ -18,16 +18,15 @@
import { ORIGINAL_TYPE_MAP } from 'app/pages/DashBoardPage/constants';
import { Widget } from 'app/pages/DashBoardPage/types/widgetTypes';
-import { TabWidgetContent, WidgetInfo } from '../../../Board/slice/types';
-import { EventLayerNode, LayerNode } from './LayerTreeItem';
+import { TabWidgetContent } from '../../../Board/slice/types';
+import { LayerNode } from './LayerTreeItem';
export const widgetMapToTree = (args: {
widgetMap: Record;
- widgetInfoMap: Record;
parentId: string;
tree: LayerNode[] | undefined;
}) => {
- const { widgetMap, widgetInfoMap, parentId, tree } = args;
+ const { widgetMap, parentId, tree } = args;
const widgets = Object.values(widgetMap).filter(widget => {
if (!parentId && !widget.parentId) {
@@ -70,14 +69,12 @@ export const widgetMapToTree = (args: {
boardId: widget.dashboardId,
content: widget.config.content,
originalType: widget.config.originalType,
- selected: widgetInfoMap[widget.id].selected,
};
if (widget.config.originalType === ORIGINAL_TYPE_MAP.group) {
treeNode.isLeaf = false;
treeNode.children = widgetMapToTree({
widgetMap,
- widgetInfoMap,
parentId: widget.id,
tree: treeNode.children,
});
@@ -85,7 +82,6 @@ export const widgetMapToTree = (args: {
treeNode.isLeaf = false;
treeNode.children = widgetMapToTree({
widgetMap,
- widgetInfoMap,
parentId: widget.id,
tree: treeNode.children,
});
@@ -95,105 +91,29 @@ export const widgetMapToTree = (args: {
return tree as LayerNode[];
};
-export function parentIsGroup(
- widgetMap: Record,
- parentId?: string,
-) {
- if (!parentId) return true;
- if (
- widgetMap[parentId] &&
- widgetMap[parentId].config.originalType !== ORIGINAL_TYPE_MAP.group
- ) {
- return false;
- }
- return true;
-}
-
-export function getChildrenValList(
+export function getDropInfo(
widgetMap: Record,
+ id: string,
pid: string,
) {
- const widgetList = Object.values(widgetMap).filter(
- widget => widget.parentId === pid,
- );
+ const parent = widgetMap[pid];
+ const inTabs = parent?.config.originalType === ORIGINAL_TYPE_MAP.tab;
+ let siblings: string[] = [];
- if (parentIsGroup(widgetMap, pid)) {
- // group
- return widgetList
- .map(widget => ({
- id: widget.id,
- index: widget.config.index,
- }))
- .sort((b, a) => a.index - b.index);
+ if (inTabs) {
+ const itemMap = (parent.config.content as TabWidgetContent).itemMap;
+ siblings = Object.values(itemMap || {})
+ .filter(i => i.childWidgetId && i.childWidgetId !== id)
+ .sort((a, b) => b.index - a.index)
+ .map(item => item.childWidgetId);
} else {
- // container
- const container = widgetMap[pid];
- const childItemMap = (container.config.content as TabWidgetContent).itemMap;
- return Object.values(childItemMap || {})
- .map(item => ({
- id: item.childWidgetId,
- index: item.index,
- }))
- .sort((b, a) => a.index - b.index);
+ siblings = Object.values(widgetMap)
+ .filter(widget => widget.parentId === pid && widget.id !== id)
+ .sort((a, b) => b.config.index - a.config.index)
+ .map(({ id }) => id);
}
-}
-export function getNewDragNodeValue(args: {
- widgetMap: Record;
- dragNode: EventLayerNode;
- targetNode: EventLayerNode;
-}) {
- const { widgetMap, dragNode, targetNode } = args;
- const newVal = {
- index: 0,
- parentId: targetNode.parentId,
- parentIsGroup: true,
+ return {
+ siblings,
+ inTabs,
};
- if (targetNode.dragOverGapTop) {
- const indexList = getChildrenValList(widgetMap, targetNode.parentId);
- newVal.index = indexList[0].index + 1;
-
- return newVal;
- }
- if (targetNode.dragOver) {
- if (targetNode.isLeaf) {
- // dragOver Leaf
- const indexList = getChildrenValList(widgetMap, targetNode.parentId);
- const targetIndex = indexList.findIndex(t => t.id === targetNode.key);
- if (targetIndex < indexList.length - 1) {
- let indexA = indexList[targetIndex].index;
- let indexC = indexList[targetIndex + 1].index;
- newVal.index = (indexA + indexC) / 2;
- } else {
- newVal.index = indexList[targetIndex].index - 1;
- }
- newVal.parentId = targetNode.parentId;
- newVal.parentIsGroup = parentIsGroup(widgetMap, targetNode.parentId);
- return newVal;
- } else {
- // dragOver folder
- const indexList = getChildrenValList(widgetMap, targetNode.key);
- if (indexList.length < 1) {
- newVal.index = dragNode.widgetIndex;
- } else {
- newVal.index = indexList[0].index + 1;
- }
- newVal.parentId = targetNode.key;
- newVal.parentIsGroup = parentIsGroup(widgetMap, targetNode.key);
- return newVal;
- }
- } else if (!targetNode.dragOver) {
- const indexList = getChildrenValList(widgetMap, targetNode.parentId);
- const targetIndex = indexList.findIndex(t => t.id === targetNode.key);
- if (targetIndex < indexList.length - 1) {
- let indexA = indexList[targetIndex].index;
- let indexC = indexList[targetIndex + 1].index;
- newVal.index = (indexA + indexC) / 2;
- } else {
- newVal.index = indexList[targetIndex].index - 1;
- }
- newVal.parentId = targetNode.parentId;
- newVal.parentIsGroup = parentIsGroup(widgetMap, targetNode.parentId);
- return newVal;
- }
- return newVal;
}
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/SlideSetting/SlideSetting.tsx b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/SlideSetting/SlideSetting.tsx
index 1425ec9f5..a70824d4a 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/SlideSetting/SlideSetting.tsx
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/components/SlideSetting/SlideSetting.tsx
@@ -27,16 +27,17 @@ import WidgetSetting from './WidgetSetting';
export const SlideSetting: FC<{}> = memo(() => {
const { boardId } = useContext(BoardContext);
const selectedIds = useSelector(selectSelectedIds);
- const setType = useMemo(
- () => (selectedIds.length === 1 ? 'widget' : 'board'),
- [selectedIds.length],
- );
+ const { type, selectedIdArr } = useMemo(() => {
+ const selectedIdArr = selectedIds ? selectedIds.split(',') : [];
+ const type = selectedIdArr.length === 1 ? 'widget' : 'board';
+ return { type, selectedIdArr };
+ }, [selectedIds]);
return (
- {setType === 'board' && }
- {setType === 'widget' && (
+ {type === 'board' && }
+ {type === 'widget' && (
@@ -52,8 +53,7 @@ export default SlideSetting;
const Wrapper = styled.div<{}>`
display: flex;
flex-direction: column;
- width: 330px;
- min-width: 330px;
+ height: 100%;
min-height: 0;
background-color: ${p => p.theme.componentBackground};
box-shadow: ${p => p.theme.shadowSider};
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/actions/actions.ts b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/actions/actions.ts
index 4c3c54026..4610f26e8 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/actions/actions.ts
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/actions/actions.ts
@@ -25,7 +25,6 @@ import {
import { boardActions } from 'app/pages/DashBoardPage/pages/Board/slice';
import {
BoardState,
- ContainerItem,
Dashboard,
DataChart,
TabWidgetContent,
@@ -58,7 +57,7 @@ import { ORIGINAL_TYPE_MAP } from '../../../../constants';
import { selectWidgetInfoMap } from '../../../Board/slice/selector';
import { syncBoardWidgetChartDataAsync } from '../../../Board/slice/thunk';
import { EventLayerNode } from '../../components/LayerPanel/LayerTreeItem';
-import { getNewDragNodeValue } from '../../components/LayerPanel/utils';
+import { getDropInfo } from '../../components/LayerPanel/utils';
import { selectAllWidgetInfoMap } from '../selectors';
import {
getEditChartWidgetDataAsync,
@@ -494,45 +493,48 @@ export const editorWidgetClearLinkageAction =
});
};
-export const dropLayerNodeAction = info => (dispatch, getState) => {
- const dragNode = info.dragNode as EventLayerNode;
- const targetNode = info.node as EventLayerNode;
- const editBoard = getState().editBoard as HistoryEditBoard;
- const widgetMap = editBoard.stack.present.widgetRecord;
-
- /*
- 1 -> group
- 2 -> container
- */
- //拖拽节点来自 group
- const newDragVal = getNewDragNodeValue({ widgetMap, dragNode, targetNode });
- if (newDragVal.parentIsGroup) {
- // 拖进 group
- dispatch(
- editBoardStackActions.dropWidgetToGroup({
- sourceId: dragNode.key,
- newIndex: newDragVal.index,
- targetId: newDragVal.parentId,
- }),
+export const dropLayerNodeAction =
+ (
+ dragNode: EventLayerNode,
+ targetNode: EventLayerNode,
+ dropPosition: string,
+ ) =>
+ (dispatch, getState) => {
+ const editBoard = getState().editBoard as HistoryEditBoard;
+ const widgetMap = editBoard.stack.present.widgetRecord;
+ const newParentId =
+ dropPosition === 'FOLDER' ? targetNode.key : targetNode.parentId;
+ const { siblings, inTabs } = getDropInfo(
+ widgetMap,
+ dragNode.key,
+ newParentId,
);
- } else {
- // 拖进 tab
- const dragWidget = widgetMap[dragNode.key];
- const newItem: ContainerItem = {
- index: newDragVal.index,
- name: dragWidget.config.name,
- tabId: dragWidget.config.clientId,
- childWidgetId: dragWidget.id,
- };
+ let reorderedChildren: string[] = [];
+
+ switch (dropPosition) {
+ case 'TOP':
+ reorderedChildren = [dragNode.key, ...siblings];
+ break;
+ case 'FOLDER':
+ reorderedChildren = [dragNode.key, ...siblings];
+ break;
+ default:
+ const targetIndex = siblings.findIndex(s => s === targetNode.key);
+ siblings.splice(targetIndex + 1, 0, dragNode.key);
+ reorderedChildren = [...siblings];
+ break;
+ }
+
dispatch(
- editBoardStackActions.dropWidgetToTab({
- newItem,
- targetId: newDragVal.parentId,
+ editBoardStackActions.dropWidgetLayer({
+ id: dragNode.key,
+ currentParentId: dragNode.parentId,
+ newParentId,
+ children: reorderedChildren,
+ inTabs,
}),
);
- return;
- }
-};
+ };
export const selectWidgetAction =
(args: { multipleKey: boolean; id: string; selected: boolean }) =>
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/childSlice/stackSlice.ts b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/childSlice/stackSlice.ts
index 7fde62b1b..a779d58d0 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/childSlice/stackSlice.ts
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/childSlice/stackSlice.ts
@@ -440,84 +440,64 @@ export const editBoardStackSlice = createSlice({
}
},
- dropWidgetToGroup(
+ dropWidgetLayer(
state,
- action: PayloadAction<{
- sourceId: string;
- newIndex: number;
- targetId: string;
+ {
+ payload: { id, currentParentId, newParentId, children, inTabs },
+ }: PayloadAction<{
+ id: string;
+ currentParentId: string;
+ newParentId: string;
+ children: string[];
+ inTabs: boolean;
}>,
) {
const widgetMap = state.widgetRecord;
- const { sourceId, newIndex, targetId } = action.payload;
+ const currentParent = widgetMap[currentParentId];
+ const newParent = widgetMap[newParentId];
- const dragWidget = widgetMap[sourceId];
- //
- const dragParent = widgetMap[dragWidget.parentId || ''];
- if (dragParent) {
- dragParent.config.children = dragParent.config.children?.filter(
- t => t !== dragWidget.id,
+ if (currentParent) {
+ currentParent.config.children = currentParent.config.children?.filter(
+ c => c !== id,
);
- if (dragParent.config.originalType === ORIGINAL_TYPE_MAP.tab) {
- const srcTabItemMap = (dragParent.config.content as TabWidgetContent)
- .itemMap;
-
- const srcItem = Object.values(srcTabItemMap).find(
- item => item.childWidgetId === dragWidget.id,
+ if (currentParent.config.originalType === ORIGINAL_TYPE_MAP.tab) {
+ const currentParentItemMap = (
+ currentParent.config.content as TabWidgetContent
+ ).itemMap;
+ const draggedItem = Object.values(currentParentItemMap).find(
+ ({ childWidgetId }) => childWidgetId === id,
);
- if (srcItem) {
- delete srcTabItemMap[srcItem.tabId];
+ if (draggedItem) {
+ delete currentParentItemMap[draggedItem.tabId];
}
}
}
- //
- dragWidget.config.index = newIndex;
- dragWidget.parentId = targetId;
- if (widgetMap[targetId]) {
- widgetMap[targetId].config.children?.push(dragWidget.id);
- }
- //
- },
- dropWidgetToTab(
- state,
- action: PayloadAction<{
- newItem: ContainerItem;
- targetId: string;
- }>,
- ) {
- const { newItem, targetId } = action.payload;
- const widgetMap = state.widgetRecord;
- const dragWidget = widgetMap[newItem.childWidgetId];
- //
- const dragParent = widgetMap[dragWidget.parentId || ''];
- if (dragParent) {
- dragParent.config.children = dragParent.config.children?.filter(
- t => t !== dragWidget.id,
- );
- if (dragParent.config.originalType === ORIGINAL_TYPE_MAP.tab) {
- const srcTabItemMap = (dragParent.config.content as TabWidgetContent)
- .itemMap;
-
- const srcItem = Object.values(srcTabItemMap).find(
- item => item.childWidgetId === dragWidget.id,
- );
- if (srcItem) {
- delete srcTabItemMap[srcItem.tabId];
- }
+ if (inTabs) {
+ (newParent.config.content as TabWidgetContent).itemMap = {};
+ } else {
+ if (newParent) {
+ newParent.config.children = [...children];
}
}
- //
- const targetTabWidget = widgetMap[targetId];
- const targetTabItemMap = (
- targetTabWidget.config.content as TabWidgetContent
- ).itemMap;
- targetTabItemMap[dragWidget.config.clientId] = newItem;
- dragWidget.parentId = targetId;
+ children.forEach((id, index) => {
+ const childWidget = widgetMap[id];
+ childWidget.config.index = children.length - 1 - index;
+ childWidget.parentId = newParentId;
- //
+ if (inTabs) {
+ (newParent.config.content as TabWidgetContent).itemMap[
+ childWidget.config.clientId
+ ] = {
+ index: childWidget.config.index,
+ name: childWidget.config.name,
+ tabId: childWidget.config.clientId,
+ childWidgetId: childWidget.id,
+ };
+ }
+ });
},
/* MediaWidgetConfig */
changeMediaWidgetConfig(
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/events.ts b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/events.ts
index 0ab19c534..47c0cbeae 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/events.ts
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/events.ts
@@ -4,17 +4,17 @@ const eventBus = new EventEmitter();
const WIDGET_MOVE = 'widgetMove';
const WIDGET_MOVE_END = 'widgetMoveEnd';
const BOARD_SCROLL = 'boardScroll';
-eventBus.setMaxListeners(100);
+eventBus.setMaxListeners(1000);
interface FnWidgetMove {
- (selectedIds: string[], deltaX: number, deltaY: number): void;
+ (selectedIdStr: string, deltaX: number, deltaY: number): void;
}
export const widgetMove = {
on: (fn: FnWidgetMove) => {
eventBus.addListener(WIDGET_MOVE, fn);
},
- emit: (selectedIds: string[], deltaX: number, deltaY: number) => {
- eventBus.emit(WIDGET_MOVE, selectedIds, deltaX, deltaY);
+ emit: (selectedIdStr: string, deltaX: number, deltaY: number) => {
+ eventBus.emit(WIDGET_MOVE, selectedIdStr, deltaX, deltaY);
},
off: (fn: FnWidgetMove) => {
eventBus.removeListener(WIDGET_MOVE, fn);
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/index.ts b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/index.ts
index 6f834e305..061859876 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/index.ts
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/index.ts
@@ -362,8 +362,7 @@ const filterActions = [
editBoardStackActions.updateBoardConfigByKey,
editBoardStackActions.updateWidgetStyleConfigByPath,
editBoardStackActions.changeFreeWidgetRect,
- editBoardStackActions.dropWidgetToTab,
- editBoardStackActions.dropWidgetToGroup,
+ editBoardStackActions.dropWidgetLayer,
].map(ele => ele.toString());
const editBoardStackReducer = undoable(editBoardStackSlice.reducer, {
undoType: BOARD_UNDO.undo,
diff --git a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/selectors.ts b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/selectors.ts
index fd251c088..7398487d0 100644
--- a/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/selectors.ts
+++ b/frontend/src/app/pages/DashBoardPage/pages/BoardEditor/slice/selectors.ts
@@ -111,8 +111,10 @@ export const selectAllWidgetInfoMap = (state: { editBoard: EditBoardState }) =>
export const selectEditingWidgetIds = (state: { editBoard: EditBoardState }) =>
Object.values(state.editBoard.widgetInfoRecord)
- ?.filter(r => r.editing)
- ?.map(r => r.id) || [];
+ .filter(r => r.editing)
+ .map(r => r.id)
+ .sort()
+ .join(',');
export const selectWidgetInfoById = createSelector(
[selectAllWidgetInfoMap, (_, widgetId: string) => widgetId],
@@ -135,7 +137,9 @@ export const selectSelectedIds = createSelector(
WidgetsInfo =>
Object.values(WidgetsInfo)
.filter(widgetInfo => widgetInfo.selected)
- .map(widgetInfo => widgetInfo.id) || [],
+ .map(widgetInfo => widgetInfo.id)
+ .sort()
+ .join(','),
);
export const selectWidgetInfoDatachartId = createSelector(
@@ -147,11 +151,10 @@ export const selectWidgetInfoDatachartId = createSelector(
);
export const selectLayerTree = createSelector(
- [selectAllWidgetMap, selectAllWidgetInfoMap],
- (widgetMap, widgetInfoMap) => {
+ [selectAllWidgetMap],
+ widgetMap => {
return widgetMapToTree({
widgetMap,
- widgetInfoMap,
parentId: '',
tree: [],
});
diff --git a/frontend/src/app/pages/DashBoardPage/utils/board.ts b/frontend/src/app/pages/DashBoardPage/utils/board.ts
index 9951b1881..e681607ee 100644
--- a/frontend/src/app/pages/DashBoardPage/utils/board.ts
+++ b/frontend/src/app/pages/DashBoardPage/utils/board.ts
@@ -83,7 +83,7 @@ export const getScheduleBoardInfo = (
let newBoardInfo: BoardInfo = { ...boardInfo };
const needFetchItems = Object.values(widgetMap)
.filter(widget => {
- if (widget.viewIds && widget.viewIds.length > 0) {
+ if (widget.viewIds && widget.viewIds.length > 0 && widget.viewIds[0]) {
return true;
}
return false;