Skip to content

Commit 88fd633

Browse files
optimize card view control
1 parent 3b1638f commit 88fd633

File tree

5 files changed

+40
-24
lines changed

5 files changed

+40
-24
lines changed

lowcoder-comp-kanban/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"antd": "^5.19.1",
1616
"bootstrap": "^5.3.3",
1717
"lowcoder-cli": "^0.0.30",
18-
"lowcoder-sdk": "^2.4.12",
18+
"lowcoder-sdk": "^2.4.13",
1919
"prop-types": "^15.8.1",
2020
"react": "18",
2121
"react-bootstrap": "^2.10.2",

lowcoder-comp-kanban/src/cardViewControl.tsx

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
RecordType,
1717
NameGenerator,
1818
JSONValue,
19+
CompActionTypes,
1920
} from "lowcoder-sdk";
2021
import React from "react";
2122

@@ -28,7 +29,8 @@ type JSONValue = typeof JSONValue;
2829
const ContextSlotControl = withSelectedMultiContext(SlotControl);
2930

3031
const ContainerView = React.memo((props: ContainerBaseProps) => {
31-
return <InnerGrid {...props} emptyRows={15} autoHeight />;
32+
console.log('card grid -> ', props);
33+
return <InnerGrid {...props} emptyRows={8} autoHeight />;
3234
});
3335

3436
const CardView = React.memo((props: { containerProps: ConstructorToView<typeof SimpleContainerComp> }) => {
@@ -47,13 +49,28 @@ const CardView = React.memo((props: { containerProps: ConstructorToView<typeof S
4749
// containerPadding={[2, 2]}
4850
/>
4951
);
50-
});
52+
}, (prev, next) => JSON.stringify(prev.containerProps) === JSON.stringify(next.containerProps));
53+
54+
const cardTemplate = (props: {
55+
data: Record<string, string>,
56+
index: number,
57+
cardView: any,
58+
}) => {
59+
const slotControl = props.cardView.getView()(
60+
{
61+
currentRow: props.data,
62+
currentIndex: props.index,
63+
currentOriginalIndex: props.index,
64+
},
65+
String(props.index)
66+
);
67+
const containerProps = slotControl.children.container.getView();
68+
return <CardView key={`view-${props.index}`} containerProps={containerProps} />
69+
};
5170

5271
let CardViewControlTmp = (function () {
53-
// const label = trans("table.expandable");
5472
return new ControlItemCompBuilder(
5573
{
56-
// expandable: BoolControl,
5774
cardView: ContextSlotControl,
5875
},
5976
() => ({ cardViewConfig: {}, cardModalView: null })
@@ -65,7 +82,7 @@ let CardViewControlTmp = (function () {
6582
{children.cardView
6683
.getSelectedComp()
6784
.getComp()
68-
.propertyView({ buttonText: "Customize" })
85+
.propertyView({ buttonText: "Customize Card View" })
6986
}
7087
</>
7188
);
@@ -78,16 +95,12 @@ export class CardViewControl extends CardViewControlTmp {
7895
const selectedContainer = this.children.cardView.getSelectedComp();
7996
return {
8097
cardTemplate: (data: Record<string, string>, index: number) => {
81-
const slotControl = this.children.cardView.getView()(
82-
{
83-
currentRow: data,
84-
currentIndex: index,
85-
currentOriginalIndex: index,
86-
},
87-
String(index)
88-
);
89-
const containerProps = slotControl.children.container.getView();
90-
return <CardView key={index} containerProps={containerProps} />;
98+
const cardView = this.children.cardView;
99+
return cardTemplate({
100+
data,
101+
index,
102+
cardView,
103+
});
91104
},
92105
cardModalView: selectedContainer.getView(),
93106
};
@@ -105,6 +118,8 @@ export class CardViewControl extends CardViewControlTmp {
105118
}
106119

107120
reduce(action: any) {
121+
if (action.type === CompActionTypes.CHANGE_VALUE && action.path[action.path.length - 1] === 'positionParams') return this;
122+
108123
const comp = super.reduce(action);
109124
// console.info("CardViewControl reduce. action: ", action, "\nthis: ", this, "\ncomp: ", comp);
110125
return comp;

lowcoder-comp-kanban/src/datasource.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"cardData": [
33
{
4-
"id": "Task 1",
4+
"id": 0,
55
"label": "Task - 29001",
66
"status": "Open",
77
"summary": "Analyze customer requirements.",
@@ -11,7 +11,7 @@
1111
"assignee": "Nancy Davloio"
1212
},
1313
{
14-
"id": "Task 2",
14+
"id": 1,
1515
"label": "Task - 29002",
1616
"status": "InProgress",
1717
"summary": "Add responsive support to applicaton",

lowcoder-comp-kanban/src/kanbanOptionsControl.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let KanbanOption = new MultiCompBuilder(
1818
estimate: NumberControl,
1919
assignee: StringControl,
2020
rankId: NumberControl,
21-
id: StringControl,
21+
id: NumberControl,
2222
},
2323
(props: any) => props
2424
).build();
@@ -89,4 +89,5 @@ KanbanOption = class extends KanbanOption implements OptionCompProperty {
8989
export const KanbanOptionControl = optionsControl(KanbanOption, {
9090
initOptions: dataSource.cardData,
9191
uniqField: "id",
92+
autoIncField: "id",
9293
});

lowcoder-comp-kanban/yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2894,7 +2894,7 @@ __metadata:
28942894
antd: ^5.19.1
28952895
bootstrap: ^5.3.3
28962896
lowcoder-cli: ^0.0.30
2897-
lowcoder-sdk: ^2.4.12
2897+
lowcoder-sdk: ^2.4.13
28982898
prop-types: ^15.8.1
28992899
react: 18
29002900
react-bootstrap: ^2.10.2
@@ -2905,15 +2905,15 @@ __metadata:
29052905
languageName: unknown
29062906
linkType: soft
29072907

2908-
"lowcoder-sdk@npm:^2.4.12":
2909-
version: 2.4.12
2910-
resolution: "lowcoder-sdk@npm:2.4.12"
2908+
"lowcoder-sdk@npm:^2.4.13":
2909+
version: 2.4.13
2910+
resolution: "lowcoder-sdk@npm:2.4.13"
29112911
dependencies:
29122912
prettier: ^3.1.1
29132913
peerDependencies:
29142914
react: ">=18"
29152915
react-dom: ">=18"
2916-
checksum: b4c76fad959ce3d19d9c35bbf8ec15dd22e387f28de2c6f22da3f22c73b7e8cb4e6226247dbbb50dbc32f920ae0b4a9e30ee75230ceb32793c98c719e20c44c8
2916+
checksum: 8687cdcde4b6be46bd798041738f55c0839d992e5551f0ba9d05f6558873cf4b8550424e6a04e755b9437cfb6b845a56cdfc1b83df500d31dd7ac5b241762d63
29172917
languageName: node
29182918
linkType: hard
29192919

0 commit comments

Comments
 (0)