Our powerful JS Calendar component


Post by droptableusers »

Dear Bryntum,

We should find a solution for the following use case. Our users only have access to different Resources, so we wrote a chanedFilter in the store part of the ResourceField item of the EventEditFeature, as show in the first picture.
Unforunately, Calendar reacted to this by adding a number 1 if someone does not have access to the first Resource. As the second picture shows.

Do you have any idea how to solve the problem? We tried to fill in the value, but unforunately it didn't work.

I really appreciate your answer.

Best Regards,
Adri

Attachments
2.png
2.png (37.06 KiB) Viewed 304 times
1.png
1.png (72.08 KiB) Viewed 304 times

Post by tasnim »

Hi,

As you're store is empty it will not work with the chainedStoreFn. You'd need to assign a masterStore to it.
https://bryntum.com/products/calendar/docs/api/Core/data/mixin/StoreChained#config-masterStore

Please check chained store docs https://bryntum.com/products/calendar/docs/api/Core/data/mixin/StoreChained

Hope this helps.

Best regards,
Tasnim


Post by droptableusers »

Hey Tasnim,

It seems that when we filter the store, it's not actually empty. All users can access at least one resource, so that's not an issue. However, we have a Resource List [R1, R2, R3, R4], and when we filter by R1, the resource appears, but only as the number "1" instead of its name. Filtering other resources like R3 works properly.

I attempted your solution, but it didn't resolve the issue. Here's what I understand:

store: new Store({
    masterStore: resourceStore,
    chainedFilterFn(record) {
        if (user?.hasRole(Role.ADMIN)) {
            return true;
        }
        const resourceRoles = record.getData('role').split(',');
        const resourceGroup = record.getData('group');
        for (const role of resourceRoles) {
            if (user?.hasRole(role as Role)) {
                if (!resourceGroup) {
                    return true;
                }
                if (user?.isInGroup(resourceGroup)) {
                    return true;
                }
            }
        }
        return false;
    },
}),

I believe the main issue is that the ResourceField loads the default Store initially. If we define a new Store for it, the default store is overwritten, but the first element of the store is saved as the default value. Since this item isn't available in the new Store, it only displays the ID.

Please let me know if I misunderstood anything.

I really appreciate your comments.

Best Regards,
Adri

Attachments
1.png
1.png (40.03 KiB) Viewed 252 times

Post by Animal »

What does the config setup of that field look like?

Are you reconfiguring the existing resource field, or adding a new combo? Combo's need to know which field of the record to use as the filter match value when typing. See valueField in the combo docs


Post by droptableusers »

Dear Animal,

Please find the code snippet that contains the our ResourceField implementation:

<BryntumCalendar
    ref={calendar}
    crudManager={{
        eventStore: eventStore,
        resourceStore: resourceStore,
    }}
    mode='agenda'
    modes={{
        week: {
            eventRenderer,
        },
        day: {
            eventRenderer,
        },
        agenda: {
            .....
        }
    }}
    sidebar={{
        ....
    }}
    eventTooltipFeature={{
        ....
    }}
    eventMenuFeature={{
        ....
    }}
    eventEditFeature={{
        editorConfig: {
            modal: true,
        },
        items: {
            resourceField: {
                name: 'resourceId',
                type: 'resourcecombo',
                label: 'Naptár',
                weight: 100,
                showEventColor: true,
                multiSelect: false,
                store: {
                    chainedFilterFn: (resource: any) => {
                        if (user?.hasRole(Role.ADMIN)) {
                            return true;
                        }
                        const resourceRoles = resource.getData('role').split(",");
                        const resourceGroup = resource.getData('group');
                        for (const role of resourceRoles) {
                            if (user?.hasRole(role as Role)) {
                                if (!resourceGroup) {
                                    return true;
                                }
                                if (user?.isInGroup(resourceGroup)) {
                                    return true;
                                }
                            }
                        }
                        return false;
                    },
                },
                listeners: {
                    change: (event: any) => {
                        const { source, value } = event;
                        const resource = resourceStore.getById(value);
                        const entityType = resource.getData('entityType');
                        const defaultAvailability = resource.getData('defaultAvailability');
                        source.owner.items.forEach((widget: any) => {
                            ....
                        });
                    },
                },
            },
            ...
        },
    }}
/>

I really appreciate your comment.

Best Regards,
Adri


Post by Animal »

Cleaning up the indentation to make it quickly readable, I added it to the "Basic" example making the filtering function sipler. It just doesn't offer the "Michael Johnson" resource.

It works as expected:

Screenshot 2024-08-13 at 15.39.21.png
Screenshot 2024-08-13 at 15.39.21.png (895.46 KiB) Viewed 215 times

Post by droptableusers »

Hey Animal,

I mentioned, the problem is comming when we need to filtering the first resource. So your example you need to filter the 'Bryntum Team' Resource, then you can see when you click to create a new Event, its showing the 'bryntum' word but its not a real Resource.

Please find the picture which representing the problem. In picture you can see, in EventEdit modal its Resource showing the 'bryntum' but this resource is filtered.

I really appreciate you comment.

Best Regards,
Adri

Attachments
3.png
3.png (206.15 KiB) Viewed 209 times

Post by Animal »

Sorry, I don't understand what you mean. In that modified example, "basic", I can't make anything unexpected happen.

It's just a Combo which only offers "Hotel Park" and "Bryntum team" now because it rejects "Michael Johnson" from the master ResourceStore.


Post by Animal »

I mean obviously if you then edit an event assigned to a resource it doesn't know about, it's never going to work. How could it?


Post by Animal »

So yes, if I edit an event for Michael Johnson, the store has no match. Because we actually asked for it not to be there, so it can't display it.

That's what just will happen.

Screenshot 2024-08-13 at 16.21.16.png
Screenshot 2024-08-13 at 16.21.16.png (278.74 KiB) Viewed 201 times

Post Reply