@cellaware/utils 8.6.8 → 8.6.10
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/dist/chatwms/datagrid.d.ts +2 -1
- package/dist/chatwms/datagrid.js +169 -12
- package/package.json +1 -1
|
@@ -148,9 +148,10 @@ interface TeamsColumnStyle {
|
|
|
148
148
|
}
|
|
149
149
|
export declare function mapTeamsStyles(columnNames: string[], htmlRowStyles: string[], htmlColumnStyles: HtmlColumnStyle[], teamsRowStyles: string[], teamsColumnStyles: TeamsColumnStyle[]): [string[], TeamsColumnStyle[]];
|
|
150
150
|
/**
|
|
151
|
-
* **Important:** `html` and `teamsRows` output will be limited to **
|
|
151
|
+
* **Important:** `html` and `teamsRows` output will be limited to **1,000 rows/64 rows** and **8 columns**, respectively.
|
|
152
152
|
*
|
|
153
153
|
* All outputs respect and will be filtered by optional `condition` argument.
|
|
154
154
|
*/
|
|
155
|
+
export declare function _transformDatagrid(rows: any[], datagridState: DatagridStateBase, locale: string, condition?: DatagridCondition): VisualDatagridState;
|
|
155
156
|
export declare function transformDatagrid(rows: any[], datagridState: DatagridStateBase, locale: string, condition?: DatagridCondition): VisualDatagridState;
|
|
156
157
|
export {};
|
package/dist/chatwms/datagrid.js
CHANGED
|
@@ -1039,13 +1039,14 @@ function createTeamsTableRow(columnNames, values, rowStyles, columnStyles) {
|
|
|
1039
1039
|
};
|
|
1040
1040
|
}
|
|
1041
1041
|
/**
|
|
1042
|
-
* **Important:** `html` and `teamsRows` output will be limited to **
|
|
1042
|
+
* **Important:** `html` and `teamsRows` output will be limited to **1,000 rows/64 rows** and **8 columns**, respectively.
|
|
1043
1043
|
*
|
|
1044
1044
|
* All outputs respect and will be filtered by optional `condition` argument.
|
|
1045
1045
|
*/
|
|
1046
|
-
export function
|
|
1047
|
-
const HTML_ROWS =
|
|
1046
|
+
export function _transformDatagrid(rows, datagridState, locale, condition) {
|
|
1047
|
+
const HTML_ROWS = 1000;
|
|
1048
1048
|
const HTML_COLS = 8;
|
|
1049
|
+
const TEAMS_ROWS = 64;
|
|
1049
1050
|
const columnState = datagridState.columnState ?? [];
|
|
1050
1051
|
const filterModel = datagridState.filterModel ?? {};
|
|
1051
1052
|
const isPivotMode = !!datagridState.isPivotMode;
|
|
@@ -1065,6 +1066,7 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
|
1065
1066
|
rows = sortModel.length > 0 ? sortRows(rows, sortModel) : rows;
|
|
1066
1067
|
let mappedDisplayColumnNames = new Map();
|
|
1067
1068
|
// Should not need to do hidden/visible column analysis -- pivoting creates new results with only the necessary columns.
|
|
1069
|
+
let rowIdx = 0;
|
|
1068
1070
|
rows.forEach(row => {
|
|
1069
1071
|
columnFormats.forEach(columnFormat => {
|
|
1070
1072
|
if (columnFormat.name in row) {
|
|
@@ -1072,6 +1074,9 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
|
1072
1074
|
if (columnFormat.displayName !== columnFormat.name) { // Remove name in favor of display name.
|
|
1073
1075
|
delete row[columnFormat.name];
|
|
1074
1076
|
}
|
|
1077
|
+
if (rowIdx === 0) {
|
|
1078
|
+
htmlColumnNames.push(columnFormat.displayName);
|
|
1079
|
+
}
|
|
1075
1080
|
}
|
|
1076
1081
|
else {
|
|
1077
1082
|
const mappedColumnNamesSet = pivotOutput.mappedColumnNames.get(columnFormat.name);
|
|
@@ -1092,16 +1097,20 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
|
1092
1097
|
displayColumnNames = new Set([adjDisplayName]);
|
|
1093
1098
|
mappedDisplayColumnNames.set(columnFormat.displayName, displayColumnNames);
|
|
1094
1099
|
}
|
|
1100
|
+
if (rowIdx === 0) {
|
|
1101
|
+
htmlColumnNames.push(columnFormat.displayName);
|
|
1102
|
+
}
|
|
1095
1103
|
}
|
|
1096
1104
|
}
|
|
1097
1105
|
}
|
|
1098
1106
|
}
|
|
1099
1107
|
});
|
|
1108
|
+
rowIdx++;
|
|
1100
1109
|
});
|
|
1101
1110
|
if (!!condition) {
|
|
1102
1111
|
rows = evaluatePivotDatagridCondition(rows, condition, mappedDisplayColumnNames);
|
|
1103
1112
|
}
|
|
1104
|
-
|
|
1113
|
+
rowIdx = 0;
|
|
1105
1114
|
rows.forEach(row => {
|
|
1106
1115
|
let chartRow = {};
|
|
1107
1116
|
let htmlRowValues = [];
|
|
@@ -1116,9 +1125,6 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
|
1116
1125
|
htmlRowValues.push(formattedValue);
|
|
1117
1126
|
[htmlRowStyles, htmlColumnStyles] = processHtmlStyles(formattedValue, columnFormat, htmlRowStyles, htmlColumnStyles);
|
|
1118
1127
|
[teamsRowStyles, teamsColumnStyles] = mapTeamsStyles(htmlColumnNames, htmlRowStyles, htmlColumnStyles, teamsRowStyles, teamsColumnStyles);
|
|
1119
|
-
if (rowIdx === 0) {
|
|
1120
|
-
htmlColumnNames.push(columnFormat.displayName);
|
|
1121
|
-
}
|
|
1122
1128
|
}
|
|
1123
1129
|
else {
|
|
1124
1130
|
const mappedColumnNamesSet = pivotOutput.mappedColumnNames.get(columnFormat.name);
|
|
@@ -1143,7 +1149,9 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
|
1143
1149
|
chartRows.push(chartRow);
|
|
1144
1150
|
if (rowIdx < HTML_ROWS) {
|
|
1145
1151
|
htmlBuf += buildHtmlRow(htmlRowValues, htmlRowStyles, htmlColumnStyles, HTML_COLS);
|
|
1146
|
-
|
|
1152
|
+
if (rowIdx < TEAMS_ROWS) {
|
|
1153
|
+
teamsRows.push(createTeamsTableRow(htmlColumnNames, htmlRowValues, teamsRowStyles, teamsColumnStyles));
|
|
1154
|
+
}
|
|
1147
1155
|
}
|
|
1148
1156
|
rowIdx++;
|
|
1149
1157
|
});
|
|
@@ -1183,14 +1191,13 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
|
1183
1191
|
htmlRowValues.push(formattedValue);
|
|
1184
1192
|
[htmlRowStyles, htmlColumnStyles] = processHtmlStyles(formattedValue, columnFormat, htmlRowStyles, htmlColumnStyles);
|
|
1185
1193
|
[teamsRowStyles, teamsColumnStyles] = mapTeamsStyles(htmlColumnNames, htmlRowStyles, htmlColumnStyles, teamsRowStyles, teamsColumnStyles);
|
|
1186
|
-
if (rowIdx === 0) {
|
|
1187
|
-
htmlColumnNames.push(columnFormat.displayName);
|
|
1188
|
-
}
|
|
1189
1194
|
});
|
|
1190
1195
|
chartRows.push(chartRow);
|
|
1191
1196
|
if (rowIdx < HTML_ROWS) {
|
|
1192
1197
|
htmlBuf += buildHtmlRow(htmlRowValues, htmlRowStyles, htmlColumnStyles, HTML_COLS);
|
|
1193
|
-
|
|
1198
|
+
if (rowIdx < TEAMS_ROWS) {
|
|
1199
|
+
teamsRows.push(createTeamsTableRow(htmlColumnNames, htmlRowValues, teamsRowStyles, teamsColumnStyles));
|
|
1200
|
+
}
|
|
1194
1201
|
}
|
|
1195
1202
|
rowIdx++;
|
|
1196
1203
|
});
|
|
@@ -1206,3 +1213,153 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
|
1206
1213
|
]
|
|
1207
1214
|
};
|
|
1208
1215
|
}
|
|
1216
|
+
export function transformDatagrid(rows, datagridState, locale, condition) {
|
|
1217
|
+
const HTML_ROWS = 1000;
|
|
1218
|
+
const HTML_COLS = 8;
|
|
1219
|
+
const TEAMS_ROWS = 64;
|
|
1220
|
+
const columnState = datagridState.columnState ?? [];
|
|
1221
|
+
const filterModel = datagridState.filterModel ?? {};
|
|
1222
|
+
const isPivotMode = !!datagridState.isPivotMode;
|
|
1223
|
+
const columnFormats = datagridState.columnFormats ?? [];
|
|
1224
|
+
const { rowGroupCols, pivotCols, valueCols, sortModel } = parseColumnState(columnState);
|
|
1225
|
+
rows = filterRows(rows, filterModel);
|
|
1226
|
+
const chartRows = [];
|
|
1227
|
+
let htmlBuf = '';
|
|
1228
|
+
const htmlColumnNames = [];
|
|
1229
|
+
const teamsRows = [];
|
|
1230
|
+
// IMPORTANT: we evaluate the datagrid condition AFTER we are done with all transformations.
|
|
1231
|
+
// NOTE: we do not need any pivot columns for pivot mode to be valid.
|
|
1232
|
+
// https://chatwms.io/user-manual/chatwms/faq#q-do-i-have-to-have-a-group-column-to-just-display-a-count-in-the-datagrid
|
|
1233
|
+
if (isPivotMode && valueCols.length > 0) {
|
|
1234
|
+
const pivotOutput = pivotData(rows, rowGroupCols, pivotCols, valueCols);
|
|
1235
|
+
rows = pivotOutput.rows;
|
|
1236
|
+
rows = sortModel.length > 0 ? sortRows(rows, sortModel) : rows;
|
|
1237
|
+
let mappedDisplayColumnNames = new Map();
|
|
1238
|
+
// Should not need to do hidden/visible column analysis -- pivoting creates new results with only the necessary columns.
|
|
1239
|
+
let rowIdx = 0;
|
|
1240
|
+
rows.forEach(row => {
|
|
1241
|
+
let chartRow = {};
|
|
1242
|
+
let htmlRowValues = [];
|
|
1243
|
+
let htmlRowStyles = [];
|
|
1244
|
+
let htmlColumnStyles = [];
|
|
1245
|
+
let teamsRowStyles = [];
|
|
1246
|
+
let teamsColumnStyles = [];
|
|
1247
|
+
columnFormats.forEach(columnFormat => {
|
|
1248
|
+
if (columnFormat.name in row) {
|
|
1249
|
+
const value = row[columnFormat.name];
|
|
1250
|
+
const formattedValue = evaluateValueFormat(columnFormat, value, locale);
|
|
1251
|
+
row[columnFormat.displayName] = formattedValue;
|
|
1252
|
+
chartRow[columnFormat.displayName] = formatNumberEnabled(columnFormat.valueFormat) ? value : formattedValue;
|
|
1253
|
+
htmlRowValues.push(formattedValue);
|
|
1254
|
+
[htmlRowStyles, htmlColumnStyles] = processHtmlStyles(formattedValue, columnFormat, htmlRowStyles, htmlColumnStyles);
|
|
1255
|
+
[teamsRowStyles, teamsColumnStyles] = mapTeamsStyles(htmlColumnNames, htmlRowStyles, htmlColumnStyles, teamsRowStyles, teamsColumnStyles);
|
|
1256
|
+
if (rowIdx === 0) {
|
|
1257
|
+
htmlColumnNames.push(columnFormat.displayName);
|
|
1258
|
+
}
|
|
1259
|
+
// Remove name in favor of display name.
|
|
1260
|
+
if (columnFormat.displayName !== columnFormat.name) {
|
|
1261
|
+
delete row[columnFormat.name];
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1264
|
+
else {
|
|
1265
|
+
const mappedColumnNamesSet = pivotOutput.mappedColumnNames.get(columnFormat.name);
|
|
1266
|
+
if (!!mappedColumnNamesSet) {
|
|
1267
|
+
const mappedColumnNamesArr = Array.from(mappedColumnNamesSet);
|
|
1268
|
+
for (const mappedColumnName of mappedColumnNamesArr) {
|
|
1269
|
+
if (mappedColumnName in row) {
|
|
1270
|
+
const adjDisplayName = mappedColumnName.replace(columnFormat.name, columnFormat.displayName);
|
|
1271
|
+
const value = row[mappedColumnName];
|
|
1272
|
+
const formattedValue = evaluateValueFormat(columnFormat, value, locale);
|
|
1273
|
+
row[adjDisplayName] = formattedValue;
|
|
1274
|
+
chartRow[adjDisplayName] = formatNumberEnabled(columnFormat.valueFormat) ? value : formattedValue;
|
|
1275
|
+
htmlRowValues.push(formattedValue);
|
|
1276
|
+
[htmlRowStyles, htmlColumnStyles] = processHtmlStyles(formattedValue, columnFormat, htmlRowStyles, htmlColumnStyles);
|
|
1277
|
+
[teamsRowStyles, teamsColumnStyles] = mapTeamsStyles(htmlColumnNames, htmlRowStyles, htmlColumnStyles, teamsRowStyles, teamsColumnStyles);
|
|
1278
|
+
if (rowIdx === 0) {
|
|
1279
|
+
htmlColumnNames.push(columnFormat.displayName);
|
|
1280
|
+
}
|
|
1281
|
+
// Remove name in favor of display name.
|
|
1282
|
+
if (adjDisplayName !== mappedColumnName) {
|
|
1283
|
+
delete row[mappedColumnName];
|
|
1284
|
+
}
|
|
1285
|
+
let displayColumnNames = mappedDisplayColumnNames.get(columnFormat.displayName);
|
|
1286
|
+
if (!!displayColumnNames) {
|
|
1287
|
+
displayColumnNames.add(adjDisplayName);
|
|
1288
|
+
}
|
|
1289
|
+
else {
|
|
1290
|
+
displayColumnNames = new Set([adjDisplayName]);
|
|
1291
|
+
mappedDisplayColumnNames.set(columnFormat.displayName, displayColumnNames);
|
|
1292
|
+
}
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
}
|
|
1297
|
+
});
|
|
1298
|
+
chartRows.push(chartRow);
|
|
1299
|
+
if (rowIdx < HTML_ROWS) {
|
|
1300
|
+
htmlBuf += buildHtmlRow(htmlRowValues, htmlRowStyles, htmlColumnStyles, HTML_COLS);
|
|
1301
|
+
if (rowIdx < TEAMS_ROWS) {
|
|
1302
|
+
teamsRows.push(createTeamsTableRow(htmlColumnNames, htmlRowValues, teamsRowStyles, teamsColumnStyles));
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
rowIdx++;
|
|
1306
|
+
});
|
|
1307
|
+
if (!!condition) {
|
|
1308
|
+
rows = evaluatePivotDatagridCondition(rows, condition, mappedDisplayColumnNames);
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
else {
|
|
1312
|
+
if (rowGroupCols.length > 0) {
|
|
1313
|
+
rows = groupAndAggregate(rows, rowGroupCols, [], valueCols);
|
|
1314
|
+
}
|
|
1315
|
+
rows = sortModel.length > 0 ? sortRows(rows, sortModel) : rows;
|
|
1316
|
+
const hiddenColumnNames = columnState.filter(column => !!column.hide && !column.rowGroup).map(column => column.colId) ?? [];
|
|
1317
|
+
const visibleColumnFormats = columnFormats.filter(column => !hiddenColumnNames.includes(column.name)) ?? [];
|
|
1318
|
+
let rowIdx = 0;
|
|
1319
|
+
rows.forEach(row => {
|
|
1320
|
+
let chartRow = {};
|
|
1321
|
+
let htmlRowValues = [];
|
|
1322
|
+
let htmlRowStyles = [];
|
|
1323
|
+
let htmlColumnStyles = [];
|
|
1324
|
+
let teamsRowStyles = [];
|
|
1325
|
+
let teamsColumnStyles = [];
|
|
1326
|
+
hiddenColumnNames.forEach(columnName => {
|
|
1327
|
+
delete row[columnName];
|
|
1328
|
+
});
|
|
1329
|
+
visibleColumnFormats.forEach(columnFormat => {
|
|
1330
|
+
const value = row[columnFormat.name];
|
|
1331
|
+
const formattedValue = evaluateValueFormat(columnFormat, value, locale);
|
|
1332
|
+
row[columnFormat.displayName] = formattedValue;
|
|
1333
|
+
chartRow[columnFormat.displayName] = formatNumberEnabled(columnFormat.valueFormat) ? value : formattedValue;
|
|
1334
|
+
htmlRowValues.push(formattedValue);
|
|
1335
|
+
[htmlRowStyles, htmlColumnStyles] = processHtmlStyles(formattedValue, columnFormat, htmlRowStyles, htmlColumnStyles);
|
|
1336
|
+
[teamsRowStyles, teamsColumnStyles] = mapTeamsStyles(htmlColumnNames, htmlRowStyles, htmlColumnStyles, teamsRowStyles, teamsColumnStyles);
|
|
1337
|
+
if (rowIdx === 0) {
|
|
1338
|
+
htmlColumnNames.push(columnFormat.displayName);
|
|
1339
|
+
}
|
|
1340
|
+
// Remove name in favor of display name.
|
|
1341
|
+
if (columnFormat.displayName !== columnFormat.name) {
|
|
1342
|
+
delete row[columnFormat.name];
|
|
1343
|
+
}
|
|
1344
|
+
});
|
|
1345
|
+
chartRows.push(chartRow);
|
|
1346
|
+
if (rowIdx < HTML_ROWS) {
|
|
1347
|
+
htmlBuf += buildHtmlRow(htmlRowValues, htmlRowStyles, htmlColumnStyles, HTML_COLS);
|
|
1348
|
+
if (rowIdx < TEAMS_ROWS) {
|
|
1349
|
+
teamsRows.push(createTeamsTableRow(htmlColumnNames, htmlRowValues, teamsRowStyles, teamsColumnStyles));
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
rowIdx++;
|
|
1353
|
+
});
|
|
1354
|
+
if (!!condition) {
|
|
1355
|
+
rows = evaluateDatagridCondition(rows, condition);
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
return {
|
|
1359
|
+
...datagridState,
|
|
1360
|
+
adjRows: rows,
|
|
1361
|
+
chartRows,
|
|
1362
|
+
html: `${buildHtmlTableHeader(htmlColumnNames.slice(0, HTML_COLS))}${htmlBuf}${buildHtmlTableFooter()}`,
|
|
1363
|
+
teamsRows
|
|
1364
|
+
};
|
|
1365
|
+
}
|