SAP / ui5-webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.
https://sap.github.io/ui5-webcomponents/
Apache License 2.0
1.56k stars 267 forks source link

feat(ui5-filter-item, ui5-sort-item,..): add selected `filterItems` to `ui5-confirm` event details #9838

Closed hinzzx closed 3 weeks ago

hinzzx commented 2 months ago

Previously, when confirming the selection in the View Settings Dialog, the visible UI text of the selected item was returned. However, this text doesn't always match the value required by the backend service for example, and it can also change due to translations or other factors, creating inconsistencies.

To address this, we are now providing the slotted ui5-filter-item's in the ui5-confirm event details.

This way the app developers could be able to selectively filter the selected items by property of their liking (for example by adding data-key (or similar) attribute/property to the ui5-filter-item-option's or ui5-filter-item's);

Sample usage:

    <h3>ViewSettingsDialog with dataset properties</h3>

    <ui5-button id="btnOpenDialogWithDataSet">Show ViewSettingsDialog</ui5-button>
    <ui5-view-settings-dialog id="vsdWithDataSet">
        <ui5-sort-item slot="sortItems" text="Name" data-key="sortName"></ui5-sort-item>
        <ui5-sort-item slot="sortItems" text="Position" data-key="sortPosition"></ui5-sort-item>
        <ui5-sort-item slot="sortItems" text="Company" data-key="sortCompany"></ui5-sort-item>

        <ui5-filter-item slot="filterItems" text="Category" data-key="filterCategory">
            <ui5-filter-item-option slot="values" text="Electronics" data-key="filterOptionElectronics" selected></ui5-filter-item-option>
            <ui5-filter-item-option slot="values" text="Clothing" data-key="filterOptionClothing"></ui5-filter-item-option>
        </ui5-filter-item>

        <ui5-filter-item slot="filterItems" text="Color" data-key="filterColor">
            <ui5-filter-item-option slot="values" text="Red" data-key="filterOptionRed"></ui5-filter-item-option>
            <ui5-filter-item-option slot="values" text="Blue" data-key="filterOptionBlue"></ui5-filter-item-option>
        </ui5-filter-item>

    </ui5-view-settings-dialog>

    <script>
        btnOpenDialogWithDataSet.addEventListener("click", function () {
            vsdWithDataSet.open = true;
        });

        vsdWithDataSet.addEventListener("ui5-confirm", function(e) {
            const filterItems = e.detail.filterItems || [];

            // Get the first selected filter and its selected item
            if (filterItems.length > 0 && filterItems[0].values.length > 0) {
                console.log("First Selected Filter: ", filterItems[0]);
                console.log("Selected item within the first filter: ", filterItems[0].values[0]);
                console.log("Selected item key within the first filter: ", filterItems[0].values[0].dataset.key);
            }
            alert("OK button clicked, returned info is: " + JSON.stringify(e.detail));
        });
</script>

Fixes: #7579 Fixes: #6910

hinzzx commented 2 months ago

In my opinion, it seems redundant to have first selected filters with all their options inside (no matter selected or not, but there is property for this), and second - the same list of just selected options. If there is no (easy) way to list just selected filter item (without its options), the second (selected options list) is maybe pointless.

Edit: After a discussion we decided to remove the second list.