@deviceinsight/ng-ui-components 7.9.0 → 7.11.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
@@ -1522,6 +1522,127 @@ function Pagination({ onChangePage, page, totalPages, onChangeSize, size }) {
1522
1522
  ) })
1523
1523
  ] }) });
1524
1524
  }
1525
+ function getSortedOptions(options, compareOptions) {
1526
+ if (!compareOptions) {
1527
+ return lodash.orderBy(options, "label", "asc");
1528
+ }
1529
+ if (options.every((option) => !option.options)) {
1530
+ const singleOptions = options;
1531
+ return [...singleOptions].sort(compareOptions);
1532
+ }
1533
+ if (options.every((option) => option.options)) {
1534
+ const groupOptions = options;
1535
+ return groupOptions.map((option) => ({ ...option, options: [...option.options].sort(compareOptions) }));
1536
+ }
1537
+ throw new Error("Mixing groups with single options not allowed");
1538
+ }
1539
+ class SelectWithSearch extends React.Component {
1540
+ constructor() {
1541
+ super(...arguments);
1542
+ this.state = {
1543
+ options: [],
1544
+ inputValue: null
1545
+ };
1546
+ this.selectRef = React.createRef();
1547
+ this.portalRoot = null;
1548
+ this.updateOptions = () => {
1549
+ const { options, specialOptions, compareOptions } = this.props;
1550
+ const sortedOptions = getSortedOptions(options, compareOptions);
1551
+ if (specialOptions) {
1552
+ this.setState({
1553
+ // @ts-ignore
1554
+ options: [...sortedOptions, ...specialOptions]
1555
+ });
1556
+ } else {
1557
+ this.setState({
1558
+ options: sortedOptions
1559
+ });
1560
+ }
1561
+ };
1562
+ this.filterOption = (option, inputValue) => {
1563
+ return option.label.toString().toLowerCase().startsWith(inputValue.toLowerCase());
1564
+ };
1565
+ this.getContainerClasses = () => {
1566
+ const { specialOptions } = this.props;
1567
+ if (specialOptions) {
1568
+ return ["select-search-container", "special"];
1569
+ }
1570
+ return ["select-search-container"];
1571
+ };
1572
+ }
1573
+ componentDidMount() {
1574
+ this.updateOptions();
1575
+ if (this.props["data-testid"] && this.selectRef && this.selectRef.current) {
1576
+ this.selectRef.current.controlRef.setAttribute("data-testid", this.props["data-testid"]);
1577
+ }
1578
+ if (this.props.menuPortalTarget) {
1579
+ this.portalRoot = document.createElement("div");
1580
+ const classes = this.getContainerClasses();
1581
+ this.portalRoot.classList.add(...classes);
1582
+ this.props.menuPortalTarget.appendChild(this.portalRoot);
1583
+ }
1584
+ }
1585
+ componentDidUpdate(prevProps) {
1586
+ if (!lodash.isEqual(prevProps.options, this.props.options) || prevProps.freeForm !== this.props.freeForm) {
1587
+ this.updateOptions();
1588
+ }
1589
+ }
1590
+ componentWillUnmount() {
1591
+ if (this.props.menuPortalTarget && this.portalRoot) {
1592
+ this.props.menuPortalTarget.removeChild(this.portalRoot);
1593
+ }
1594
+ }
1595
+ render() {
1596
+ const { noResultsMessage, placeholder, value, onChange, clearable, loading, disabled } = this.props;
1597
+ const { options } = this.state;
1598
+ const dataTestId = this.props["data-testid"];
1599
+ return /* @__PURE__ */ jsxRuntime.jsx(
1600
+ Select,
1601
+ {
1602
+ ref: this.selectRef,
1603
+ joinValues: true,
1604
+ name: "form-field-name",
1605
+ className: this.getContainerClasses().join(" "),
1606
+ classNamePrefix: "select-search",
1607
+ isClearable: clearable,
1608
+ noOptionsMessage: noResultsMessage ? () => noResultsMessage : void 0,
1609
+ options,
1610
+ value: value || null,
1611
+ onChange,
1612
+ onInputChange: (newValue) => {
1613
+ if (this.props.freeForm && newValue) {
1614
+ this.setState({ inputValue: newValue });
1615
+ }
1616
+ },
1617
+ placeholder,
1618
+ filterOption: this.filterOption,
1619
+ isLoading: loading,
1620
+ menuPortalTarget: this.portalRoot,
1621
+ isDisabled: disabled,
1622
+ formatOptionLabel: dataTestId ? (option) => /* @__PURE__ */ jsxRuntime.jsx("span", { "data-testid": `${dataTestId}-option-${option.label}`, children: option.label }) : void 0,
1623
+ onBlur: () => {
1624
+ if (this.props.freeForm && this.state.inputValue !== null) {
1625
+ this.setState({ options: this.props.options });
1626
+ this.setState({ inputValue: this.state.inputValue }, () => {
1627
+ const newItem = {
1628
+ type: "item",
1629
+ value: this.state.inputValue,
1630
+ label: this.state.inputValue
1631
+ };
1632
+ this.setState(
1633
+ (prevState) => ({
1634
+ options: [newItem, ...prevState.options]
1635
+ })
1636
+ );
1637
+ this.state.inputValue = null;
1638
+ onChange(newItem);
1639
+ });
1640
+ }
1641
+ }
1642
+ }
1643
+ );
1644
+ }
1645
+ }
1525
1646
  const getInitialValueFromColumnDef = (columnDef) => {
1526
1647
  return columnDef.filterable?.initialValue ?? "";
1527
1648
  };
