@vuu-ui/vuu-table 0.7.2-debug → 0.7.3-debug

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/cjs/index.js CHANGED
@@ -162,7 +162,10 @@ function buildAggregationMenuItems(options, dataSource) {
162
162
  return [
163
163
  {
164
164
  label: `Aggregate ${label}`,
165
- children: [{ label: "Count", action: "agg-count", options }].concat(
165
+ children: [
166
+ { label: "Count", action: "agg-count", options },
167
+ { label: "Distinct", action: "agg-distinct", options }
168
+ ].concat(
166
169
  (0, import_vuu_utils.isNumericColumn)(column) ? [
167
170
  { label: "Sum", action: "agg-sum", options },
168
171
  { label: "Avg", action: "agg-avg", options },
@@ -271,7 +274,7 @@ var removeFilterColumn = (dataSourceFilter, column) => {
271
274
  return dataSourceFilter;
272
275
  }
273
276
  };
274
- var { Average, Count, High, Low, Sum } = import_vuu_utils2.AggregationType;
277
+ var { Average, Count, Distinct, High, Low, Sum } = import_vuu_utils2.AggregationType;
275
278
  var useTableContextMenu = ({
276
279
  dataSource,
277
280
  onPersistentColumnOperation
@@ -309,6 +312,8 @@ var useTableContextMenu = ({
309
312
  return dataSource.aggregations = (0, import_vuu_utils2.setAggregations)(dataSource.aggregations, column, Low), true;
310
313
  case "agg-count":
311
314
  return dataSource.aggregations = (0, import_vuu_utils2.setAggregations)(dataSource.aggregations, column, Count), true;
315
+ case "agg-distinct":
316
+ return dataSource.aggregations = (0, import_vuu_utils2.setAggregations)(dataSource.aggregations, column, Distinct), true;
312
317
  case "agg-sum":
313
318
  return dataSource.aggregations = (0, import_vuu_utils2.setAggregations)(dataSource.aggregations, column, Sum), true;
314
319
  case "column-pin-floating":
@@ -456,7 +461,7 @@ var { DEPTH, IS_LEAF } = import_vuu_utils4.metadataKeys;
456
461
  var getGroupValueAndOffset = (columns, row) => {
457
462
  const { [DEPTH]: depth, [IS_LEAF]: isLeaf } = row;
458
463
  if (isLeaf || depth > columns.length) {
459
- return [null, depth === null ? 0 : depth - 1];
464
+ return [null, depth === null ? 0 : Math.max(0, depth - 1)];
460
465
  } else if (depth === 0) {
461
466
  return ["$root", 0];
462
467
  } else {
@@ -1712,14 +1717,18 @@ var getCellRendererForColumn = (column) => {
1712
1717
  return (0, import_vuu_utils11.getCellRenderer)((_a = column.type) == null ? void 0 : _a.renderer);
1713
1718
  }
1714
1719
  };
1715
- var getDataType = (column, columnNames, dataTypes) => {
1716
- var _a;
1717
- const index = columnNames.indexOf(column.name);
1718
- if (index !== -1 && dataTypes[index]) {
1719
- return dataTypes[index];
1720
- } else {
1721
- return (_a = column.serverDataType) != null ? _a : "string";
1720
+ var getServerDataTypeForColumn = (column, tableSchema) => {
1721
+ if (column.serverDataType) {
1722
+ return column.serverDataType;
1723
+ } else if (tableSchema) {
1724
+ const schemaColumn = tableSchema.columns.find(
1725
+ (col) => col.name === column.name
1726
+ );
1727
+ if (schemaColumn) {
1728
+ return schemaColumn.serverDataType;
1729
+ }
1722
1730
  }
1731
+ return "string";
1723
1732
  };
1724
1733
  var numericTypes = ["int", "long", "double"];
1725
1734
  var getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
@@ -1732,8 +1741,8 @@ var columnReducer = (state, action) => {
1732
1741
  return moveColumn(state, action);
1733
1742
  case "resizeColumn":
1734
1743
  return resizeColumn(state, action);
1735
- case "setTypes":
1736
- return setTypes(state, action);
1744
+ case "setTableSchema":
1745
+ return setTableSchema(state, action);
1737
1746
  case "hideColumns":
1738
1747
  return hideColumns(state, action);
1739
1748
  case "showColumns":
@@ -1785,9 +1794,13 @@ var getLabel = (label, columnFormatHeader) => {
1785
1794
  return label;
1786
1795
  };
1787
1796
  var toKeyedColumWithDefaults = (options) => (column, index) => {
1797
+ const serverDataType = getServerDataTypeForColumn(
1798
+ column,
1799
+ options.tableSchema
1800
+ );
1788
1801
  const { columnDefaultWidth = DEFAULT_COLUMN_WIDTH, columnFormatHeader } = options;
1789
1802
  const {
1790
- align = getDefaultAlignment(column.serverDataType),
1803
+ align = getDefaultAlignment(serverDataType),
1791
1804
  key,
1792
1805
  name,
1793
1806
  label = name,
@@ -1802,6 +1815,7 @@ var toKeyedColumWithDefaults = (options) => (column, index) => {
1802
1815
  key: key != null ? key : index + KEY_OFFSET,
1803
1816
  name,
1804
1817
  originalIdx: index,
1818
+ serverDataType,
1805
1819
  valueFormatter: (0, import_vuu_utils11.getValueFormatter)(column),
1806
1820
  width
1807
1821
  };
@@ -1879,12 +1893,12 @@ function resizeColumn(state, { column, phase, width }) {
1879
1893
  throw Error(`useTableModel.resizeColumn, invalid resizePhase ${phase}`);
1880
1894
  }
1881
1895
  }
1882
- function setTypes(state, { columnNames, serverDataTypes }) {
1896
+ function setTableSchema(state, { tableSchema }) {
1883
1897
  const { columns } = state;
1884
1898
  if (columns.some(columnWithoutDataType)) {
1885
1899
  const cols = columns.map((column) => {
1886
1900
  var _a;
1887
- const serverDataType = getDataType(column, columnNames, serverDataTypes);
1901
+ const serverDataType = getServerDataTypeForColumn(column, tableSchema);
1888
1902
  return {
1889
1903
  ...column,
1890
1904
  align: (_a = column.align) != null ? _a : getDefaultAlignment(serverDataType),
@@ -1893,10 +1907,14 @@ function setTypes(state, { columnNames, serverDataTypes }) {
1893
1907
  });
1894
1908
  return {
1895
1909
  ...state,
1896
- columns: cols
1910
+ columns: cols,
1911
+ tableSchema
1897
1912
  };
1898
1913
  } else {
1899
- return state;
1914
+ return {
1915
+ ...state,
1916
+ tableSchema
1917
+ };
1900
1918
  }
1901
1919
  }
1902
1920
  function pinColumn2(state, action) {
@@ -1962,6 +1980,13 @@ function updateTableConfig(state, { columns, confirmed, filter, groupBy, sort })
1962
1980
  key
1963
1981
  };
1964
1982
  }
1983
+ } else {
1984
+ return toKeyedColumWithDefaults(state)(
1985
+ {
1986
+ name: colName
1987
+ },
1988
+ index
1989
+ );
1965
1990
  }
1966
1991
  throw Error(`useTableModel column ${colName} not found`);
1967
1992
  })
@@ -2391,15 +2416,15 @@ var useTable = ({
2391
2416
  size: containerMeasurements.innerSize
2392
2417
  });
2393
2418
  const onSubscribed = (0, import_react20.useCallback)(
2394
- (subscription) => {
2395
- if (subscription.tableMeta) {
2396
- const { columns: columnNames, dataTypes: serverDataTypes } = subscription.tableMeta;
2419
+ ({ tableSchema }) => {
2420
+ if (tableSchema) {
2397
2421
  expectConfigChangeRef.current = true;
2398
2422
  dispatchColumnAction({
2399
- type: "setTypes",
2400
- columnNames,
2401
- serverDataTypes
2423
+ type: "setTableSchema",
2424
+ tableSchema
2402
2425
  });
2426
+ } else {
2427
+ console.log("usbscription message with no schema");
2403
2428
  }
2404
2429
  },
2405
2430
  [dispatchColumnAction]