@griddo/ax 11.1.11 → 11.1.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "11.1.
|
|
4
|
+
"version": "11.1.12",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Carlos Torres <carlos.torres@secuoyas.com>",
|
|
@@ -225,5 +225,5 @@
|
|
|
225
225
|
"publishConfig": {
|
|
226
226
|
"access": "public"
|
|
227
227
|
},
|
|
228
|
-
"gitHead": "
|
|
228
|
+
"gitHead": "3cf8c664e60c6b5e2f2eadddaca55eb1867ce11b"
|
|
229
229
|
}
|
|
@@ -19,7 +19,17 @@ const DragButton = ({ dragHandleProps }: any) => (
|
|
|
19
19
|
);
|
|
20
20
|
|
|
21
21
|
const Item = (props: IItemProps): JSX.Element => {
|
|
22
|
-
const {
|
|
22
|
+
const {
|
|
23
|
+
item,
|
|
24
|
+
deleteMenuItem,
|
|
25
|
+
resetItemValues,
|
|
26
|
+
setItemValue,
|
|
27
|
+
updateFormValue,
|
|
28
|
+
icon,
|
|
29
|
+
dragHandleProps,
|
|
30
|
+
depth,
|
|
31
|
+
isDragging,
|
|
32
|
+
} = props;
|
|
23
33
|
const deleteItem = (item: IMenuItem, deleteChildren?: boolean) => deleteMenuItem(item.id, deleteChildren);
|
|
24
34
|
const hasChildren = !!item.children.length;
|
|
25
35
|
|
|
@@ -56,10 +66,12 @@ const Item = (props: IItemProps): JSX.Element => {
|
|
|
56
66
|
};
|
|
57
67
|
|
|
58
68
|
const openModal = () => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
69
|
+
if (!isDragging) {
|
|
70
|
+
resetValues();
|
|
71
|
+
setItem(item);
|
|
72
|
+
setIsOpenedSecond(false);
|
|
73
|
+
toggleModal();
|
|
74
|
+
}
|
|
63
75
|
};
|
|
64
76
|
|
|
65
77
|
const openConfigModal = () => {
|
|
@@ -116,6 +128,7 @@ interface IProps {
|
|
|
116
128
|
icon: JSX.Element;
|
|
117
129
|
dragHandleProps: any;
|
|
118
130
|
depth: number;
|
|
131
|
+
isDragging: boolean;
|
|
119
132
|
}
|
|
120
133
|
|
|
121
134
|
interface IDispatchProps {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ItemId,
|
|
1
|
+
import { ItemId, TreeData, TreeItem } from "@atlaskit/tree";
|
|
2
2
|
import { isEmptyObj } from "@ax/helpers";
|
|
3
3
|
import { IMenuItem } from "@ax/types";
|
|
4
4
|
|
|
@@ -32,11 +32,15 @@ const normalizeMenu = (menu: IMenuItem[], tree: TreeData) => {
|
|
|
32
32
|
children: [],
|
|
33
33
|
isExpanded: isItemExpanded(previousMenu),
|
|
34
34
|
};
|
|
35
|
+
|
|
35
36
|
if (item.children && item.children.length > 0) {
|
|
36
37
|
item.children.forEach((child: IMenuItem, index: number) => {
|
|
37
38
|
normalized.items[item.id].children.push(child.id);
|
|
38
39
|
getElement(child, previousMenu?.children[index]);
|
|
39
40
|
});
|
|
41
|
+
normalized.items[item.id].hasChildren = true;
|
|
42
|
+
} else {
|
|
43
|
+
normalized.items[item.id].hasChildren = false;
|
|
40
44
|
}
|
|
41
45
|
};
|
|
42
46
|
|
|
@@ -85,34 +89,4 @@ const formatItem = (item: any, tree: TreeData) => {
|
|
|
85
89
|
return formattedItem;
|
|
86
90
|
};
|
|
87
91
|
|
|
88
|
-
|
|
89
|
-
const isLeafItem = (item: TreeItem) => !item.children.length;
|
|
90
|
-
|
|
91
|
-
const customMoveItemOnTree = (tree: TreeData, from: TreeSourcePosition, to: TreeDestinationPosition) => {
|
|
92
|
-
const sourceParent = tree.items[from.parentId];
|
|
93
|
-
const newSourceChildren = [...sourceParent.children];
|
|
94
|
-
const itemRemoved = newSourceChildren.splice(from.index, 1)[0];
|
|
95
|
-
const treeWithoutSource = mutateTree(tree, from.parentId, {
|
|
96
|
-
children: newSourceChildren,
|
|
97
|
-
hasChildren: newSourceChildren.length > 0,
|
|
98
|
-
isExpanded: newSourceChildren.length > 0 && sourceParent.isExpanded,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
const destinationParent = treeWithoutSource.items[to.parentId];
|
|
102
|
-
const newDestinationChildren = [...destinationParent.children];
|
|
103
|
-
|
|
104
|
-
if (typeof to.index === "undefined") {
|
|
105
|
-
if (hasLoadedChildren(destinationParent) || isLeafItem(destinationParent)) {
|
|
106
|
-
newDestinationChildren.push(itemRemoved);
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
newDestinationChildren.splice(to.index, 0, itemRemoved);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return mutateTree(treeWithoutSource, to.parentId, {
|
|
113
|
-
children: newDestinationChildren,
|
|
114
|
-
hasChildren: true,
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
export { normalizeMenu, formatMenu, formatItem, customMoveItemOnTree };
|
|
92
|
+
export { normalizeMenu, formatMenu, formatItem };
|
|
@@ -9,6 +9,7 @@ import Tree, {
|
|
|
9
9
|
ItemId,
|
|
10
10
|
TreeSourcePosition,
|
|
11
11
|
TreeDestinationPosition,
|
|
12
|
+
moveItemOnTree,
|
|
12
13
|
} from "@atlaskit/tree";
|
|
13
14
|
|
|
14
15
|
import { menuActions } from "@ax/containers/Navigation";
|
|
@@ -17,7 +18,7 @@ import { Loading, ErrorToast, IconAction } from "@ax/components";
|
|
|
17
18
|
import { RouteLeavingGuard } from "@ax/guards";
|
|
18
19
|
import { IMenuItem, IRootState } from "@ax/types";
|
|
19
20
|
|
|
20
|
-
import {
|
|
21
|
+
import { formatItem, formatMenu, normalizeMenu } from "./helpers";
|
|
21
22
|
import Header from "./Header";
|
|
22
23
|
import Item from "./Item";
|
|
23
24
|
import * as S from "./style";
|
|
@@ -25,6 +26,7 @@ import * as S from "./style";
|
|
|
25
26
|
const ItemList = (props: IItemList): JSX.Element => {
|
|
26
27
|
const { menu, reorderMenu } = props;
|
|
27
28
|
const [tree, setTree] = useState<TreeData>({ rootId: "root", items: {} });
|
|
29
|
+
const [itemDragging, setItemDragging] = useState<ItemId | null>(null);
|
|
28
30
|
|
|
29
31
|
useEffect(() => {
|
|
30
32
|
setTree(normalizeMenu(menu, tree));
|
|
@@ -54,6 +56,7 @@ const ItemList = (props: IItemList): JSX.Element => {
|
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
const renderItem = ({ item, onExpand, onCollapse, provided, depth }: RenderItemParams) => {
|
|
59
|
+
const isDragging = !!itemDragging && itemDragging !== item.id;
|
|
57
60
|
return (
|
|
58
61
|
<S.Draggable ref={provided.innerRef} {...provided.draggableProps}>
|
|
59
62
|
<Item
|
|
@@ -61,6 +64,7 @@ const ItemList = (props: IItemList): JSX.Element => {
|
|
|
61
64
|
icon={getIcon(item, onExpand, onCollapse)}
|
|
62
65
|
dragHandleProps={provided.dragHandleProps}
|
|
63
66
|
depth={depth}
|
|
67
|
+
isDragging={isDragging}
|
|
64
68
|
/>
|
|
65
69
|
</S.Draggable>
|
|
66
70
|
);
|
|
@@ -80,15 +84,21 @@ const ItemList = (props: IItemList): JSX.Element => {
|
|
|
80
84
|
reorderMenu(newMenu);
|
|
81
85
|
};
|
|
82
86
|
|
|
87
|
+
const onDragStart = (item: ItemId) => setItemDragging(item);
|
|
88
|
+
|
|
83
89
|
const onDragEnd = (source: TreeSourcePosition, destination?: TreeDestinationPosition) => {
|
|
84
|
-
if (!destination || (source.parentId === destination.parentId && source.index === destination.index))
|
|
90
|
+
if (!destination || (source.parentId === destination.parentId && source.index === destination.index)) {
|
|
91
|
+
setItemDragging(null);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
85
94
|
|
|
86
|
-
const newTree =
|
|
95
|
+
const newTree = moveItemOnTree(tree, source, destination);
|
|
87
96
|
const { parentId } = destination;
|
|
88
97
|
newTree.items[parentId].isExpanded = true;
|
|
89
98
|
setTree(newTree);
|
|
90
99
|
const newMenu = formatMenu(newTree);
|
|
91
100
|
reorderMenu(newMenu);
|
|
101
|
+
setItemDragging(null);
|
|
92
102
|
};
|
|
93
103
|
|
|
94
104
|
return (
|
|
@@ -98,6 +108,7 @@ const ItemList = (props: IItemList): JSX.Element => {
|
|
|
98
108
|
renderItem={renderItem}
|
|
99
109
|
onExpand={onExpand}
|
|
100
110
|
onCollapse={onCollapse}
|
|
111
|
+
onDragStart={onDragStart}
|
|
101
112
|
onDragEnd={onDragEnd}
|
|
102
113
|
isDragEnabled
|
|
103
114
|
isNestingEnabled
|
package/src/types/index.tsx
CHANGED
|
@@ -382,9 +382,9 @@ export interface IMenuItem {
|
|
|
382
382
|
name: string;
|
|
383
383
|
editorID?: number;
|
|
384
384
|
label: string;
|
|
385
|
-
url:
|
|
385
|
+
url: string;
|
|
386
386
|
auxText: string;
|
|
387
|
-
children:
|
|
387
|
+
children: IMenuItem[];
|
|
388
388
|
image?: IImage | string | null;
|
|
389
389
|
isExpanded?: boolean;
|
|
390
390
|
config: IMenuItemConfig | null;
|