daisycrego / jbg-admin

Admin app for Jill Biggs Group follow-up boss event management
1 stars 0 forks source link

Events Table - Filter source #16

Closed daisycrego closed 3 years ago

daisycrego commented 3 years ago
daisycrego commented 3 years ago

Minor issue

daisycrego commented 3 years ago
daisycrego commented 3 years ago

Issue

Reproduce the Issue

What should happen

What does happen

daisycrego commented 3 years ago

Problem

// ...

React.useEffect(() => { // Extract property.street from property object (for sorting) const rowsWithPropertyStreet = rows.map((event) => { if (event.property && event.property.street) { event.propertyStreet = event.property.street; } else { event.propertyStreet = ""; } return event; }); const rowsWithActiveSource = rowsWithPropertyStreet.filter((row) => activeSources.includes(row.source) );

const active = stableSort( rowsWithActiveSource, getComparator(order, orderBy) ).slice(page rowsPerPage, page rowsPerPage + rowsPerPage); const allSources = rows.map((row) => row.source).filter((x) => x); const uniqueSources = _.uniq(allSources); setSources(uniqueSources); setActiveRows(rowsWithActiveSource); setCurrentRows(active); }, [rows, order]);

// ...

const handleChangePage = (event, newPage) => { setPage(newPage); const newActiveRows = activeRows.slice( newPage rowsPerPage, newPage rowsPerPage + rowsPerPage ); setActiveRows(newActiveRows); };


## Found it
- Needed to change `handleChangePage` to this:
```js
 const handleChangePage = (event, newPage) => {
    setPage(newPage);
    const newActiveRows = activeRows.slice(
      newPage * rowsPerPage,
      newPage * rowsPerPage + rowsPerPage
    );
    setCurrentRows(newActiveRows);
  };
daisycrego commented 3 years ago

New issue with the table

Reproduce the issue

Change the source to include a bunch of events by adding a large lead source (e.g. Ylopo) to the default (Zillow Flex). Page through the results many pages (the error in my case occured at page 23->24). Now that you're at this advanced page, change the sources again -> Remove the large lead source (eg Ylopo))

What should happen

List of activeEvents and currentEvents should be updated correctly so that we see the first page of the revised set of sources! This means when we update source, we need to update pagination! This is the fix, need to implement it.

What does happen

When source is changed, pagination isn't updated appropriately.

daisycrego commented 3 years ago

Solution

Whenever we update the source by clicking a checkbox, make sure to reset the page to 0:

const handleCheckboxClick = (source) => {
  let newActiveSources;
  if (activeSources.includes(source)) {
    newActiveSources = activeSources.filter(
      (activeSource) => activeSource != source
    );
  } else {
    newActiveSources = [...activeSources, source];
  }
  setActiveSources(newActiveSources);
  const rowsWithActiveSource = rows.filter((row) =>
    newActiveSources.includes(row.source)
  );
  const newActiveRows = stableSort(
    rowsWithActiveSource,
    getComparator(order, orderBy)
  );
  const newPage = 0;
  setActiveRows(newActiveRows);
  setCurrentRows(
    newActiveRows.slice(
      newPage * rowsPerPage,
      newPage * rowsPerPage + rowsPerPage
    )
  );
  setPage(0);
};
daisycrego commented 3 years ago

More features

3 new buttons:

daisycrego commented 3 years ago

Options:

import DoneAllIcon from '@material-ui/icons/DoneAll';
daisycrego commented 3 years ago

Refactor - Allow similar filtering by Status