-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1003 from akto-api-security/feature/persist_filters
Feature/persist filters
- Loading branch information
Showing
19 changed files
with
456 additions
and
289 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/tables/TableContext.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { createContext, useReducer, useContext } from "react"; | ||
import tableReducer, {initialState} from "./tableReducer"; | ||
|
||
const TableContext = createContext(initialState); | ||
|
||
export const TableContextProvider = ({ children }) => { | ||
const [state, dispatch] = useReducer(tableReducer, initialState); | ||
|
||
const applyFilter = (filter) => { | ||
dispatch({ | ||
type: "APPLY_FILTER", | ||
payload: { | ||
tabsInfo: filter | ||
} | ||
}); | ||
}; | ||
|
||
const value = { | ||
tabsInfo: state.tabsInfo, | ||
applyFilter, | ||
}; | ||
return <TableContext.Provider value={value}>{children}</TableContext.Provider>; | ||
}; | ||
|
||
const useTable = () => { | ||
const context = useContext(TableContext); | ||
|
||
if (context === undefined) { | ||
throw new Error("useTable must be used within TableContext"); | ||
} | ||
|
||
return context; | ||
}; | ||
|
||
export default useTable; |
21 changes: 21 additions & 0 deletions
21
apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/tables/tableReducer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import PersistStore from "../../../main/PersistStore"; | ||
const tableInitialState = PersistStore.getState().tableInitialState[window.location.href] || {} | ||
|
||
export const initialState = { | ||
tabsInfo : tableInitialState | ||
} | ||
|
||
const tableReducer = (state, action) =>{ | ||
const { type, payload } = action; | ||
switch (type) { | ||
case "APPLY_FILTER": | ||
return { | ||
...state, | ||
tabsInfo: payload.tabsInfo, | ||
}; | ||
default: | ||
return{...state} | ||
} | ||
} | ||
|
||
export default tableReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.