@@ -1642,125 +1763,6 @@ function extendColumnDefsWithCheckboxes(columnDefs, onSelectChange, onSelectAllC
1642
1763
  function getClassName(tableName, columnName) {
1643
1764
  return `${tableName || "unnamedTable"}-${columnName}`;
1644
1765
  }
1645
- function getSortedOptions(options, compareOptions) {
1646
- if (!compareOptions) {
1647
- return lodash.orderBy(options, "label", "asc");
1648
- }
1649
- if (options.every((option) => !option.options)) {
1650
- const singleOptions = options;
1651
- return [...singleOptions].sort(compareOptions);
1652
- }
1653
- if (options.every((option) => option.options)) {
1654
- const groupOptions = options;
1655
- return groupOptions.map((option) => ({ ...option, options: [...option.options].sort(compareOptions) }));
1656
- }
1657
- throw new Error("Mixing groups with single options not allowed");
1658
- }
1659
- class SelectWithSearch extends React.Component {
1660
- constructor() {
1661
- super(...arguments);
1662
- this.state = {
1663
- options: [],
1664
- inputValue: null
1665
- };
1666
- this.selectRef = React.createRef();
1667
- this.portalRoot = null;
1668
- this.updateOptions = () => {
1669
- const { options, specialOptions, compareOptions } = this.props;
1670
- const sortedOptions = getSortedOptions(options, compareOptions);
1671
- if (specialOptions) {
1672
- this.setState({
1673
- // @ts-ignore
1674
- options: [...sortedOptions, ...specialOptions]
1675
- });
1676
- } else {
1677
- this.setState({
1678
- options: sortedOptions
1679
- });
1680
- }
1681
- };
1682
- this.filterOption = (option, inputValue) => {
1683
- return option.label.toString().toLowerCase().startsWith(inputValue.toLowerCase());
1684
- };
1685
- this.getContainerClasses = () => {
1686
- const { specialOptions } = this.props;
1687
- if (specialOptions) {
1688
- return ["select-search-container", "special"];
1689
- }
1690
- return ["select-search-container"];
1691
- };
1692
- }
1693
- componentDidMount() {
1694
- this.updateOptions();
1695
- if (this.props["data-testid"] && this.selectRef && this.selectRef.current) {
1696
- this.selectRef.current.controlRef.setAttribute("data-testid", this.props["data-testid"]);
1697
- }
1698
- if (this.props.menuPortalTarget) {
1699
- this.portalRoot = document.createElement("div");
1700
- const classes = this.getContainerClasses();
1701
- this.portalRoot.classList.add(...classes);
1702
- this.props.menuPortalTarget.appendChild(this.portalRoot);
1703
- }
1704
- }
1705
- componentDidUpdate(prevProps) {
1706
- if (!lodash.isEqual(prevProps.options, this.props.options) || prevProps.freeForm !== this.props.freeForm) {
1707
- this.updateOptions();
1708
- }
1709
- }
1710
- componentWillUnmount() {
1711
- if (this.props.menuPortalTarget && this.portalRoot) {
1712
- this.props.menuPortalTarget.removeChild(this.portalRoot);
1713
- }
1714
- }
1715
- render() {
1716
- const { noResultsMessage, placeholder, value, onChange, clearable, loading, disabled } = this.props;
1717
- const { options } = this.state;
1718
- return /* @__PURE__ */ jsxRuntime.jsx(
1719
- Select,
1720
- {
1721
- ref: this.selectRef,
1722
- joinValues: true,
1723
- name: "form-field-name",
1724
- className: this.getContainerClasses().join(" "),
1725
- classNamePrefix: "select-search",
1726
- isClearable: clearable,
1727
- noOptionsMessage: noResultsMessage ? () => noResultsMessage : void 0,
1728
- options,
1729
- value: value || null,
1730
- onChange,
1731
- onInputChange: (newValue) => {
1732
- if (this.props.freeForm && newValue) {
1733
- this.setState({ inputValue: newValue });
1734
- }
1735
- },
1736
- placeholder,
1737
- filterOption: this.filterOption,
1738
- isLoading: loading,
1739
- menuPortalTarget: this.portalRoot,
1740
- isDisabled: disabled,
1741
- onBlur: () => {
1742
- if (this.props.freeForm && this.state.inputValue !== null) {
1743
- this.setState({ options: this.props.options });
1744
- this.setState({ inputValue: this.state.inputValue }, () => {
1745
- const newItem = {
1746
- type: "item",
1747
- value: this.state.inputValue,
1748
- label: this.state.inputValue
1749
- };
1750
- this.setState(
1751
- (prevState) => ({
1752
- options: [newItem, ...prevState.options]
1753
- })
1754
- );
1755
- this.state.inputValue = null;
1756
- onChange(newItem);
1757
- });
1758
- }
1759
- }
1760
- }
1761
- );
1762
- }
1763
- }
1764
1766
  const ReactableTableFilterRow = ({ columnDefs, onFilter, tableName }) => {
1765
1767
  const { t } = useTranslation();
1766
1768
  const [state, setState] = React.useState({});
@@ -1857,7 +1859,15 @@ const ReactableTableFilterRow = ({ columnDefs, onFilter, tableName }) => {
1857
1859
  );
1858
1860
  }
1859
1861
  };
