Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResourceFilter in Sidebar should be configurable with custom selection #2006

Closed
pmiklashevych opened this issue Nov 30, 2020 · 3 comments
Closed
Assignees
Labels
feature request resolved Fixed but not yet released (available in the nightly builds)
Milestone

Comments

@pmiklashevych
Copy link

pmiklashevych commented Nov 30, 2020

Requested here:
https://www.bryntum.com/forum/viewtopic.php?p=79899#p79899
https://www.bryntum.com/forum/viewtopic.php?p=81630#p81630
https://www.bryntum.com/forum/viewtopic.php?f=51&t=19959

It should be possible to check some of resources by default instead of the whole dataset.

Workaround:
Calendar/examples/basic/app.js

import ResourceFilter from '../../lib/Scheduler/widget/ResourceFilter.js';

class MyResourceFilter extends ResourceFilter {
    static get $name() {
        return 'MyResourceFilter';
    }

    // Factoryable type name
    static get type() {
        return 'myresourcefilter';
    }

    // PRIVATE FUNCTION OVERRIDDEN
    initFilter() {
        const { eventStore } = this;

        if (eventStore.count && eventStore.resourceStore.count) {
            // SELECT THE RECORDS YOU NEED
            // this.selected.add(this.store.getRange());
            this.selected.add(this.store.first);
            this.detachListeners('project');
        }
    }
    
    // PRIVATE FUNCTION OVERRIDDEN
    onSelectionChange({ source : selected }) {
        const
            applyFirstFilter = !this.resourceFilter,
            disabled         = selected.count === this.eventStore.resourceStore.count;

        super.onSelectionChange(...arguments);

        // REQUIRED TO APPLY FIRST TIME BECAUSE FIRST FILTER IS APPLIED SILENTLY BY DEFAULT
        if (applyFirstFilter && this.resourceFilter) {
            // Filter disabled if all resources selected
            this.resourceFilter.disabled = disabled;
            // Have the client EventStore refresh its filtering but after a small delay so the List UI updates immediately.
            this.applyFilter();
        }
    }
}
// Register this widget type with its Factory
MyResourceFilter.initClass();

const calendar = new Calendar({
    sidebar : {
        items : {
            resourceFilter : {
                type : 'myresourcefilter'
            }
        }
    },
@pmiklashevych
Copy link
Author

Also describe names of https://www.bryntum.com/docs/calendar/#Calendar/widget/Sidebar named items.

@isglass isglass added this to the 4.0.x milestone Dec 1, 2020
@ExtAnimal
Copy link

I think the solution is to fix the selected config in List.

If what is passed is an Array, then take it to be the requested initial selection.

So there will be a changeSelected

Right now updateSelected is incorrect in that it upgrades an incoming value to the final state, but that is the job of a changer:

            /**
             * A {@link Core.util.Collection Collection}, or Collection config object, or array of records
             * to use to use as this List's selected records.
             * @config {Core.util.Collection|Object|Object[]}
             */
            selected : {},

...

    changeSelected(selected) {
        if (selected) {
            if (Array.isArray(selected)) {
                selected = { values : selected };
            }
        }
        if (!selected.isCollection) {
            selected = new Collection(selected);
        }
        return selected;
    }

    updateSelected(selected) {
        selected.on({
            change  : 'onSelectionChange',
            thisObj : this
        });
    }

Then in ResourceFilter

    initFilter() {
        const
            me              = this,
            {
                eventStore,
                store,
                selected
            }                = me,
            initialSelection = me.initialConfig.selected;

        if (eventStore.count && eventStore.resourceStore.count) {
            if (initialSelection) {
                selected.splice(0, selected.count, initialSelection.map(s => store.storage.get(s.id, true) || s));
                me.onSelectionChange({ source : selected, removed : [], added : [] });
                me.applyFilter();
            }
            else {
                selected.add(store.getRange());
            }
            me.detachListeners('project');
        }
    }

Then in one of the examples, illustrate it by configuring the sidebar:

sidebar : {
    items : {
        resourceFilter : {
            // ids are matched. We don't need to have access to the record now
            selected : [{ id : 'bryntum' }]
        }
    }
},

@isglass isglass modified the milestones: 4.0.x, 4.0.7 Jan 8, 2021
@SergeyMaltsev SergeyMaltsev modified the milestones: 4.0.7, 4.0.8 Jan 12, 2021
@pmiklashevych pmiklashevych modified the milestones: 4.0.8, 4.1.0 Jan 22, 2021
@isglass isglass modified the milestones: 4.1.0, 4.2.0 Feb 1, 2021
@ExtAnimal
Copy link

Note that the initial election should be allowed to be [] to mean none.

This request asks for there to be non selected initially: https://www.bryntum.com/forum/viewtopic.php?f=54&t=16564&p=82434#p82434

Seems strange since that will result in no events being displayed, but, [] is technically valid for selection.

@matsbryntse matsbryntse removed this from the 4.2.0 milestone Jun 22, 2021
@isglass isglass added this to the 5.1 milestone Jan 7, 2022
@ExtAnimal ExtAnimal modified the milestones: 5.1, 5.0.2 Mar 24, 2022
@ExtAnimal ExtAnimal self-assigned this Mar 24, 2022
@ExtAnimal ExtAnimal added in progress ready for review Issue is fixed, the pull request is being reviewed resolved Fixed but not yet released (available in the nightly builds) and removed in progress ready for review Issue is fixed, the pull request is being reviewed labels Mar 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request resolved Fixed but not yet released (available in the nightly builds)
Projects
None yet
Development

No branches or pull requests

5 participants