@cellaware/utils 8.6.7 → 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.
@@ -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 **200 rows** and **8 columns**.
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 {};
@@ -998,6 +998,7 @@ function createTeamsTableCellText(value, columnStyle) {
998
998
  isSubtle = styles.isSubtle;
999
999
  }
1000
1000
  }
1001
+ console.log('HERE: ' + columnStyle);
1001
1002
  return {
1002
1003
  type: "TextBlock",
1003
1004
  text: italic ? `*${value}*` : value,
@@ -1010,17 +1011,19 @@ function createTeamsTableCellText(value, columnStyle) {
1010
1011
  isSubtle
1011
1012
  };
1012
1013
  }
1013
- function createTeamsTableRow(columnNames, values, oddRow, rowStyles, columnStyles) {
1014
+ function createTeamsTableRow(columnNames, values, rowStyles, columnStyles) {
1014
1015
  let rowStyle = undefined;
1015
1016
  for (const style of rowStyles) {
1016
1017
  rowStyle = style;
1018
+ console.log(style);
1017
1019
  }
1018
1020
  return {
1019
1021
  type: "TableRow",
1020
- ...(rowStyle ? { style: rowStyle } : (oddRow ? { style: "emphasis" } : {})),
1022
+ style: rowStyle,
1021
1023
  cells: values.map((value, idx) => {
1022
1024
  const columnName = columnNames[idx];
1023
1025
  const columnStyle = columnStyles.find(columnStyle => columnStyle.columnName === columnName);
1026
+ console.log(columnStyle);
1024
1027
  let style = undefined;
1025
1028
  for (const styles of columnStyle?.styles ?? []) {
1026
1029
  if (!!styles.style) {
@@ -1036,13 +1039,14 @@ function createTeamsTableRow(columnNames, values, oddRow, rowStyles, columnStyle
1036
1039
  };
1037
1040
  }
1038
1041
  /**
1039
- * **Important:** `html` and `teamsRows` output will be limited to **200 rows** and **8 columns**.
1042
+ * **Important:** `html` and `teamsRows` output will be limited to **1,000 rows/64 rows** and **8 columns**, respectively.
1040
1043
  *
1041
1044
  * All outputs respect and will be filtered by optional `condition` argument.
1042
1045
  */
1043
- export function transformDatagrid(rows, datagridState, locale, condition) {
1044
- const HTML_ROWS = 200;
1046
+ export function _transformDatagrid(rows, datagridState, locale, condition) {
1047
+ const HTML_ROWS = 1000;
1045
1048
  const HTML_COLS = 8;
1049
+ const TEAMS_ROWS = 64;
1046
1050
  const columnState = datagridState.columnState ?? [];
1047
1051
  const filterModel = datagridState.filterModel ?? {};
1048
1052
  const isPivotMode = !!datagridState.isPivotMode;
@@ -1062,6 +1066,7 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
1062
1066
  rows = sortModel.length > 0 ? sortRows(rows, sortModel) : rows;
1063
1067
  let mappedDisplayColumnNames = new Map();
1064
1068
  // Should not need to do hidden/visible column analysis -- pivoting creates new results with only the necessary columns.
1069
+ let rowIdx = 0;
1065
1070
  rows.forEach(row => {
1066
1071
  columnFormats.forEach(columnFormat => {
1067
1072
  if (columnFormat.name in row) {
@@ -1069,6 +1074,9 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
1069
1074
  if (columnFormat.displayName !== columnFormat.name) { // Remove name in favor of display name.
1070
1075
  delete row[columnFormat.name];
1071
1076
  }
1077
+ if (rowIdx === 0) {
1078
+ htmlColumnNames.push(columnFormat.displayName);
1079
+ }
1072
1080
  }
1073
1081
  else {
1074
1082
  const mappedColumnNamesSet = pivotOutput.mappedColumnNames.get(columnFormat.name);
@@ -1089,16 +1097,20 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
1089
1097
  displayColumnNames = new Set([adjDisplayName]);
1090
1098
  mappedDisplayColumnNames.set(columnFormat.displayName, displayColumnNames);
1091
1099
  }
1100
+ if (rowIdx === 0) {
1101
+ htmlColumnNames.push(columnFormat.displayName);
1102
+ }
1092
1103
  }
1093
1104
  }
1094
1105
  }
1095
1106
  }
1096
1107
  });
1108
+ rowIdx++;
1097
1109
  });
1098
1110
  if (!!condition) {
1099
1111
  rows = evaluatePivotDatagridCondition(rows, condition, mappedDisplayColumnNames);
1100
1112
  }
1101
- let rowIdx = 0;
1113
+ rowIdx = 0;
1102
1114
  rows.forEach(row => {
1103
1115
  let chartRow = {};
1104
1116
  let htmlRowValues = [];
@@ -1113,9 +1125,6 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
1113
1125
  htmlRowValues.push(formattedValue);
1114
1126
  [htmlRowStyles, htmlColumnStyles] = processHtmlStyles(formattedValue, columnFormat, htmlRowStyles, htmlColumnStyles);
1115
1127
  [teamsRowStyles, teamsColumnStyles] = mapTeamsStyles(htmlColumnNames, htmlRowStyles, htmlColumnStyles, teamsRowStyles, teamsColumnStyles);
1116
- if (rowIdx === 0) {
1117
- htmlColumnNames.push(columnFormat.displayName);
1118
- }
1119
1128
  }
1120
1129
  else {
1121
1130
  const mappedColumnNamesSet = pivotOutput.mappedColumnNames.get(columnFormat.name);
@@ -1140,7 +1149,9 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
1140
1149
  chartRows.push(chartRow);
1141
1150
  if (rowIdx < HTML_ROWS) {
1142
1151
  htmlBuf += buildHtmlRow(htmlRowValues, htmlRowStyles, htmlColumnStyles, HTML_COLS);
1143
- teamsRows.push(createTeamsTableRow(htmlColumnNames, htmlRowValues, rowIdx % 2 === 1, teamsRowStyles, teamsColumnStyles));
1152
+ if (rowIdx < TEAMS_ROWS) {
1153
+ teamsRows.push(createTeamsTableRow(htmlColumnNames, htmlRowValues, teamsRowStyles, teamsColumnStyles));
1154
+ }
1144
1155
  }
1145
1156
  rowIdx++;
1146
1157
  });
@@ -1180,14 +1191,13 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
1180
1191
  htmlRowValues.push(formattedValue);
1181
1192
  [htmlRowStyles, htmlColumnStyles] = processHtmlStyles(formattedValue, columnFormat, htmlRowStyles, htmlColumnStyles);
1182
1193
  [teamsRowStyles, teamsColumnStyles] = mapTeamsStyles(htmlColumnNames, htmlRowStyles, htmlColumnStyles, teamsRowStyles, teamsColumnStyles);
1183
- if (rowIdx === 0) {
1184
- htmlColumnNames.push(columnFormat.displayName);
1185
- }
1186
1194
  });
1187
1195
  chartRows.push(chartRow);
1188
1196
  if (rowIdx < HTML_ROWS) {
1189
1197
  htmlBuf += buildHtmlRow(htmlRowValues, htmlRowStyles, htmlColumnStyles, HTML_COLS);
1190
- teamsRows.push(createTeamsTableRow(htmlColumnNames, htmlRowValues, rowIdx % 2 === 1, teamsRowStyles, teamsColumnStyles));
1198
+ if (rowIdx < TEAMS_ROWS) {
1199
+ teamsRows.push(createTeamsTableRow(htmlColumnNames, htmlRowValues, teamsRowStyles, teamsColumnStyles));
1200
+ }
1191
1201
  }
1192
1202
  rowIdx++;
1193
1203
  });
@@ -1203,3 +1213,153 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
1203
1213
  ]
1204
1214
  };
1205
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cellaware/utils",
3
- "version": "8.6.7",
3
+ "version": "8.6.10",
4
4
  "description": "Cellaware Utilities for Node.js",
5
5
  "author": "Cellaware Technologies",
6
6
  "type": "module",