@ni/nimble-components 17.0.0 → 17.0.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.
@@ -25080,6 +25080,54 @@
25080
25080
  });
25081
25081
  }
25082
25082
 
25083
+ /**
25084
+ * Helper class for the nimble-table to validate that the table's configuration
25085
+ * is valid and report which aspects of the configuration are valid or invalid.
25086
+ */
25087
+ class TableValidator {
25088
+ constructor() {
25089
+ this.duplicateRowId = false;
25090
+ this.missingRowId = false;
25091
+ this.invalidRowId = false;
25092
+ }
25093
+ getValidity() {
25094
+ return {
25095
+ duplicateRowId: this.duplicateRowId,
25096
+ missingRowId: this.missingRowId,
25097
+ invalidRowId: this.invalidRowId
25098
+ };
25099
+ }
25100
+ isValid() {
25101
+ return Object.values(this.getValidity()).every(x => x === false);
25102
+ }
25103
+ validateDataIds(data, idFieldName) {
25104
+ // Start off by assuming all IDs are valid.
25105
+ this.duplicateRowId = false;
25106
+ this.missingRowId = false;
25107
+ this.invalidRowId = false;
25108
+ if (idFieldName == null) {
25109
+ return true;
25110
+ }
25111
+ const ids = new Set();
25112
+ for (const record of data) {
25113
+ if (!Object.prototype.hasOwnProperty.call(record, idFieldName)) {
25114
+ this.missingRowId = true;
25115
+ continue;
25116
+ }
25117
+ const id = record[idFieldName];
25118
+ if (typeof id !== 'string' || id === '') {
25119
+ this.invalidRowId = true;
25120
+ continue;
25121
+ }
25122
+ if (ids.has(id)) {
25123
+ this.duplicateRowId = true;
25124
+ }
25125
+ ids.add(id);
25126
+ }
25127
+ return !this.missingRowId && !this.invalidRowId && !this.duplicateRowId;
25128
+ }
25129
+ }
25130
+
25083
25131
  const styles$c = css `
25084
25132
  ${display('flex')}
25085
25133
 
@@ -25245,9 +25293,9 @@
25245
25293
  </div>
25246
25294
  </div>
25247
25295
  <div class="table-viewport" role="rowgroup">
25248
- ${repeat(x => x.data, html `
25296
+ ${repeat(x => x.tableData, html `
25249
25297
  <${DesignSystem.tagFor(TableRow)}
25250
- :data="${x => x}"
25298
+ :data="${x => x.data}"
25251
25299
  :columns="${(_, c) => c.parent.columns}"
25252
25300
  >
25253
25301
  </${DesignSystem.tagFor(TableRow)}>
@@ -25264,12 +25312,17 @@
25264
25312
  constructor() {
25265
25313
  super();
25266
25314
  this.data = [];
25315
+ /**
25316
+ * @internal
25317
+ */
25318
+ this.tableData = [];
25267
25319
  // TODO: Temporarily expose the columns as a string array. This will ultimately be
25268
25320
  // column definitions provided by slotted elements.
25269
25321
  this.columns = [];
25270
25322
  // TODO: Temporarily expose the column headers as a string array.
25271
25323
  this.columnHeaders = [];
25272
25324
  this.tableInitialized = false;
25325
+ this.tableValidator = new TableValidator();
25273
25326
  this.update = (state) => {
25274
25327
  this.table.setOptions(prev => ({
25275
25328
  ...prev,
@@ -25287,6 +25340,13 @@
25287
25340
  data: [],
25288
25341
  onStateChange: (_) => { },
25289
25342
  getCoreRowModel: getCoreRowModel(),
25343
+ getRowId: record => {
25344
+ if (this.idFieldName) {
25345
+ return record[this.idFieldName];
25346
+ }
25347
+ // Return a falsey value to use the default ID from TanStack.
25348
+ return '';
25349
+ },
25290
25350
  columns: [],
25291
25351
  state: {},
25292
25352
  renderFallbackValue: null,
@@ -25295,18 +25355,46 @@
25295
25355
  this.table = createTable(this.options);
25296
25356
  this.tableInitialized = true;
25297
25357
  }
25358
+ get validity() {
25359
+ return this.tableValidator.getValidity();
25360
+ }
25361
+ idFieldNameChanged(_prev, _next) {
25362
+ // Force TanStack to detect a data update because a row's ID is only
25363
+ // generated when creating a new row model.
25364
+ this.trySetData([...this.data]);
25365
+ }
25298
25366
  dataChanged(prev, next) {
25299
25367
  if ((!prev || prev.length === 0) && next && next.length > 0) {
25300
25368
  this.generateColumns();
25301
25369
  }
25302
25370
  // Ignore any updates that occur prior to the TanStack table being initialized.
25303
25371
  if (this.tableInitialized) {
25304
- this.updateTableOptions({ data: this.data });
25372
+ this.trySetData(this.data);
25373
+ }
25374
+ }
25375
+ checkValidity() {
25376
+ return this.tableValidator.isValid();
25377
+ }
25378
+ trySetData(newData) {
25379
+ const areIdsValid = this.tableValidator.validateDataIds(newData, this.idFieldName);
25380
+ if (areIdsValid) {
25381
+ this.updateTableOptions({ data: newData });
25382
+ }
25383
+ else {
25384
+ this.updateTableOptions({ data: [] });
25305
25385
  }
25306
25386
  }
25387
+ refreshRows() {
25388
+ const rows = this.table.getRowModel().rows;
25389
+ this.tableData = rows.map(row => {
25390
+ const rowState = { data: row.original };
25391
+ return rowState;
25392
+ });
25393
+ }
25307
25394
  updateTableOptions(updatedOptions) {
25308
25395
  this.options = { ...this.options, ...updatedOptions };
25309
25396
  this.update(this.table.initialState);
25397
+ this.refreshRows();
25310
25398
  }
25311
25399
  // Temporarily auto-detect the keys in TData to make columns.
25312
25400
  // TODO: Remove this logic when another way to specify columns is provided.
@@ -25329,9 +25417,15 @@
25329
25417
  this.columns = this.columnHeaders;
25330
25418
  }
25331
25419
  }
25420
+ __decorate$1([
25421
+ attr({ attribute: 'id-field-name' })
25422
+ ], Table.prototype, "idFieldName", void 0);
25332
25423
  __decorate$1([
25333
25424
  observable
25334
25425
  ], Table.prototype, "data", void 0);
25426
+ __decorate$1([
25427
+ observable
25428
+ ], Table.prototype, "tableData", void 0);
25335
25429
  __decorate$1([
25336
25430
  observable
25337
25431
  ], Table.prototype, "columns", void 0);
@@ -29560,13 +29654,10 @@ Instead styling against the role which is more general and likely a better appro
29560
29654
  attr({
29561
29655
  attribute: 'color-scale-mode'
29562
29656
  })
29563
- ], WaferMap.prototype, "canvas", void 0);
29657
+ ], WaferMap.prototype, "colorScaleMode", void 0);
29564
29658
  __decorate$1([
29565
29659
  observable
29566
29660
  ], WaferMap.prototype, "canvasSideLength", void 0);
29567
- __decorate$1([
29568
- observable
29569
- ], WaferMap.prototype, "colorScaleMode", void 0);
29570
29661
  __decorate$1([
29571
29662
  observable
29572
29663
  ], WaferMap.prototype, "highlightedValues", void 0);