@aivenio/aquarium 2.2.0 → 2.3.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.
Files changed (37) hide show
  1. package/dist/atoms.cjs +21 -6
  2. package/dist/atoms.mjs +21 -6
  3. package/dist/src/atoms/DataList/DataList.d.ts +6 -2
  4. package/dist/src/atoms/DataList/DataList.js +15 -4
  5. package/dist/src/molecules/DataList/DataList.d.ts +2 -2
  6. package/dist/src/molecules/DataList/DataList.js +3 -3
  7. package/dist/src/molecules/DataList/DataListComponents.d.ts +3 -3
  8. package/dist/src/molecules/DataList/DataListComponents.js +15 -2
  9. package/dist/src/molecules/DataList/DataListGroup.js +10 -6
  10. package/dist/src/molecules/DataList/DataListSkeleton.js +2 -2
  11. package/dist/src/molecules/DataTable/DataTable.js +3 -3
  12. package/dist/src/molecules/ItemList/ItemList.d.ts +39 -0
  13. package/dist/src/molecules/ItemList/ItemList.js +72 -0
  14. package/dist/src/molecules/ItemList/ItemList.spec.d.ts +24 -0
  15. package/dist/src/molecules/ItemList/ItemList.spec.js +100 -0
  16. package/dist/src/molecules/ItemList/types.d.ts +114 -0
  17. package/dist/src/molecules/ItemList/types.js +2 -0
  18. package/dist/src/molecules/PageHeader/PageHeader.d.ts +3 -3
  19. package/dist/src/molecules/PageHeader/PageHeader.js +5 -1
  20. package/dist/src/molecules/index.d.ts +3 -0
  21. package/dist/src/molecules/index.js +4 -1
  22. package/dist/src/utils/table/sortByColumn.d.ts +3 -0
  23. package/dist/src/utils/table/sortByColumn.js +23 -0
  24. package/dist/src/utils/table/types.d.ts +23 -3
  25. package/dist/src/utils/table/types.js +3 -1
  26. package/dist/src/utils/table/useSortState.d.ts +15 -0
  27. package/dist/src/utils/table/useSortState.js +3 -0
  28. package/dist/src/utils/table/useTableSort.d.ts +3 -3
  29. package/dist/src/utils/table/useTableSort.js +2 -2
  30. package/dist/src/utils/table/utils.d.ts +2 -2
  31. package/dist/src/utils/table/utils.js +3 -3
  32. package/dist/styles.css +18 -0
  33. package/dist/system.cjs +182 -23
  34. package/dist/system.mjs +178 -23
  35. package/dist/tsconfig.module.tsbuildinfo +1 -1
  36. package/dist/types/tailwindGenerated.d.ts +1 -1
  37. package/package.json +2 -2
