@jobber/components 4.77.2-fixdatali.1 → 4.77.3

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.
@@ -31,13 +31,13 @@ export interface DataListObject {
31
31
  export type DataListHeader<T extends DataListObject> = {
32
32
  readonly [K in keyof T]?: string;
33
33
  };
34
- export interface DataListSorting extends SortableOptions {
34
+ export interface DataListSorting extends Partial<SortableOptions> {
35
35
  readonly key: string;
36
36
  }
37
37
  export interface SortableOptions {
38
- readonly id?: string;
39
- readonly label?: string;
40
- readonly order?: "asc" | "desc";
38
+ readonly id: string;
39
+ readonly label: string;
40
+ readonly order: "asc" | "desc";
41
41
  }
42
42
  export interface DataListProps<T extends DataListObject> {
43
43
  /**
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
- import { SortableOptions } from "../../../DataList.types";
2
+ import { DataListSorting, SortableOptions } from "../../../DataList.types";
3
3
  interface DataListSortingOptionsProps {
4
4
  readonly options: SortableOptions[];
5
- readonly selectedOption: SortableOptions | null;
5
+ readonly selectedOption: DataListSorting | null;
6
6
  readonly onSelectChange: (selectedOption: SortableOptions) => void;
7
7
  readonly onClose: () => void;
8
8
  readonly optionsListRef: React.RefObject<HTMLUListElement>;
@@ -339,28 +339,28 @@ function DataListHeaderTile({ headers, headerKey, visible = false, }) {
339
339
  const isSortable = Boolean(sortableItem);
340
340
  const sortingState = sorting === null || sorting === void 0 ? void 0 : sorting.state;
341
341
  const Tag = isSortable ? "button" : "div";
342
- const selectedOption = (sorting === null || sorting === void 0 ? void 0 : sorting.state) || null;
343
342
  return (React__default["default"].createElement(Tag, { className: classnames__default["default"](styles$a.headerLabel, {
344
343
  [styles$a.sortable]: isSortable,
345
344
  }), onClick: handleOnClick, ref: dataListHeaderTileRef },
346
345
  React__default["default"].createElement(Text.Text, { maxLines: "single" }, headers[headerKey]),
347
- isSortable && (sortableItem === null || sortableItem === void 0 ? void 0 : sortableItem.options) && isDropDownOpen && (React__default["default"].createElement(DataListSortingOptions, { options: sortableItem.options, selectedOption: selectedOption, onSelectChange: handleSelectChange, onClose: () => setIsDropDownOpen(false), optionsListRef: optionsListRef, dataListHeaderTileRef: dataListHeaderTileRef })),
346
+ isSortable && (sortableItem === null || sortableItem === void 0 ? void 0 : sortableItem.options) && isDropDownOpen && (React__default["default"].createElement(DataListSortingOptions, { options: sortableItem.options, selectedOption: (sorting === null || sorting === void 0 ? void 0 : sorting.state) || null, onSelectChange: handleSelectChange, onClose: () => setIsDropDownOpen(false), optionsListRef: optionsListRef, dataListHeaderTileRef: dataListHeaderTileRef })),
348
347
  (sortingState === null || sortingState === void 0 ? void 0 : sortingState.key) === headerKey ? (React__default["default"].createElement(DataListSortingArrows, { order: sortingState.order })) : (sortingState === null || sortingState === void 0 ? void 0 : sortingState.key) !== headerKey && isSortable ? (React__default["default"].createElement(DataListSortingArrows, { order: "none" })) : null));
349
- function toggleSorting(sortingKey, id, label, order) {
350
- const isSameKey = (sortingState === null || sortingState === void 0 ? void 0 : sortingState.label) === label && sortingKey === (sortingState === null || sortingState === void 0 ? void 0 : sortingState.key);
348
+ function toggleSorting(newSortingKey, newId, newLabel, newOrder) {
349
+ const isSameKey = newSortingKey === (sortingState === null || sortingState === void 0 ? void 0 : sortingState.key);
351
350
  const isDescending = (sortingState === null || sortingState === void 0 ? void 0 : sortingState.order) === "desc";
352
- if (isSameKey && isDescending && order !== "asc") {
353
- if (order === "desc")
354
- return;
351
+ if (isSameKey && isDescending && newOrder === undefined) {
355
352
  sorting === null || sorting === void 0 ? void 0 : sorting.onSort(undefined);
356
353
  return;
357
354
  }
358
- const sortingOrder = order || (isSameKey && !isDescending ? "desc" : "asc");
355
+ const sortingOrder = newOrder || (isSameKey && !isDescending ? "desc" : "asc");
356
+ setSorting(newSortingKey, newId, newLabel, sortingOrder);
357
+ }
358
+ function setSorting(newSortingKey, newId, newLabel, newOrder) {
359
359
  sorting === null || sorting === void 0 ? void 0 : sorting.onSort({
360
- key: sortingKey,
361
- id,
362
- label,
363
- order: sortingOrder,
360
+ key: newSortingKey,
361
+ id: newId,
362
+ label: newLabel,
363
+ order: newOrder,
364
364
  });
365
365
  }
366
366
  function handleOnClick() {
@@ -380,7 +380,7 @@ function DataListHeaderTile({ headers, headerKey, visible = false, }) {
380
380
  }
381
381
  function handleSelectChange(newSortOption) {
382
382
  if (sortableItem) {
383
- toggleSorting(sortableItem.key, newSortOption.id, newSortOption.label, newSortOption.order);
383
+ setSorting(sortableItem.key, newSortOption.id, newSortOption.label, newSortOption.order);
384
384
  }
385
385
  setIsDropDownOpen(true);
386
386
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jobber/components",
3
- "version": "4.77.2-fixdatali.1+f6f79546",
3
+ "version": "4.77.3",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -20,7 +20,7 @@
20
20
  ],
21
21
  "dependencies": {
22
22
  "@jobber/design": "^0.53.0",
23
- "@jobber/formatters": "^0.2.2",
23
+ "@jobber/formatters": "*",
24
24
  "@jobber/hooks": "^2.8.1",
25
25
  "@popperjs/core": "^2.0.6",
26
26
  "@std-proposal/temporal": "0.0.1",
@@ -84,5 +84,5 @@
84
84
  "> 1%",
85
85
  "IE 10"
86
86
  ],
87
- "gitHead": "f6f795462fdda0164727e5c9491f0da40fad04f1"
87
+ "gitHead": "0691129f73092a3143495c15965874d7956c91c1"
88
88
  }