@deviceinsight/ng-ui-components 7.9.0 → 7.10.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.js CHANGED
@@ -1503,6 +1503,125 @@ function Pagination({ onChangePage, page, totalPages, onChangeSize, size }) {
1503
1503
  ) })
1504
1504
  ] }) });
1505
1505
  }
1506
+ function getSortedOptions(options, compareOptions) {
1507
+ if (!compareOptions) {
1508
+ return orderBy(options, "label", "asc");
1509
+ }
1510
+ if (options.every((option) => !option.options)) {
1511
+ const singleOptions = options;
1512
+ return [...singleOptions].sort(compareOptions);
1513
+ }
1514
+ if (options.every((option) => option.options)) {
1515
+ const groupOptions = options;
1516
+ return groupOptions.map((option) => ({ ...option, options: [...option.options].sort(compareOptions) }));
1517
+ }
1518
+ throw new Error("Mixing groups with single options not allowed");
1519
+ }
1520
+ class SelectWithSearch extends Component {
1521
+ constructor() {
1522
+ super(...arguments);
1523
+ this.state = {
1524
+ options: [],
1525
+ inputValue: null
1526
+ };
1527
+ this.selectRef = createRef();
1528
+ this.portalRoot = null;
1529
+ this.updateOptions = () => {
1530
+ const { options, specialOptions, compareOptions } = this.props;
1531
+ const sortedOptions = getSortedOptions(options, compareOptions);
1532
+ if (specialOptions) {
1533
+ this.setState({
1534
+ // @ts-ignore
1535
+ options: [...sortedOptions, ...specialOptions]
1536
+ });
1537
+ } else {
1538
+ this.setState({
1539
+ options: sortedOptions
1540
+ });
1541
+ }
1542
+ };
1543
+ this.filterOption = (option, inputValue) => {
1544
+ return option.label.toString().toLowerCase().startsWith(inputValue.toLowerCase());
1545
+ };
1546
+ this.getContainerClasses = () => {
1547
+ const { specialOptions } = this.props;
1548
+ if (specialOptions) {
1549
+ return ["select-search-container", "special"];
1550
+ }
1551
+ return ["select-search-container"];
1552
+ };
1553
+ }
1554
+ componentDidMount() {
1555
+ this.updateOptions();
1556
+ if (this.props["data-testid"] && this.selectRef && this.selectRef.current) {
1557
+ this.selectRef.current.controlRef.setAttribute("data-testid", this.props["data-testid"]);
1558
+ }
1559
+ if (this.props.menuPortalTarget) {
1560
+ this.portalRoot = document.createElement("div");
1561
+ const classes = this.getContainerClasses();
1562
+ this.portalRoot.classList.add(...classes);
1563
+ this.props.menuPortalTarget.appendChild(this.portalRoot);
1564
+ }
1565
+ }
1566
+ componentDidUpdate(prevProps) {
1567
+ if (!isEqual(prevProps.options, this.props.options) || prevProps.freeForm !== this.props.freeForm) {
1568
+ this.updateOptions();
1569
+ }
1570
+ }
1571
+ componentWillUnmount() {
1572
+ if (this.props.menuPortalTarget && this.portalRoot) {
1573
+ this.props.menuPortalTarget.removeChild(this.portalRoot);
1574
+ }
1575
+ }
1576
+ render() {
1577
+ const { noResultsMessage, placeholder, value, onChange, clearable, loading, disabled } = this.props;
1578
+ const { options } = this.state;
1579
+ return /* @__PURE__ */ jsx(
1580
+ Select,
1581
+ {
1582
+ ref: this.selectRef,
1583
+ joinValues: true,
1584
+ name: "form-field-name",
1585
+ className: this.getContainerClasses().join(" "),
1586
+ classNamePrefix: "select-search",
1587
+ isClearable: clearable,
1588
+ noOptionsMessage: noResultsMessage ? () => noResultsMessage : void 0,
1589
+ options,
1590
+ value: value || null,
1591
+ onChange,
1592
+ onInputChange: (newValue) => {
1593
+ if (this.props.freeForm && newValue) {
1594
+ this.setState({ inputValue: newValue });
1595
+ }
1596
+ },
1597
+ placeholder,
1598
+ filterOption: this.filterOption,
1599
+ isLoading: loading,
1600
+ menuPortalTarget: this.portalRoot,
1601
+ isDisabled: disabled,
1602
+ onBlur: () => {
1603
+ if (this.props.freeForm && this.state.inputValue !== null) {
1604
+ this.setState({ options: this.props.options });
1605
+ this.setState({ inputValue: this.state.inputValue }, () => {
1606
+ const newItem = {
1607
+ type: "item",
1608
+ value: this.state.inputValue,
1609
+ label: this.state.inputValue
1610
+ };
1611
+ this.setState(
1612
+ (prevState) => ({
1613
+ options: [newItem, ...prevState.options]
1614
+ })
1615
+ );
1616
+ this.state.inputValue = null;
1617
+ onChange(newItem);
1618
+ });
1619
+ }
1620
+ }
1621
+ }
1622
+ );
1623
+ }
1624
+ }
1506
1625
  const getInitialValueFromColumnDef = (columnDef) => {
1507
1626
  return columnDef.filterable?.initialValue ?? "";
1508
1627
  };
