Skip to content

Commit 65aeca5

Browse files
allow table summary row
1 parent 64d5bbd commit 65aeca5

File tree

8 files changed

+1060
-2
lines changed

8 files changed

+1060
-2
lines changed

client/packages/lowcoder/src/comps/comps/avatarGroup.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { clickEvent, eventHandlerControl, refreshEvent } from "../controls/event
1212
import styled from "styled-components";
1313
import { useContext, ReactElement, useEffect } from "react";
1414
import { MultiCompBuilder, stateComp, withDefault } from "../generators";
15-
import { EditorContext } from "comps/editorState";
15+
import { CompNameContext, EditorContext } from "comps/editorState";
1616
import { IconControl } from "../controls/iconControl";
1717
import { ColorControl } from "../controls/colorControl";
1818
import { optionsControl } from "../controls/optionsControl";
@@ -105,6 +105,30 @@ const childrenMap = {
105105
};
106106

107107
const AvatarGroupView = (props: RecordConstructorToView<typeof childrenMap> & { dispatch: (action: CompAction) => void; }) => {
108+
const comp = useContext(EditorContext).getUICompByName(useContext(CompNameContext));
109+
110+
const updateAvatars = () => {
111+
debugger;
112+
if (!comp) return;
113+
// comp?.children.comp.children?.avatars?.children.manual.dispatchChangeValueAction({
114+
// initOptions: [
115+
// { src: "https://api.dicebear.com/7.x/miniavs/svg?seed=1", label: String.fromCharCode(65 + Math.ceil(Math.random() * 25)) },
116+
// // { AvatarIcon: "/icon:antd/startwotone" },
117+
// // { label: String.fromCharCode(65 + Math.ceil(Math.random() * 25)) },
118+
// // { label: String.fromCharCode(65 + Math.ceil(Math.random() * 25)) },
119+
// ],
120+
// });
121+
// comp?.children.comp.children?.avatars.children.manual.children.manual.dispatch([
122+
// { src: "https://api.dicebear.com/7.x/miniavs/svg?seed=1", label: String.fromCharCode(65 + Math.ceil(Math.random() * 25)) }
123+
// ])
124+
comp?.children.comp.children?.avatars.children.manual.children.manual.dispatch(
125+
comp?.children.comp.children?.avatars.children.manual.children.manual.setChildrensAction([
126+
{ src: "https://api.dicebear.com/7.x/miniavs/svg?seed=1", label: String.fromCharCode(65 + Math.ceil(Math.random() * 25)) }
127+
])
128+
);
129+
}
130+
131+
108132
return (
109133
<Container
110134
$style={props.style}
@@ -127,6 +151,7 @@ const AvatarGroupView = (props: RecordConstructorToView<typeof childrenMap> & {
127151
onClick={() => {
128152
props.onEvent("click")
129153
props.dispatch(changeChildAction("currentAvatar", item as JSONObject, false));
154+
updateAvatars();
130155
}}
131156
>
132157
{item.label}

client/packages/lowcoder/src/comps/comps/tableComp/column/tableColumnListComp.tsx

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ import {
1717
import { shallowEqual } from "react-redux";
1818
import { JSONObject, JSONValue } from "util/jsonTypes";
1919
import { lastValueIfEqual } from "util/objectUtils";
20+
import { SummaryColumnComp } from "./tableSummaryColumnComp";
2021

2122
/**
2223
* column list
2324
*/
2425
const ColumnListTmpComp = list(ColumnComp);
26+
const SummaryColumnListTmpComp = list(SummaryColumnComp);
2527

2628
/**
2729
* rowExample is used for code prompts
@@ -190,3 +192,139 @@ export class ColumnListComp extends ColumnListTmpComp {
190192
return this.forEachAction(ColumnComp.setSelectionAction(key));
191193
}
192194
}
195+
196+
export class SummaryColumnListComp extends SummaryColumnListTmpComp {
197+
override reduce(action: CompAction): this {
198+
if (isMyCustomAction<ActionDataType>(action, "dataChanged")) {
199+
const rowExample = action.value.rowExample;
200+
const { readOnly } = getReduceContext();
201+
let comp = this;
202+
if (action.value.doGeneColumn && (action.value.dynamicColumn || !readOnly)) {
203+
const actions = this.geneColumnsAction(rowExample, action.value.data);
204+
comp = this.reduce(this.multiAction(actions));
205+
}
206+
return comp;
207+
}
208+
return super.reduce(action);
209+
}
210+
211+
getChangeSet() {
212+
const changeSet: Record<string, Record<string, JSONValue>> = {};
213+
const columns = this.getView();
214+
columns.forEach((column) => {
215+
const columnChangeSet = column.getChangeSet();
216+
Object.keys(columnChangeSet).forEach((dataIndex) => {
217+
Object.keys(columnChangeSet[dataIndex]).forEach((key) => {
218+
if (!_.isNil(columnChangeSet[dataIndex][key])) {
219+
if (!changeSet[key]) changeSet[key] = {};
220+
changeSet[key][dataIndex] = columnChangeSet[dataIndex][key];
221+
}
222+
});
223+
});
224+
});
225+
return changeSet;
226+
}
227+
228+
dispatchClearChangeSet() {
229+
const columns = this.getView();
230+
columns.forEach((column) => column.dispatchClearChangeSet());
231+
}
232+
233+
/**
234+
* If the table data changes, call this method to trigger the action
235+
*/
236+
dataChangedAction(param: {
237+
rowExample: JSONObject;
238+
doGeneColumn: boolean;
239+
dynamicColumn: boolean;
240+
data: Array<JSONObject>;
241+
}) {
242+
return customAction<ActionDataType>(
243+
{
244+
type: "dataChanged",
245+
...param,
246+
},
247+
true
248+
);
249+
}
250+
251+
/**
252+
* According to the data, adjust the column
253+
*/
254+
private geneColumnsAction(rowExample: RowExampleType, data: Array<JSONObject>) {
255+
// If no data, return directly
256+
if (rowExample === undefined || rowExample === null) {
257+
return [];
258+
}
259+
const dataKeys = Object.keys(rowExample);
260+
if (dataKeys.length === 0) {
261+
return [];
262+
}
263+
const columnsView = this.getView();
264+
const actions: Array<any> = [];
265+
let deleteCnt = 0;
266+
columnsView.forEach((column, index) => {
267+
if (column.getView().isCustom) {
268+
return;
269+
}
270+
const dataIndex = column.getView().dataIndex;
271+
if (dataIndex === COLUMN_CHILDREN_KEY || !dataKeys.find((key) => dataIndex === key)) {
272+
// to Delete
273+
actions.push(this.deleteAction(index - deleteCnt));
274+
deleteCnt += 1;
275+
}
276+
});
277+
// The order should be the same as the data
278+
dataKeys.forEach((key) => {
279+
if (key === COLUMN_CHILDREN_KEY && supportChildrenTree(data)) {
280+
return;
281+
}
282+
if (!columnsView.find((column) => column.getView().dataIndex === key)) {
283+
// to Add
284+
actions.push(this.pushAction(newPrimaryColumn(key, calcColumnWidth(key, data))));
285+
}
286+
});
287+
if (actions.length === 0) {
288+
return [];
289+
}
290+
return actions;
291+
}
292+
293+
withParamsNode() {
294+
const columns = this.getView();
295+
const nodes = _(columns)
296+
.map((col) => col.children.render.getOriginalComp().node())
297+
.toPairs()
298+
.fromPairs()
299+
.value();
300+
const result = lastValueIfEqual(
301+
this,
302+
"withParamsNode",
303+
[fromRecord(nodes), nodes] as const,
304+
(a, b) => shallowEqual(a[1], b[1])
305+
)[0];
306+
return result;
307+
}
308+
309+
getColumnsNode<T extends keyof SummaryColumnComp["children"]>(
310+
field: T
311+
): RecordNode<Record<string, ReturnType<SummaryColumnComp["children"][T]["node"]>>> {
312+
const columns = this.getView();
313+
const nodes = _(columns)
314+
.map((col) => col.children[field].node() as ReturnType<SummaryColumnComp["children"][T]["node"]>)
315+
.toPairs()
316+
.fromPairs()
317+
.value();
318+
const result = lastValueIfEqual(
319+
this,
320+
"col_nodes_" + field,
321+
[fromRecord(nodes), nodes] as const,
322+
(a, b) => shallowEqual(a[1], b[1])
323+
)[0];
324+
return result;
325+
}
326+
327+
setSelectionAction(key: string) {
328+
return this.forEachAction(ColumnComp.setSelectionAction(key));
329+
}
330+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy