This repository was archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
1401 admin UI persist redux store to localstorage #1409
Merged
chriscalhoun1974
merged 7 commits into
main
from
1401-admin-ui-persist-redux-store-to-localstorage
Oct 2, 2022
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aa7ddc9
1401 - Admin UI: Persist Redux store to localStorage
chriscalhoun1974 8248e3c
Resolved React memory leak when user attempts to logout via the Subje…
chriscalhoun1974 bb3e469
Merge branch 'main' into 1401-admin-ui-persist-redux-store-to-localst…
chriscalhoun1974 02b3804
Resolved UI unit test failure
chriscalhoun1974 eddad34
Rollback previous change
chriscalhoun1974 599a264
Removed blacklist property from Redux store config
chriscalhoun1974 b9eec25
Refactored due to recommended code review feedback
chriscalhoun1974 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
42 changes: 0 additions & 42 deletions
42
clients/ops/admin-ui/src/features/auth/__tests__/auth.slice.test.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
| @@ -1,12 +1,8 @@ | ||
| import { | ||
| createListenerMiddleware, | ||
| createSlice, | ||
| PayloadAction, | ||
| } from "@reduxjs/toolkit"; | ||
| import { createSlice, PayloadAction } from "@reduxjs/toolkit"; | ||
| import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react"; | ||
|
|
||
| import type { RootState } from "../../app/store"; | ||
| import { BASE_URL, STORED_CREDENTIALS_KEY } from "../../constants"; | ||
| import { BASE_URL } from "../../constants"; | ||
| import { addCommonHeaders } from "../common/CommonHeaders"; | ||
| import { utf8ToB64 } from "../common/utils"; | ||
| import { User } from "../user-management/types"; | ||
|
|
@@ -56,27 +52,6 @@ export const selectToken = (state: RootState) => selectAuth(state).token; | |
|
|
||
| export const { login, logout } = authSlice.actions; | ||
|
|
||
| export const credentialStorage = createListenerMiddleware(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed the following event listeners given the redux-perist localStorage functionality. Redux-persist localStorage root key is |
||
| credentialStorage.startListening({ | ||
| actionCreator: login, | ||
| effect: (action, { getState }) => { | ||
| if (window && window.localStorage) { | ||
| localStorage.setItem( | ||
| STORED_CREDENTIALS_KEY, | ||
| JSON.stringify(selectAuth(getState() as RootState)) | ||
| ); | ||
| } | ||
| }, | ||
| }); | ||
| credentialStorage.startListening({ | ||
| actionCreator: logout, | ||
| effect: () => { | ||
| if (window && window.localStorage) { | ||
| localStorage.removeItem(STORED_CREDENTIALS_KEY); | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| // Auth API | ||
| export const authApi = createApi({ | ||
| reducerPath: "authApi", | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -18,35 +18,11 @@ import { AddConnectionStep } from "./types"; | |
| const AddConnection: React.FC = () => { | ||
| const dispatch = useDispatch(); | ||
| const router = useRouter(); | ||
| const { connectorType, key, step: currentStep } = router.query; | ||
| const { connectorType, step: currentStep } = router.query; | ||
|
|
||
| const { connectionOption, step } = useAppSelector(selectConnectionTypeState); | ||
|
|
||
| /** | ||
| * NOTE: If the user reloads the web page via F5, the react redux store state is lost. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The following code snippet was no longer needed given the Redux store is persisted in localStorage. |
||
| * By default its persisted in internal memory. As a result, a runtime exception occurs | ||
| * which impedes the page rendering. | ||
| * | ||
| * @example | ||
| * The above error occurred in the <AddConnection> component | ||
| * | ||
| * For now, a temporary solution is to redirect the user | ||
| * to the "Choose your connection" step. This allows a better overall user experience. | ||
| * A permanent solution will be to persist the react redux store state to either local storage | ||
| * or session storage. Once completed, this method can be deleted. | ||
| */ | ||
| const reload = useCallback(() => { | ||
| if ( | ||
| key && | ||
| currentStep && | ||
| (currentStep as unknown as number) !== step?.stepId | ||
| ) { | ||
| window.location.href = STEPS[1].href; | ||
| } | ||
| }, [currentStep, key, step?.stepId]); | ||
|
|
||
| useEffect(() => { | ||
| reload(); | ||
| if (connectorType) { | ||
| dispatch(setConnectionOption(JSON.parse(connectorType as string))); | ||
| } | ||
|
|
@@ -55,19 +31,7 @@ const AddConnection: React.FC = () => { | |
| dispatch(setStep(item || STEPS[1])); | ||
| } | ||
| return () => {}; | ||
| }, [connectorType, currentStep, dispatch, reload, router.query.step]); | ||
|
|
||
| const getComponent = useCallback(() => { | ||
| switch (step.stepId) { | ||
| case 1: | ||
| return <ChooseConnection />; | ||
| case 2: | ||
| case 3: | ||
| return <ConfigureConnector />; | ||
| default: | ||
| return <ChooseConnection />; | ||
| } | ||
| }, [step.stepId]); | ||
| }, [connectorType, currentStep, dispatch, router.query.step]); | ||
|
|
||
| const getLabel = useCallback( | ||
| (s: AddConnectionStep): string => { | ||
|
|
@@ -108,7 +72,17 @@ const AddConnection: React.FC = () => { | |
| {!connectionOption && <Text>{getLabel(step)}</Text>} | ||
| </Box> | ||
| </Heading> | ||
| {getComponent()} | ||
| {(() => { | ||
| switch (step.stepId) { | ||
| case 1: | ||
| return <ChooseConnection />; | ||
| case 2: | ||
| case 3: | ||
| return <ConfigureConnector />; | ||
| default: | ||
| return <ChooseConnection />; | ||
| } | ||
| })()} | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.