@@ -1623,125 +1742,6 @@ function extendColumnDefsWithCheckboxes(columnDefs, onSelectChange, onSelectAllC
1623
1742
  function getClassName(tableName, columnName) {
1624
1743
  return `${tableName || "unnamedTable"}-${columnName}`;
1625
1744
  }
1626
- function getSortedOptions(options, compareOptions) {
1627
- if (!compareOptions) {
1628
- return orderBy(options, "label", "asc");
1629
- }
1630
- if (options.every((option) => !option.options)) {
1631
- const singleOptions = options;
1632
- return [...singleOptions].sort(compareOptions);
1633
- }
1634
- if (options.every((option) => option.options)) {
1635
- const groupOptions = options;
1636
- return groupOptions.map((option) => ({ ...option, options: [...option.options].sort(compareOptions) }));
1637
- }
1638
- throw new Error("Mixing groups with single options not allowed");
1639
- }
1640
- class SelectWithSearch extends Component {
1641
- constructor() {
1642
- super(...arguments);
1643
- this.state = {
1644
- options: [],
1645
- inputValue: null
1646
- };
1647
- this.selectRef = createRef();
1648
- this.portalRoot = null;
1649
- this.updateOptions = () => {
1650
- const { options, specialOptions, compareOptions } = this.props;
1651
- const sortedOptions = getSortedOptions(options, compareOptions);
1652
- if (specialOptions) {
1653
- this.setState({
1654
- // @ts-ignore
1655
- options: [...sortedOptions, ...specialOptions]
1656
- });
1657
- } else {
1658
- this.setState({
1659
- options: sortedOptions
1660
- });
1661
- }
1662
- };
1663
- this.filterOption = (option, inputValue) => {
1664
- return option.label.toString().toLowerCase().startsWith(inputValue.toLowerCase());
1665
- };
1666
- this.getContainerClasses = () => {
1667
- const { specialOptions } = this.props;
1668
- if (specialOptions) {
1669
- return ["select-search-container", "special"];
1670
- }
1671
- return ["select-search-container"];
1672
- };
1673
- }
1674
- componentDidMount() {
1675
- this.updateOptions();
1676
- if (this.props["data-testid"] && this.selectRef && this.selectRef.current) {
1677
- this.selectRef.current.controlRef.setAttribute("data-testid", this.props["data-testid"]);
1678
- }
1679
- if (this.props.menuPortalTarget) {
1680
- this.portalRoot = document.createElement("div");
1681
- const classes = this.getContainerClasses();
1682
- this.portalRoot.classList.add(...classes);
1683
- this.props.menuPortalTarget.appendChild(this.portalRoot);
1684
- }
1685
- }
1686
- componentDidUpdate(prevProps) {
1687
- if (!isEqual(prevProps.options, this.props.options) || prevProps.freeForm !== this.props.freeForm) {
1688
- this.updateOptions();
1689
- }
1690
- }
1691
- componentWillUnmount() {
1692
- if (this.props.menuPortalTarget && this.portalRoot) {
1693
- this.props.menuPortalTarget.removeChild(this.portalRoot);
1694
- }
1695
- }
1696
- render() {
1697
- const { noResultsMessage, placeholder, value, onChange, clearable, loading, disabled } = this.props;
1698
- const { options } = this.state;
1699
- return /* @__PURE__ */ jsx(
1700
- Select,
1701
- {
1702
- ref: this.selectRef,
1703
- joinValues: true,
1704
- name: "form-field-name",
1705
- className: this.getContainerClasses().join(" "),
1706
- classNamePrefix: "select-search",
1707
- isClearable: clearable,
1708
- noOptionsMessage: noResultsMessage ? () => noResultsMessage : void 0,
1709
- options,
1710
- value: value || null,
1711
- onChange,
1712
- onInputChange: (newValue) => {
1713
- if (this.props.freeForm && newValue) {
1714
- this.setState({ inputValue: newValue });
1715
- }
1716
- },
1717
- placeholder,
1718
- filterOption: this.filterOption,
1719
- isLoading: loading,
1720
- menuPortalTarget: this.portalRoot,
1721
- isDisabled: disabled,
1722
- onBlur: () => {
1723
- if (this.props.freeForm && this.state.inputValue !== null) {
1724
- this.setState({ options: this.props.options });
1725
- this.setState({ inputValue: this.state.inputValue }, () => {
1726
- const newItem = {
1727
- type: "item",
1728
- value: this.state.inputValue,
1729
- label: this.state.inputValue
1730
- };
1731
- this.setState(
1732
- (prevState) => ({
1733
- options: [newItem, ...prevState.options]
1734
- })
1735
- );
1736
- this.state.inputValue = null;
1737
- onChange(newItem);
1738
- });
1739
- }
1740
- }
1741
- }
1742
- );
1743
- }
1744
- }
1745
1745
  const ReactableTableFilterRow = ({ columnDefs, onFilter, tableName }) => {
1746
1746
  const { t } = useTranslation();
1747
1747
  const [state, setState] = useState({});
@@ -1838,7 +1838,15 @@ const ReactableTableFilterRow = ({ columnDefs, onFilter, tableName }) => {
1838
1838
  );
1839
1839
  }
1840
1840
  };
1841
- return /* @__PURE__ */ jsx("tr", { className: "di filterrow form", children: columnDefs.map((columnDef) => /* @__PURE__ */ jsx("td", { style: { textAlign: columnDef.align || "left" }, children: getFilterByColumnDef(columnDef) }, columnDef.name)) });
1841
+ return /* @__PURE__ */ jsx("tr", { className: "di filterrow form", children: columnDefs.map((columnDef) => /* @__PURE__ */ jsx(
1842
+ "td",
1843
+ {
1844
+ className: getClassName(tableName, columnDef.name),
1845
+ style: { textAlign: columnDef.align || "left" },
1846
+ children: getFilterByColumnDef(columnDef)
1847
+ },
1848
+ columnDef.name
1849
+ )) });
1842
1850
  };
1843
1851
  const toggleSortDirection = (direction) => direction === "ASC" ? "DESC" : "ASC";
1844
1852
  class ReactableTableHeader extends Component {