package/dist/system.mjs CHANGED
@@ -4260,6 +4260,7 @@ __export(molecules_exports, {
4260
4260
  InlineIcon: () => InlineIcon,
4261
4261
  Input: () => Input2,
4262
4262
  InputBase: () => InputBase,
4263
+ ItemList: () => ItemList,
4263
4264
  LineClamp: () => LineClamp2,
4264
4265
  Link: () => Link2,
4265
4266
  List: () => List,
@@ -4324,13 +4325,16 @@ __export(molecules_exports, {
4324
4325
  asPopoverButton: () => asPopoverButton,
4325
4326
  asTabItem: () => asTabItem,
4326
4327
  cellProps: () => cellProps,
4328
+ columnHasSort: () => columnHasSort,
4327
4329
  columnIsFieldColumn: () => columnIsFieldColumn,
4328
4330
  createTabsComponent: () => createTabsComponent,
4329
4331
  isOnSortChangedDirection: () => isOnSortChangedDirection,
4332
+ sortByColumn: () => sortByColumn,
4330
4333
  toSortDirection: () => toSortDirection,
4331
4334
  usePagination: () => usePagination,
4332
4335
  usePopoverContext: () => usePopoverContext,
4333
4336
  useScrollTarget: () => useScrollTarget,
4337
+ useSortState: () => useSortState,
4334
4338
  useStaticInfiniteList: () => useStaticInfiniteList,
4335
4339
  useTableSelect: () => useTableSelect,
4336
4340
  useTableSort: () => useTableSort,
@@ -11268,6 +11272,19 @@ var DataList = (_a) => {
11268
11272
  var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
11269
11273
  return /* @__PURE__ */ React63.createElement("div", __spreadValues({}, rest));
11270
11274
  };
11275
+ var TreeLine = (_a) => {
11276
+ var _b = _a, { className, style, isLast } = _b, rest = __objRest(_b, ["className", "style", "isLast"]);
11277
+ return /* @__PURE__ */ React63.createElement("div", __spreadProps(__spreadValues({}, rest), {
11278
+ className: classNames(tw("flex justify-start h-full mx-4"), className)
11279
+ }), /* @__PURE__ */ React63.createElement("div", {
11280
+ className: tw("border-l border-default border-dashed flex-1", {
11281
+ "h-full": !isLast,
11282
+ "h-1/2": Boolean(isLast)
11283
+ })
11284
+ }), /* @__PURE__ */ React63.createElement("div", {
11285
+ className: tw("border-t border-default border-dashed self-center w-[18px]")
11286
+ }));
11287
+ };
11271
11288
  var HeadCell = (_a) => {
11272
11289
  var _b = _a, {
11273
11290
  className,
@@ -11317,22 +11334,22 @@ var Row = (_a) => {
11317
11334
  className,
11318
11335
  disabled,
11319
11336
  header,
11320
- subgroup,
11337
+ isGroup,
11321
11338
  active,
11322
- isLast
11339
+ noDivider
11323
11340
  } = _b, rest = __objRest(_b, [
11324
11341
  "className",
11325
11342
  "disabled",
11326
11343
  "header",
11327
- "subgroup",
11344
+ "isGroup",
11328
11345
  "active",
11329
- "isLast"
11346
+ "noDivider"
11330
11347
  ]);
11331
11348
  return /* @__PURE__ */ React63.createElement("div", __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, rest), {
11332
- role: subgroup ? "rowgroup" : "row"
11349
+ role: isGroup ? "rowgroup" : "row"
11333
11350
  }), { inert: disabled ? "" : void 0 }), {
11334
11351
  className: classNames(tw("contents"), className, {
11335
- "[&>*]:border-b-transparent": isLast,
11352
+ "[&>*]:border-b-transparent": noDivider,
11336
11353
  "children:opacity-70": disabled,
11337
11354
  "[&>*]:bg-primary-active": active,
11338
11355
  "[&>*]:hover:bg-muted": !disabled && !header
@@ -11388,6 +11405,8 @@ DataList.SubGroupSpacing = SubGroupSpacing;
11388
11405
  DataList.SubGroupSpacing.displayName = "DataList.SubGroupSpacing";
11389
11406
  DataList.Row = Row;
11390
11407
  DataList.Row.displayName = "DataList.Row";
11408
+ DataList.TreeLine = TreeLine;
11409
+ DataList.TreeLine.displayName = "DataList.TreeLine";
11391
11410
  var ToolbarContainer = (_a) => {
11392
11411
  var _b = _a, { className, sticky = true } = _b, rest = __objRest(_b, ["className", "sticky"]);
11393
11412
  return /* @__PURE__ */ React63.createElement("div", __spreadProps(__spreadValues({}, rest), {
@@ -11534,6 +11553,7 @@ var cellProps = (column) => {
11534
11553
  var _a;
11535
11554
  let align;
11536
11555
  switch (column.type) {
11556
+ case "menu":
11537
11557
  case "action":
11538
11558
  case "number": {
11539
11559
  align = "right";
@@ -11553,6 +11573,7 @@ var cellProps = (column) => {
11553
11573
  stickyColumn: column.sticky
11554
11574
  };
11555
11575
  };
11576
+ var columnHasSort = (column) => columnIsFieldColumn(column) && column.sortable || Boolean(column.sort);
11556
11577
  var columnIsFieldColumn = (column) => Boolean(column && column.field);
11557
11578
  function isOnSortChangedDirection(value) {
11558
11579
  return value === void 0 || ["ascending", "descending"].includes(value);
@@ -11560,11 +11581,7 @@ function isOnSortChangedDirection(value) {
11560
11581
 
11561
11582
  // src/utils/table/useTableSort.tsx
11562
11583
  import React65 from "react";
11563
- var useTableSort = ({
11564
- column,
11565
- direction,
11566
- onSortChanged
11567
- } = {}) => {
11584
+ var useTableSort = ({ column, direction, onSortChanged } = {}) => {
11568
11585
  const defaultSort = column ? { column, direction } : void 0;
11569
11586
  const [sort, setSort] = React65.useState(defaultSort);
11570
11587
  const setSortAndEmitOnSortChangedEvent = (sort2) => {
@@ -11594,7 +11611,7 @@ var useTableSort = ({
11594
11611
  // src/utils/table/utils.ts
11595
11612
  import orderBy2 from "lodash/orderBy";
11596
11613
  var sortRowsBy = (rows, sort) => {
11597
- if (!sort) {
11614
+ if (!sort || !columnHasSort(sort.column)) {
11598
11615
  return rows;
11599
11616
  }
11600
11617
  const sortFunction = sort.column.sort;
@@ -12059,7 +12076,7 @@ var DataListRow = ({
12059
12076
  key: row.id,
12060
12077
  disabled: isRowDisabled,
12061
12078
  active,
12062
- isLast
12079
+ noDivider: isLast
12063
12080
  }, resolvedAdditionalRowProps), {
12064
12081
  style,
12065
12082
  onClick: isRowClickable ? onClick : void 0
@@ -12126,6 +12143,21 @@ var DataListCell = ({
12126
12143
  }
12127
12144
  break;
12128
12145
  }
12146
+ case "menu": {
12147
+ const menuContent = column.menu(row, index);
12148
+ if (!menuContent) {
12149
+ cellContent = null;
12150
+ } else {
12151
+ cellContent = /* @__PURE__ */ React68.createElement(DropdownMenu2, {
12152
+ placement: defaultContextualMenuPlacement,
12153
+ onAction: (action) => column.onAction(action, row, index)
12154
+ }, /* @__PURE__ */ React68.createElement(DropdownMenu2.Trigger, null, /* @__PURE__ */ React68.createElement(Button.Icon, {
12155
+ "aria-label": "action",
12156
+ icon: import_more2.default
12157
+ })), menuContent);
12158
+ }
12159
+ break;
12160
+ }
12129
12161
  default:
12130
12162
  if (column.formatter) {
12131
12163
  cellContent = column.formatter(row[column.field], row, index, rows);
@@ -12206,14 +12238,18 @@ var DataListGroup = (_a) => {
12206
12238
  const hasCustomRowForGroup = isFunction2(getGroupRow);
12207
12239
  if (!areRowsGrouped(groups)) {
12208
12240
  if (groups.length === 0 && groupKey && groupKey !== "undefined") {
12241
+ const emptyGroupContent = renderEmptyGroup(groupKey);
12242
+ if (!emptyGroupContent) {
12243
+ return null;
12244
+ }
12209
12245
  return /* @__PURE__ */ React69.createElement(DataList.Row, {
12210
- isLast: isLastGroup
12246
+ noDivider: isLastGroup
12211
12247
  }, selectable && /* @__PURE__ */ React69.createElement(DataList.Cell, null), /* @__PURE__ */ React69.createElement(DataList.Cell, {
12212
12248
  style: { paddingLeft: `${2 + GAP + level * INDENTATION}px`, gridColumn: `${selectable ? 2 : 1} / -1` }
12213
12249
  }, /* @__PURE__ */ React69.createElement(Typography, {
12214
12250
  variant: "small",
12215
12251
  color: "muted"
12216
- }, renderEmptyGroup(groupKey))));
12252
+ }, emptyGroupContent)));
12217
12253
  }
12218
12254
  return /* @__PURE__ */ React69.createElement(List, {
12219
12255
  items: groups,
@@ -12299,7 +12335,7 @@ var DataListGroup = (_a) => {
12299
12335
  openPanelId
12300
12336
  }, hasCustomRowForGroup && /* @__PURE__ */ React69.createElement(DataList.Row, {
12301
12337
  active: isActiveRow,
12302
- isLast: isLastRow
12338
+ noDivider: isLastRow
12303
12339
  }, selectable && /* @__PURE__ */ React69.createElement(DataList.Cell, null, selectable === "multiple" && /* @__PURE__ */ React69.createElement(Checkbox, {
12304
12340
  "aria-label": getGroupCheckboxLabel(key, group, index, isChecked, rows),
12305
12341
  checked: isChecked,
@@ -12329,7 +12365,7 @@ var DataListGroup = (_a) => {
12329
12365
  menuAriaLabel
12330
12366
  })), !hasCustomRowForGroup && /* @__PURE__ */ React69.createElement(DataList.Row, {
12331
12367
  active: isActiveRow,
12332
- isLast: isLastRow
12368
+ noDivider: isLastRow
12333
12369
  }, selectable === "multiple" && /* @__PURE__ */ React69.createElement(DataList.Cell, null, /* @__PURE__ */ React69.createElement(Checkbox, {
12334
12370
  "aria-label": getGroupCheckboxLabel(key, group, index, isChecked, rows),
12335
12371
  checked: isChecked,
@@ -12345,7 +12381,7 @@ var DataListGroup = (_a) => {
12345
12381
  }), renderGroupName(key, group))), /* @__PURE__ */ React69.createElement(Accordion.UnanimatedPanel, {
12346
12382
  panelId: key
12347
12383
  }, /* @__PURE__ */ React69.createElement(DataList.Row, {
12348
- subgroup: true
12384
+ isGroup: true
12349
12385
  }, /* @__PURE__ */ React69.createElement(DataListGroup, __spreadProps(__spreadValues({
12350
12386
  key,
12351
12387
  groupKey: key,
@@ -12374,7 +12410,7 @@ var DataListSkeleton = ({ columns = ["1", "2", "2", 52], rows = 5 }) => {
12374
12410
  items: [...Array(rows).keys()],
12375
12411
  renderItem: (item, index) => /* @__PURE__ */ React70.createElement(DataList.Row, {
12376
12412
  key: item,
12377
- isLast: index === rows - 1
12413
+ noDivider: index === rows - 1
12378
12414
  }, /* @__PURE__ */ React70.createElement(List, {
12379
12415
  items: columnsAmount,
12380
12416
  renderItem: (key) => /* @__PURE__ */ React70.createElement(DataList.Cell, {
@@ -12580,7 +12616,7 @@ var DataList2 = (_a) => {
12580
12616
  color: "default",
12581
12617
  "aria-hidden": true
12582
12618
  }), content) : content;
12583
- const cell2 = columnIsFieldColumn(column) && column.sortable || column.sort ? /* @__PURE__ */ React72.createElement(DataList.SortCell, __spreadValues({
12619
+ const cell2 = columnHasSort(column) ? /* @__PURE__ */ React72.createElement(DataList.SortCell, __spreadValues({
12584
12620
  direction: sort && sort.column.headerName === column.headerName ? sort.direction : "none",
12585
12621
  onClick: () => updateSort(column),
12586
12622
  sticky
@@ -12844,7 +12880,7 @@ var DataTable = (_a) => {
12844
12880
  color: "default",
12845
12881
  "aria-hidden": true
12846
12882
  }), content) : content;
12847
- const cell2 = columnIsFieldColumn(column) && column.sortable || column.sort ? /* @__PURE__ */ React75.createElement(Table2.SortCell, __spreadValues({
12883
+ const cell2 = columnHasSort(column) ? /* @__PURE__ */ React75.createElement(Table2.SortCell, __spreadValues({
12848
12884
  direction: sort && sort.column.headerName === column.headerName ? sort.direction : "none",
12849
12885
  onClick: () => updateSort(column),
12850
12886
  style: { width: column.width },
@@ -15480,6 +15516,12 @@ var CommonPageHeader = ({
15480
15516
  isSubHeader = false
15481
15517
  }) => {
15482
15518
  var _a, _b;
15519
+ const actions = [primaryAction, ...castArray6(secondaryActions)].filter(Boolean);
15520
+ if (actions.length > 2) {
15521
+ throw new Error(
15522
+ "Limit the combined `primaryAction` and `secondaryActions` to 2 actions. Use the `menu` prop for additional actions."
15523
+ );
15524
+ }
15483
15525
  return /* @__PURE__ */ React110.createElement(PageHeader, {
15484
15526
  className: "Aquarium-PageHeader"
15485
15527
  }, /* @__PURE__ */ React110.createElement(PageHeader.Container, null, breadcrumbs && /* @__PURE__ */ React110.createElement(Box, {
@@ -16539,10 +16581,33 @@ Timeline2.Skeleton.displayName = "Timeline.Skeleton";
16539
16581
  import React129 from "react";
16540
16582
  var TimePicker = (props) => /* @__PURE__ */ React129.createElement(TimeField, __spreadValues({}, props));
16541
16583
 
16542
- // src/utils/table/useTableSelect.ts
16584
+ // src/utils/table/sortByColumn.ts
16585
+ var sortByColumn = (items, column, sortState) => {
16586
+ const sortedColumn = column.find((column2) => column2.headerName === (sortState == null ? void 0 : sortState.headerName));
16587
+ if (sortState && sortedColumn && columnHasSort(sortedColumn)) {
16588
+ const sortFunction = sortedColumn.sort;
16589
+ if (sortFunction) {
16590
+ const ascending = [...items].sort((a, b) => sortFunction(a, b, sortState.direction));
16591
+ if (sortState.direction === "descending") {
16592
+ return ascending.reverse();
16593
+ } else {
16594
+ return ascending;
16595
+ }
16596
+ }
16597
+ return items;
16598
+ } else {
16599
+ return items;
16600
+ }
16601
+ };
16602
+
16603
+ // src/utils/table/useSortState.ts
16543
16604
  import React130 from "react";
16605
+ var useSortState = (initialSortState) => React130.useState(initialSortState);
16606
+
16607
+ // src/utils/table/useTableSelect.ts
16608
+ import React131 from "react";
16544
16609
  var useTableSelect = (data, { key }) => {
16545
- const [selected, setSelected] = React130.useState([]);
16610
+ const [selected, setSelected] = React131.useState([]);
16546
16611
  const allSelected = selected.length === data.length;
16547
16612
  const isSelected = (dot) => selected.includes(dot[key]);
16548
16613
  const selectAll = () => setSelected(data.map((dot) => dot[key]));
@@ -16566,6 +16631,92 @@ var useTableSelect = (data, { key }) => {
16566
16631
  };
16567
16632
  };
16568
16633
 
16634
+ // src/molecules/ItemList/ItemList.tsx
16635
+ import React132 from "react";
16636
+ var ItemList = (_a) => {
16637
+ var _b = _a, {
16638
+ columns,
16639
+ items,
16640
+ onSortChanged,
16641
+ sticky
16642
+ } = _b, infiniteProps = __objRest(_b, [
16643
+ "columns",
16644
+ "items",
16645
+ "onSortChanged",
16646
+ "sticky"
16647
+ ]);
16648
+ const templateColumns = columns.map((column) => {
16649
+ var _a2;
16650
+ return (_a2 = column.width) != null ? _a2 : "auto";
16651
+ });
16652
+ const [sortState, setSortState] = useSortState();
16653
+ const sortedItems = onSortChanged ? items : sortByColumn(items, columns, sortState);
16654
+ return /* @__PURE__ */ React132.createElement(Template, {
16655
+ className: "Aquarium-ItemList",
16656
+ columns: templateColumns,
16657
+ role: "table"
16658
+ }, /* @__PURE__ */ React132.createElement(DataList.Row, {
16659
+ header: true
16660
+ }, columns.map((column) => {
16661
+ if (columnHasSort(column)) {
16662
+ return /* @__PURE__ */ React132.createElement(DataList.SortCell, __spreadValues({
16663
+ sticky,
16664
+ direction: (sortState == null ? void 0 : sortState.headerName) === column.headerName ? sortState.direction : "none",
16665
+ onClick: () => {
16666
+ const newState = sortState && sortState.headerName === column.headerName ? sortState.direction === "ascending" ? { headerName: column.headerName, direction: "descending" } : void 0 : { headerName: column.headerName, direction: "ascending" };
16667
+ setSortState(newState);
16668
+ onSortChanged == null ? void 0 : onSortChanged(newState);
16669
+ }
16670
+ }, cellProps(column)), column.headerName);
16671
+ }
16672
+ return /* @__PURE__ */ React132.createElement(DataList.HeadCell, __spreadProps(__spreadValues({}, cellProps(column)), {
16673
+ sticky
16674
+ }), column.headerName);
16675
+ })), /* @__PURE__ */ React132.createElement(Rows, __spreadValues({
16676
+ columns,
16677
+ items: sortedItems,
16678
+ level: 0
16679
+ }, infiniteProps)));
16680
+ };
16681
+ var Rows = (_a) => {
16682
+ var _b = _a, { columns, items, level, isLastGroup } = _b, infiniteProps = __objRest(_b, ["columns", "items", "level", "isLastGroup"]);
16683
+ return /* @__PURE__ */ React132.createElement(List, __spreadProps(__spreadValues({}, level === 0 ? infiniteProps : {}), {
16684
+ items,
16685
+ renderItem: (item, itemIndex) => {
16686
+ const hasSubItems = item.items && item.items.length > 0;
16687
+ const isLastItem = itemIndex === items.length - 1;
16688
+ const noDivider = level === 0 && isLastItem || level > 0 && (isLastGroup || !isLastItem) || hasSubItems;
16689
+ return /* @__PURE__ */ React132.createElement(React132.Fragment, {
16690
+ key: item.id
16691
+ }, /* @__PURE__ */ React132.createElement(DataList.Row, {
16692
+ noDivider
16693
+ }, /* @__PURE__ */ React132.createElement(List, {
16694
+ items: columns,
16695
+ renderItem: (column, columnIndex) => /* @__PURE__ */ React132.createElement(DataList.Cell, __spreadProps(__spreadValues({}, cellProps(column)), {
16696
+ style: level > 1 && columnIndex === 0 ? { paddingLeft: (level - 1) * 60 } : void 0
16697
+ }), level > 0 && columnIndex === 0 && /* @__PURE__ */ React132.createElement(DataList.TreeLine, {
16698
+ isLast: itemIndex === items.length - 1
16699
+ }), /* @__PURE__ */ React132.createElement(DataListCell, {
16700
+ column,
16701
+ row: item,
16702
+ index: columnIndex,
16703
+ rows: items
16704
+ }))
16705
+ })), item.items && /* @__PURE__ */ React132.createElement(WithGroup, {
16706
+ level
16707
+ }, /* @__PURE__ */ React132.createElement(Rows, {
16708
+ columns,
16709
+ items: item.items,
16710
+ level: level + 1,
16711
+ isLastGroup: level === 0 && itemIndex === items.length - 1 || isLastGroup
16712
+ })));
16713
+ }
16714
+ }));
16715
+ };
16716
+ var WithGroup = ({ level, children }) => level === 0 ? /* @__PURE__ */ React132.createElement(DataList.Row, {
16717
+ isGroup: true
16718
+ }, children) : children;
16719
+
16569
16720
  // src/molecules/index.ts
16570
16721
  var SelectItem = Select.Item;
16571
16722
 
@@ -16741,6 +16892,7 @@ export {
16741
16892
  InlineIcon,
16742
16893
  Input2 as Input,
16743
16894
  InputBase,
16895
+ ItemList,
16744
16896
  Label2 as Label,
16745
16897
  LabelControl,
16746
16898
  LineClamp2 as LineClamp,
@@ -16818,6 +16970,7 @@ export {
16818
16970
  calcTopPosition,
16819
16971
  calcTopRightPosition,
16820
16972
  cellProps,
16973
+ columnHasSort,
16821
16974
  columnIsFieldColumn,
16822
16975
  createComponent,
16823
16976
  createMountPointElement,
@@ -16828,10 +16981,12 @@ export {
16828
16981
  isOnSortChangedDirection,
16829
16982
  isOutOfBounds,
16830
16983
  placementOrder,
16984
+ sortByColumn,
16831
16985
  toSortDirection,
16832
16986
  usePagination,
16833
16987
  usePopoverContext,
16834
16988
  useScrollTarget,
16989
+ useSortState,
16835
16990
  useStaticInfiniteList,
16836
16991
  useTableSelect,
16837
16992
  useTableSort,