@richardmcquiston01/dashboard-widgets-toolkit 0.5.0 → 0.7.0

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/index.cjs CHANGED
@@ -252,6 +252,16 @@ function resolveDetailOptions(definition) {
252
252
  mode: options.mode ?? "client"
253
253
  };
254
254
  }
255
+ function resolveTableControls(definition) {
256
+ const setting = definition.tableControls;
257
+ if (setting === void 0 || setting === false) return void 0;
258
+ const options = setting === true ? {} : setting;
259
+ const resolved = {
260
+ search: options.search ?? true,
261
+ sort: options.sort ?? true
262
+ };
263
+ return resolved.search || resolved.sort ? resolved : void 0;
264
+ }
255
265
  function defaultDetailQuery(pageSize = DEFAULT_DETAIL_PAGE_SIZE) {
256
266
  return { page: 1, pageSize };
257
267
  }
@@ -526,17 +536,19 @@ function validateDetailData(data, subject = "Detail data") {
526
536
  }
527
537
  return ok(data);
528
538
  }
539
+ function tableDetailData(data) {
540
+ return {
541
+ columns: data.columns.map((column, index) => ({
542
+ key: `c${index}`,
543
+ label: column.label,
544
+ ...column.numeric === void 0 ? {} : { numeric: column.numeric }
545
+ })),
546
+ rows: data.rows
547
+ };
548
+ }
529
549
  function deriveDetailData(data, locale) {
530
550
  if (data.kind === "TABLE") {
531
- if (data.footer !== void 0) return void 0;
532
- return {
533
- columns: data.columns.map((column, index) => ({
534
- key: `c${index}`,
535
- label: column.label,
536
- ...column.numeric === void 0 ? {} : { numeric: column.numeric }
537
- })),
538
- rows: data.rows
539
- };
551
+ return data.footer === void 0 ? tableDetailData(data) : void 0;
540
552
  }
541
553
  if (data.kind === "BAR_LIST") {
542
554
  return {
@@ -814,6 +826,14 @@ function optionalNumber(record, field, path, problems) {
814
826
  requireNumber(record, field, path, problems);
815
827
  }
816
828
  }
829
+ function optionalSortValue(record, path, problems) {
830
+ const value = record["value"];
831
+ if (value !== void 0 && typeof value !== "string" && !(typeof value === "number" && Number.isFinite(value))) {
832
+ problems.push(
833
+ `${path}.value must be a string or a finite number, got ${describeType2(value)}.`
834
+ );
835
+ }
836
+ }
817
837
  function optionalBoolean(record, field, path, problems) {
818
838
  const value = record[field];
819
839
  if (value !== void 0 && typeof value !== "boolean") {
@@ -917,6 +937,7 @@ function checkPayloadFields(kind, data, problems) {
917
937
  }
918
938
  eachRecord(row, rowPath, problems, (cell, cellPath) => {
919
939
  requireString(cell, "text", cellPath, problems);
940
+ optionalSortValue(cell, cellPath, problems);
920
941
  optionalUrl(
921
942
  cell,
922
943
  "href",
@@ -1021,6 +1042,24 @@ function checkDetailOption(detail, problems) {
1021
1042
  requireOneOf(detail, "mode", DETAIL_MODES, "detail", problems);
1022
1043
  }
1023
1044
  }
1045
+ function checkTableControlsOption(controls, kind, problems) {
1046
+ if (controls === void 0 || controls === false) return;
1047
+ if (typeof controls !== "boolean" && !isRecord(controls)) {
1048
+ problems.push(
1049
+ `tableControls must be true, false or an options object, got ${describeType2(controls)}.`
1050
+ );
1051
+ return;
1052
+ }
1053
+ if (isRecord(controls)) {
1054
+ optionalBoolean(controls, "search", "tableControls", problems);
1055
+ optionalBoolean(controls, "sort", "tableControls", problems);
1056
+ }
1057
+ if (typeof kind === "string" && kind !== "TABLE") {
1058
+ problems.push(
1059
+ `tableControls only applies to TABLE widgets, but kind is "${kind}".`
1060
+ );
1061
+ }
1062
+ }
1024
1063
  function formatProblems(prefix, problems) {
1025
1064
  const shown = problems.slice(0, MAX_REPORTED_PROBLEMS);
1026
1065
  const more = problems.length - shown.length;
@@ -1093,6 +1132,7 @@ function validateWidgetDefinition(value) {
1093
1132
  );
1094
1133
  }
1095
1134
  checkDetailOption(value["detail"], problems);
1135
+ checkTableControlsOption(value["tableControls"], value["kind"], problems);
1096
1136
  if (value["fill"] !== void 0) {
1097
1137
  requireOneOf(value, "fill", WIDGET_FILLS, "", problems);
1098
1138
  }
@@ -1440,6 +1480,7 @@ exports.pruneLayout = pruneLayout;
1440
1480
  exports.queryRows = queryRows;
1441
1481
  exports.resolveDetailOptions = resolveDetailOptions;
1442
1482
  exports.resolvePayload = resolvePayload;
1483
+ exports.resolveTableControls = resolveTableControls;
1443
1484
  exports.resolveWidget = resolveWidget;
1444
1485
  exports.resolveWidgets = resolveWidgets;
1445
1486
  exports.restoreWidget = restoreWidget;
@@ -1448,6 +1489,7 @@ exports.serializeLayout = serializeLayout;
1448
1489
  exports.shareOf = shareOf;
1449
1490
  exports.showWidget = showWidget;
1450
1491
  exports.sortDefinitions = sortDefinitions;
1492
+ exports.tableDetailData = tableDetailData;
1451
1493
  exports.toggleHidden = toggleHidden;
1452
1494
  exports.toggleMinimized = toggleMinimized;
1453
1495
  exports.upgradeLegacyWidgetData = upgradeLegacyWidgetData;