MCPcopy Create free account
hub / github.com/pywebio/PyWebIO / row_data_and_column_def

Function row_data_and_column_def

webiojs/src/models/datatable.ts:78–150  ·  view source on GitHub ↗
(
    data: any[],
    field_args: { [field: string]: any },
    path_args: any[][],
    column_order: { [field: string]: any },
)

Source from the content-addressed store, hash-verified

76* path_args: [(path, column_def), ...]
77* */
78function row_data_and_column_def(
79 data: any[],
80 field_args: { [field: string]: any },
81 path_args: any[][],
82 column_order: { [field: string]: any },
83) {
84 function capitalizeFirstLetter(s: string) {
85 return s.charAt(0).toUpperCase() + s.slice(1);
86 }
87
88
89 function gen_columns_def(
90 current_columns: { [field: string]: any }, // all leaf node is {}
91 path: string[],
92 field_args: { [field: string]: any },
93 path_field_args: { [field: string]: any },
94 args_from_parent: { [field: string]: any }
95 ) {
96 let column_def: any[] = [];
97 Object.keys(current_columns).forEach((key) => {
98 let val = current_columns[key];
99 path.push(key);
100 let path_field = path2field(path);
101 if (Object.keys(val).length > 0) {
102 let extra_args = {
103 ...args_from_parent,
104 ...(path_field_args[path_field] || {}),
105 };
106 column_def.push({
107 headerName: capitalizeFirstLetter(key.replace(/_/g, " ")),
108 children: gen_columns_def(val, path, field_args, path_field_args, extra_args)
109 });
110 } else {
111 let column = {
112 headerName: capitalizeFirstLetter(key.replace(/_/g, " ")),
113 field: path_field,
114 ...args_from_parent,
115 ...(field_args[key] || {}),
116 ...(path_field_args[path_field] || {}),
117 };
118 column_def.push(column);
119 }
120 path.pop();
121 })
122 return column_def;
123 }
124
125 let columns = {};
126 let rows = [];
127 for (let row of data) {
128 let row_data = {};
129 flatten_row_and_extract_column(row, columns, row_data, []);
130 rows.push(row_data);
131 }
132 let path_field_args: { [field: string]: any } = {};
133 path_args.map(([path, column_def]) => {
134 path_field_args[path2field(path)] = column_def
135 })

Callers 1

datatable.tsFile · 0.85

Calls 4

path2fieldFunction · 0.85
gen_columns_defFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…