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

DataChangeEvent is not fired when GridListDataView#setFilter is called #5303

Open
TatuLund opened this issue Jul 31, 2023 · 3 comments · May be fixed by #5304
Open

DataChangeEvent is not fired when GridListDataView#setFilter is called #5303

TatuLund opened this issue Jul 31, 2023 · 3 comments · May be fixed by #5304

Comments

@TatuLund
Copy link
Contributor

TatuLund commented Jul 31, 2023

Description

DataChangeEvent is not fired when GridListDataView#setFilter is called. Note, the event is fired when filter is set via DataProvider instead. This should be analogous.

Expected outcome

Event is fired.

Minimal reproducible example

    @Test
    public void dataView_setFilter_methodsUseFilteredData() {
        AtomicInteger refreshed = new AtomicInteger(0);
        String[] items = new String[] { "item1", "item2", "item3", "item4" };
        Grid<String> grid = new Grid<>();
        GridListDataView<String> dataView = grid.setItems(items);
        grid.getDataProvider().addDataProviderListener(e -> {
            refreshed.incrementAndGet();
        });

        dataView.setFilter(s -> s.endsWith("4"));
        Assert.assertEquals("Filter change did not fire DataChangeEvent", 1,
                refreshed.get());

        Assert.assertEquals("Filter was not applied to data size", 1,
                dataView.getItemCount());

        Assert.assertTrue("Expected item is missing from filtered data",
                dataView.contains(items[3]));
        Assert.assertFalse(
                "Item that should be filtered out is available in the data",
                dataView.contains(items[1]));

        Assert.assertEquals("Wrong item on row for filtered data.", items[3],
                dataView.getItem(0));
    }

Steps to reproduce

Run the unit test

Environment

Vaadin version(s): Vaadin 24.1.4
OS:

Browsers

No response

@TatuLund TatuLund changed the title DataViewEvent is not fired when GridListDataView#setFilter is called DataChangeEvent is not fired when GridListDataView#setFilter is called Jul 31, 2023
@sissbruecker
Copy link
Contributor

Closing with the same reasoning provided here: #5304 (comment)

@TatuLund
Copy link
Contributor Author

TatuLund commented Aug 7, 2023

Note, the event is fired when filter is set via DataProvider instead. This should be analogous.

@sissbruecker according to justification setFilter implementation of DataProvider should then changed not to emit the event, right? Now there is discrepancy.

@sissbruecker
Copy link
Contributor

I mean, I would say yes, conceptually that doesn't make sense. But looking at the implementation that might not be possible and may also be undesirable as developers might rely on that event in that case. I'm also not sure if the inconsistency is a big problem that needs fixing, the data provider and data view APIs work differently, and the data provider implementation has a lot of baggage that can't be changed anymore.

But you're probably better off discussing this with the Flow team, maybe they have a different interpretation of data, data view and the data change event than I do. I'd suggest to create a ticket there to discuss the inconsistency and what the intended behavior is. If there is an outcome that requires changes to the components, then we're up for taking PRs for that.

@TatuLund TatuLund reopened this Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants