@cellaware/utils 8.1.12 → 8.2.1

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.
@@ -116,6 +116,7 @@ export interface DatagridCondition {
116
116
  }
117
117
  export declare function initDatagridCondition(): DatagridCondition;
118
118
  export declare function summarizeCondition(condition: DatagridCondition, localeMessageFn: (language: string, messageId: string) => Promise<string>): Promise<string>;
119
+ export declare function summarizeConditionAsMarkdown(condition: DatagridCondition, localeMessageFn: (language: string, messageId: string) => Promise<string>): Promise<string>;
119
120
  export declare function codifyCondition(condition: DatagridCondition): string;
120
121
  /**
121
122
  * Equivalent of `parseNumeric` in front end
@@ -124,5 +125,8 @@ export declare function codifyCondition(condition: DatagridCondition): string;
124
125
  */
125
126
  export declare function stripNumericValueFormat(value: string | number | undefined): any;
126
127
  export declare function transformDatagrid(rows: any[], datagridState: DatagridStateBase, locale: string, condition?: DatagridCondition): DatagridState;
127
- export declare function datagridToHtml(datagridState: DatagridState): string;
128
+ export declare function datagridToString(datagridState: DatagridState): {
129
+ html: string;
130
+ markdown: string;
131
+ };
128
132
  export {};
@@ -286,6 +286,27 @@ export async function summarizeCondition(condition, localeMessageFn) {
286
286
  }
287
287
  return `${condition.columnName} ${ruleStr}`;
288
288
  }
