@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 +133 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +133 -121
- package/dist/index.js.map +1 -1
- package/dist/types/components/input/SelectWithSearch.d.ts.map +1 -1
- package/dist/types/components/input/SelectWithSearchAsync.d.ts.map +1 -1
- package/dist/types/components/reactable/helpers/ReactableTableFilterRow.d.ts.map +1 -1
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -1503,6 +1503,127 @@ 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
|
+
const dataTestId = this.props["data-testid"];
|
|
1580
|
+
return /* @__PURE__ */ jsx(
|
|
1581
|
+
Select,
|
|
1582
|
+
{
|
|
1583
|
+
ref: this.selectRef,
|
|
1584
|
+
joinValues: true,
|
|
1585
|
+
name: "form-field-name",
|
|
1586
|
+
className: this.getContainerClasses().join(" "),
|
|
1587
|
+
classNamePrefix: "select-search",
|
|
1588
|
+
isClearable: clearable,
|
|
1589
|
+
noOptionsMessage: noResultsMessage ? () => noResultsMessage : void 0,
|
|
1590
|
+
options,
|
|
1591
|
+
value: value || null,
|
|
1592
|
+
onChange,
|
|
1593
|
+
onInputChange: (newValue) => {
|
|
1594
|
+
if (this.props.freeForm && newValue) {
|
|
1595
|
+
this.setState({ inputValue: newValue });
|
|
1596
|
+
}
|
|
1597
|
+
},
|
|
1598
|
+
placeholder,
|
|
1599
|
+
filterOption: this.filterOption,
|
|
1600
|
+
isLoading: loading,
|
|
1601
|
+
menuPortalTarget: this.portalRoot,
|
|
1602
|
+
isDisabled: disabled,
|
|
1603
|
+
formatOptionLabel: dataTestId ? (option) => /* @__PURE__ */ jsx("span", { "data-testid": `${dataTestId}-option-${option.label}`, children: option.label }) : void 0,
|
|
1604
|
+
onBlur: () => {
|
|
1605
|
+
if (this.props.freeForm && this.state.inputValue !== null) {
|
|
1606
|
+
this.setState({ options: this.props.options });
|
|
1607
|
+
this.setState({ inputValue: this.state.inputValue }, () => {
|
|
1608
|
+
const newItem = {
|
|
1609
|
+
type: "item",
|
|
1610
|
+
value: this.state.inputValue,
|
|
1611
|
+
label: this.state.inputValue
|
|
1612
|
+
};
|
|
1613
|
+
this.setState(
|
|
1614
|
+
(prevState) => ({
|
|
1615
|
+
options: [newItem, ...prevState.options]
|
|
1616
|
+
})
|
|
1617
|
+
);
|
|
1618
|
+
this.state.inputValue = null;
|
|
1619
|
+
onChange(newItem);
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
);
|
|
1625
|
+
}
|
|
1626
|
+
}
|
|
1506
1627
|
const getInitialValueFromColumnDef = (columnDef) => {
|
|
1507
1628
|
return columnDef.filterable?.initialValue ?? "";
|
|
1508
1629
|
};
|
|
@@ -1623,125 +1744,6 @@ function extendColumnDefsWithCheckboxes(columnDefs, onSelectChange, onSelectAllC
|
|
|
1623
1744
|
function getClassName(tableName, columnName) {
|
|
1624
1745
|
return `${tableName || "unnamedTable"}-${columnName}`;
|
|
1625
1746
|
}
|
|
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
1747
|
const ReactableTableFilterRow = ({ columnDefs, onFilter, tableName }) => {
|
|
1746
1748
|
const { t } = useTranslation();
|
|
1747
1749
|
const [state, setState] = useState({});
|
|
@@ -1838,7 +1840,15 @@ const ReactableTableFilterRow = ({ columnDefs, onFilter, tableName }) => {
|
|
|
1838
1840
|
);
|
|
1839
1841
|
}
|
|
1840
1842
|
};
|
|
1841
|
-
return /* @__PURE__ */ jsx("tr", { className: "di filterrow form", children: columnDefs.map((columnDef) => /* @__PURE__ */ jsx(
|
|
1843
|
+
return /* @__PURE__ */ jsx("tr", { className: "di filterrow form", children: columnDefs.map((columnDef) => /* @__PURE__ */ jsx(
|
|
1844
|
+
"td",
|
|
1845
|
+
{
|
|
1846
|
+
className: getClassName(tableName, columnDef.name),
|
|
1847
|
+
style: { textAlign: columnDef.align || "left" },
|
|
1848
|
+
children: getFilterByColumnDef(columnDef)
|
|
1849
|
+
},
|
|
1850
|
+
columnDef.name
|
|
1851
|
+
)) });
|
|
1842
1852
|
};
|
|
1843
1853
|
const toggleSortDirection = (direction) => direction === "ASC" ? "DESC" : "ASC";
|
|
1844
1854
|
class ReactableTableHeader extends Component {
|
|
@@ -2739,6 +2749,7 @@ class SelectWithSearchAsync extends Component {
|
|
|
2739
2749
|
render() {
|
|
2740
2750
|
const { clearable, noResultsMessage, disabled, menuPortalTarget } = this.props;
|
|
2741
2751
|
const { currentItem } = this.state;
|
|
2752
|
+
const dataTestId = this.props["data-testid"];
|
|
2742
2753
|
return /* @__PURE__ */ jsx(
|
|
2743
2754
|
AsyncPaginate,
|
|
2744
2755
|
{
|
|
@@ -2752,7 +2763,8 @@ class SelectWithSearchAsync extends Component {
|
|
|
2752
2763
|
loadOptions: this.fetchOptions,
|
|
2753
2764
|
isDisabled: disabled,
|
|
2754
2765
|
menuPortalTarget,
|
|
2755
|
-
placeholder: this.props.placeholder
|
|
2766
|
+
placeholder: this.props.placeholder,
|
|
2767
|
+
formatOptionLabel: dataTestId ? (option) => /* @__PURE__ */ jsx("span", { "data-testid": `${dataTestId}-option-${option.label}`, children: option.label }) : void 0
|
|
2756
2768
|
}
|
|
2757
2769
|
);
|
|
2758
2770
|
}
|