Skip to content

Commit

Permalink
feat: allow third party plugin to add filters
Browse files Browse the repository at this point in the history
  • Loading branch information
David GABISON committed Aug 5, 2024
1 parent 5a2c198 commit 73e8b5d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/Views/Components/ListTable/Filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ export const Filter = ({filter, value = null, onChange, debouncedOnChange}) => {
};

// figure out what the initial filter state should be based on the filter configuration
export const getInitialFilterState = (filters) => {
export const getInitialFilterState = (filters, apiSettings) => {
const state = {};
const urlParams = new URLSearchParams(window.location.search);

// Allow third party extends filters
filters = wp.hooks.applyFilters(`give-${apiSettings.table.id}-list-table-filters`, filters);
filters.map((filter) => {
// if the search parameters contained a value for the filter, use that
const filterQuery = decodeURI(urlParams.get(filter.name));
Expand Down
2 changes: 1 addition & 1 deletion src/Views/Components/ListTable/ListTablePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function ListTablePage({
}: ListTablePageProps) {
const [page, setPage] = useState<number>(1);
const [perPage, setPerPage] = useState<number>(30);
const [filters, setFilters] = useState(getInitialFilterState(filterSettings));
const [filters, setFilters] = useState(getInitialFilterState(filterSettings, apiSettings));
const [modalContent, setModalContent] = useState<{confirm; action; label; type?: 'normal' | 'warning' | 'danger'}>({
confirm: (selected) => {},
action: (selected) => {},
Expand Down

0 comments on commit 73e8b5d

Please sign in to comment.