289
+ export async function summarizeConditionAsMarkdown(condition, localeMessageFn) {
290
+ let ruleStr = '';
291
+ switch (condition.rule) {
292
+ case ConditionalFormatRule.BETWEEN:
293
+ ruleStr = `**${await localeMessageFn(CHATWMS_DEFAULT_LANGUAGE, condition.rule)}** ${condition.value} **${await localeMessageFn(CHATWMS_DEFAULT_LANGUAGE, 'conditional-format-rule-and')}** ${condition.value2}`;
294
+ break;
295
+ case ConditionalFormatRule.BLANK:
296
+ case ConditionalFormatRule.NOT_BLANK:
297
+ ruleStr = `**${await localeMessageFn(CHATWMS_DEFAULT_LANGUAGE, condition.rule)}**`;
298
+ break;
299
+ default:
300
+ if (condition.dataType === 'text') {
301
+ ruleStr = `**${await localeMessageFn(CHATWMS_DEFAULT_LANGUAGE, condition.rule)}** '${condition.value}'`;
302
+ }
303
+ else {
304
+ ruleStr = `**${await localeMessageFn(CHATWMS_DEFAULT_LANGUAGE, condition.rule)}** ${condition.value}`;
305
+ }
306
+ break;
307
+ }
308
+ return `\`${condition.columnName}\` ${ruleStr}`;
309
+ }
289
310
  export function codifyCondition(condition) {
290
311
  // NOTE: since we check for action/unsafe SQL with every query, we do not need to check for SQL injection here.
291
312
  if (condition.dataType === 'number') {
@@ -723,6 +744,8 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
723
744
  rows = filterRows(rows, filterModel);
724
745
  const chartRowData = [];
725
746
  // IMPORTANT: we evaluate the datagrid condition AFTER we are done with all transformations.
747
+ // NOTE: we do not need any pivot columns for pivot mode to be valid.
748
+ // https://chatwms.io/user-manual/chatwms/faq#q-do-i-have-to-have-a-group-column-to-just-display-a-count-in-the-datagrid
726
749
  if (isPivotMode && valueCols.length > 0) {
727
750
  const pivotOutput = pivotData(rows, rowGroupCols, pivotCols, valueCols);
728
751
  rows = pivotOutput.rows;
@@ -806,32 +829,45 @@ export function transformDatagrid(rows, datagridState, locale, condition) {
806
829
  }
807
830
  return { ...datagridState, adjRowData: rows, chartRowData };
808
831
  }
809
- export function datagridToHtml(datagridState) {
810
- let buf = '';
832
+ export function datagridToString(datagridState) {
833
+ let htmlBuf = '';
834
+ let markdownBuf = '';
811
835
  if (datagridState.adjRowData.length === 0) {
812
- return buf;
836
+ return {
837
+ html: htmlBuf,
838
+ markdown: markdownBuf
839
+ };
813
840
  }
814
841
  const columnFormats = datagridState.columnFormats ?? [];
815
842
  if (columnFormats.length === 0) {
816
- return buf;
843
+ return {
844
+ html: htmlBuf,
845
+ markdown: markdownBuf
846
+ };
817
847
  }
818
848
  // Header:
819
- buf += '<table>\n\t<thead>\n\t\t<tr>';
849
+ htmlBuf += '<table>\n\t<thead>\n\t\t<tr>';
820
850
  let columns = [];
821
851
  for (const key in datagridState.adjRowData[0]) {
822
852
  columns.push(key);
823
- buf += `\n\t\t\t<th>${key}</th>`;
853
+ htmlBuf += `\n\t\t\t<th>${key}</th>`;
854
+ markdownBuf += `| ${key} `;
855
+ }
856
+ markdownBuf += '|\n';
857
+ for (const _ of columns) {
858
+ markdownBuf += `| ----- `;
824
859
  }
825
- buf += '\n\t\t</tr>\n\t</thead>';
860
+ markdownBuf += '|\n';
861
+ htmlBuf += '\n\t\t</tr>\n\t</thead>';
826
862
  // Rows:
827
- buf += '\n\t<tbody>';
863
+ htmlBuf += '\n\t<tbody>';
828
864
  let rowIdx = 0;
829
865
  for (const row of datagridState.adjRowData) {
830
866
  let colIdx = 0;
831
867
  const rowStyles = [];
832
868
  const colStyles = [];
833
869
  let cellValues = [];
834
- // Extract cell values and row/column styles first, then write to html.
870
+ // Extract cell values and row/column styles first, then write to html & markdown.
835
871
  for (const key in row) {
836
872
  let val = row[key];
837
873
  if (val instanceof Date) {
@@ -864,25 +900,30 @@ export function datagridToHtml(datagridState) {
864
900
  }
865
901
  // Apply row styles.
866
902
  if (rowStyles.length > 0) {
867
- buf += `\n\t\t<tr class="${rowStyles.join(' ')}">`;
903
+ htmlBuf += `\n\t\t<tr class="${rowStyles.join(' ')}">`;
868
904
  }
869
905
  else {
870
- buf += '\n\t\t<tr>';
906
+ htmlBuf += '\n\t\t<tr>';
871
907
  }
872
908
  // Write cell values with styles.
873
909
  colIdx = 0;
874
910
  for (const rowValue of cellValues) {
875
911
  if (colStyles[colIdx].styles.length > 0) {
876
- buf += `\n\t\t\t<td class="${colStyles[colIdx].styles.join(' ')}">${rowValue}</td>`;
912
+ htmlBuf += `\n\t\t\t<td class="${colStyles[colIdx].styles.join(' ')}">${rowValue}</td>`;
877
913
  }
878
914
  else {
879
- buf += `\n\t\t\t<td>${rowValue}</td>`;
915
+ htmlBuf += `\n\t\t\t<td>${rowValue}</td>`;
880
916
  }
917
+ markdownBuf += `| ${rowValue} `;
881
918
  colIdx++;
882
919
  }
883
- buf += '\n\t\t</tr>';
920
+ htmlBuf += '\n\t\t</tr>';
921
+ markdownBuf += '|\n';
884
922
  rowIdx++;
885
923
  }
886
- buf += '\n\t</tbody>\n</table>';
887
- return buf;
924
+ htmlBuf += '\n\t</tbody>\n</table>';
925
+ return {
926
+ html: htmlBuf,
927
+ markdown: markdownBuf
928
+ };
888
929
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cellaware/utils",
3
- "version": "8.1.12",
3
+ "version": "8.2.1",
4
4
  "description": "Cellaware Utilities for Node.js",
5
5
  "author": "Cellaware Technologies",
6
6
  "type": "module",