1860
- return /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "di filterrow form", children: columnDefs.map((columnDef) => /* @__PURE__ */ jsxRuntime.jsx("td", { style: { textAlign: columnDef.align || "left" }, children: getFilterByColumnDef(columnDef) }, columnDef.name)) });
1862
+ return /* @__PURE__ */ jsxRuntime.jsx("tr", { className: "di filterrow form", children: columnDefs.map((columnDef) => /* @__PURE__ */ jsxRuntime.jsx(
1863
+ "td",
1864
+ {
1865
+ className: getClassName(tableName, columnDef.name),
1866
+ style: { textAlign: columnDef.align || "left" },
1867
+ children: getFilterByColumnDef(columnDef)
1868
+ },
1869
+ columnDef.name
1870
+ )) });
1861
1871
  };
1862
1872
  const toggleSortDirection = (direction) => direction === "ASC" ? "DESC" : "ASC";
1863
1873
  class ReactableTableHeader extends React.Component {
@@ -2758,6 +2768,7 @@ class SelectWithSearchAsync extends React.Component {
2758
2768
  render() {
2759
2769
  const { clearable, noResultsMessage, disabled, menuPortalTarget } = this.props;
2760
2770
  const { currentItem } = this.state;
2771
+ const dataTestId = this.props["data-testid"];
2761
2772
  return /* @__PURE__ */ jsxRuntime.jsx(
2762
2773
  reactSelectAsyncPaginate.AsyncPaginate,
2763
2774
  {
@@ -2771,7 +2782,8 @@ class SelectWithSearchAsync extends React.Component {
2771
2782
  loadOptions: this.fetchOptions,
2772
2783
  isDisabled: disabled,
2773
2784
  menuPortalTarget,
2774
- placeholder: this.props.placeholder
2785
+ placeholder: this.props.placeholder,
2786
+ formatOptionLabel: dataTestId ? (option) => /* @__PURE__ */ jsxRuntime.jsx("span", { "data-testid": `${dataTestId}-option-${option.label}`, children: option.label }) : void 0
2775
2787
  }
2776
2788
  );
2777
2789
  }