Skip to content

Commit 99bbd96

Browse files
Merge pull request #4 from lowcoder-org/kanban-refactor
Kanban refactoring - replace ej2-kanban component with dndkit
2 parents 9b819b2 + 6f8440d commit 99bbd96

14 files changed

+1184
-138704
lines changed
28.5 KB
Binary file not shown.
Binary file not shown.

lowcoder-comp-kanban/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
"type": "module",
55
"license": "MIT",
66
"dependencies": {
7+
"@dnd-kit/core": "^6.2.0",
8+
"@dnd-kit/sortable": "^9.0.0",
9+
"@dnd-kit/utilities": "^3.2.2",
710
"@observablehq/runtime": "^5.9.8",
8-
"@syncfusion/ej2-base": "^25.2.7",
9-
"@syncfusion/ej2-kanban": "^26.1.40",
10-
"@syncfusion/ej2-material3-theme": "^26.1.35",
11-
"@syncfusion/ej2-react-kanban": "^25.2.6",
1211
"@types/lodash.differenceby": "^4.8.9",
1312
"@types/lodash.filter": "^4.6.9",
1413
"@types/lodash.includes": "^4.3.9",
@@ -18,6 +17,7 @@
1817
"@types/react-dom": "18",
1918
"antd": "^5.19.1",
2019
"bootstrap": "^5.3.3",
20+
"immutability-helper": "^3.1.1",
2121
"lodash.differenceby": "^4.8.0",
2222
"lodash.differencewith": "^4.5.0",
2323
"lodash.filter": "^4.6.0",

lowcoder-comp-kanban/src/KabanComp.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ import {
99
withMethodExposing,
1010
CompAction,
1111
CompDepsConfig,
12+
CompActionTypes,
1213
} from 'lowcoder-sdk';
1314
import { trans } from "./i18n/comps";
1415
import { KanbanInitComp } from './kanbanTypes';
1516
import { KanbanPropertyView } from './kanbanPropertyView';
1617
import { KanbanCompView } from './kanbanCompView';
1718
import * as datasource from './datasource.json';
19+
import isEqual from 'lodash.isequal';
1820

1921
type IContainer = typeof IContainer;
2022
type NameGenerator = typeof NameGenerator;
@@ -50,20 +52,39 @@ export class KanbanImplComp extends KanbanInitComp implements IContainer {
5052

5153
override reduce(action: CompAction): this {
5254
let comp = super.reduce(action);
53-
const params = comp.children.cardView.children.cardView.getCachedParams('0');
54-
if (!Boolean(params)) {
55+
56+
let dataChanged = false;
57+
if (action.type === CompActionTypes.UPDATE_NODES_V2) {
58+
dataChanged =
59+
comp.children.data !== this.children.data &&
60+
isEqual(this.children.data.getView(), comp.children.data.getView());
61+
}
62+
63+
const thisSelection = this.children.activeCardIndex.getView() ?? "0";
64+
const newSelection = comp.children.activeCardIndex.getView() ?? "0";
65+
const selectionChanged = thisSelection !== newSelection;
66+
let params = comp.children.cardView.children.cardView.getCachedParams(newSelection);
67+
if (selectionChanged || !Boolean(params) || dataChanged) {
68+
params = !Boolean(params) || dataChanged
69+
? {
70+
currentRow: comp.children.data.getView()[newSelection],
71+
currentIndex: newSelection,
72+
currentOriginalIndex: newSelection,
73+
} : undefined;
5574
comp = comp.setChild(
5675
"cardView",
5776
comp.children.cardView.reduce(
58-
comp.children.cardView.setSelectionAction('0', params)
77+
comp.children.cardView.setSelectionAction(newSelection, params)
5978
)
6079
);
6180
}
6281
return comp;
6382
}
6483
}
6584

66-
const KanbanRenderComp = withViewFn(KanbanImplComp, (comp: KanbanImplComp) => <KanbanCompView comp={comp} />);
85+
const KanbanRenderComp = withViewFn(KanbanImplComp, (comp: KanbanImplComp) => {
86+
return <KanbanCompView comp={comp} />
87+
});
6788
let KanbanPropertyComp = withPropertyViewFn(KanbanRenderComp, (comp: KanbanImplComp) => {
6889
return <KanbanPropertyView comp={comp} />;
6990
});

lowcoder-comp-kanban/src/cardViewControl.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ const CardView = React.memo((props: { containerProps: ConstructorToView<typeof S
4848
// containerPadding={[2, 2]}
4949
/>
5050
);
51-
}, (prev, next) => JSON.stringify(prev.containerProps) === JSON.stringify(next.containerProps));
51+
// }, (prev, next) => JSON.stringify(prev.containerProps) === JSON.stringify(next.containerProps));
52+
});
5253

5354
const cardTemplate = (props: {
5455
data: Record<string, string>,

0 commit comments

Comments
 (0)