keyshade-xyz / keyshade

Realtime secret and configuration management tool, with the best in class security and seamless integration support
https://keyshade.xyz
Mozilla Public License 2.0
208 stars 105 forks source link

fix(platform): Replace localStorage with Jotai #439

Closed Nil2000 closed 2 months ago

Nil2000 commented 2 months ago

Description

Replaced all the instances in localStorage

Fixes #409

Dependencies

Mention any dependencies/packages used

Future Improvements

Mention any improvements to be done in future related to any file/feature

Mentions

Mention and tag the people

Screenshots of relevant screens

Add screenshots of relevant screens

Developer's checklist

If changes are made in the code:

Documentation Update

codiumai-pr-agent-free[bot] commented 2 months ago

PR Reviewer Guide ๐Ÿ”

โฑ๏ธ Estimated effort to review: 2 ๐Ÿ”ต๐Ÿ”ตโšชโšชโšช
๐Ÿงช No relevant tests
๐Ÿ”’ No security concerns identified
โšก Key issues to review

Possible Bug
The `setWorkspace` function uses `getCurrentWorkspace()` which depends on the `useAtom` hook. This may cause issues if called outside of a React component. Code Smell
The `setDefaultWorkspaceAtom` and `setCurrentWorkspaceAtom` functions use the `useAtom` hook, which should typically be used within React components, not in utility functions.
codiumai-pr-agent-free[bot] commented 2 months ago

PR Code Suggestions โœจ

CategorySuggestion                                                                                                                                    Score
Enhancement
โœ… Rename utility functions to better reflect their purpose of updating atom values ___ **Consider using a more descriptive name for the utility functions, such as
updateDefaultWorkspaceAtom and updateCurrentWorkspaceAtom, to better reflect their
purpose of updating the atom values.** [apps/platform/src/lib/workspace-storage.ts [28-35]](https://github.com/keyshade-xyz/keyshade/pull/439/files#diff-3399b4a605e2a48dd3faa057150c25a91b298f00543cc21fc191839f08d236cbR28-R35) ```diff -export function setDefaultWorkspaceAtom(workspace: Workspace | null): void { +export function updateDefaultWorkspaceAtom(workspace: Workspace | null): void { const [, setDefaultWorkspace] = useAtom(defaultWorkspaceAtom) setDefaultWorkspace(workspace) } -export function setCurrentWorkspaceAtom(workspace: Workspace | null): void { +export function updateCurrentWorkspaceAtom(workspace: Workspace | null): void { const [, setCurrentWorkspace] = useAtom(currentWorkspaceAtom) setCurrentWorkspace(workspace) } ``` `[Suggestion has been applied]`
Suggestion importance[1-10]: 7 Why:
7
โœ… Use a more descriptive comment for the utility functions section ___
Suggestion Impact:The comment for the utility functions section was changed from "Utility functions" to "Atom update functions" as suggested. code diff: ```diff //Utility functions ```
___ **Consider using a more descriptive comment for the utility functions section, such as
"Atom update functions" instead of "Utility functions", to better reflect their
specific purpose.** [apps/platform/src/lib/workspace-storage.ts [27-28]](https://github.com/keyshade-xyz/keyshade/pull/439/files#diff-3399b4a605e2a48dd3faa057150c25a91b298f00543cc21fc191839f08d236cbR27-R28) ```diff -//Utility functions +// Atom update functions export function setDefaultWorkspaceAtom(workspace: Workspace | null): void { ``` - [ ] **Apply this suggestion**
Suggestion importance[1-10]: 7 Why:
7
Best practice
โœ… Move atom declarations to the top of the file for better code organization ___ **Consider moving the atom declarations to the top of the file, just after the
imports, to improve code organization and readability.** [apps/platform/src/lib/workspace-storage.ts [1-5]](https://github.com/keyshade-xyz/keyshade/pull/439/files#diff-3399b4a605e2a48dd3faa057150c25a91b298f00543cc21fc191839f08d236cbR1-R5) ```diff import type { Workspace } from '@/types' import { atom, useAtom } from 'jotai' const defaultWorkspaceAtom = atom(null) const currentWorkspaceAtom = atom(null) +export function setWorkspace(workspaceData: Workspace[]): void { + ``` `[Suggestion has been applied]`
Suggestion importance[1-10]: 7 Why:
7
Possible issue
โœ… Add a null check before setting the current workspace to avoid potential runtime errors ___
Suggestion Impact:The commit added a null check for defaultWorkspace before calling setCurrentWorkspace, aligning with the suggestion to prevent potential runtime errors. code diff: ```diff + if (currentWorkspace === null && defaultWorkspace) { + setCurrentWorkspace(defaultWorkspace) ```
___ **In the setWorkspace function, consider adding a null check before calling
setCurrentWorkspace(defaultWorkspace!) to avoid potential runtime errors if
defaultWorkspace is null.** [apps/platform/src/lib/workspace-storage.ts [13-15]](https://github.com/keyshade-xyz/keyshade/pull/439/files#diff-3399b4a605e2a48dd3faa057150c25a91b298f00543cc21fc191839f08d236cbR13-R15) ```diff -if (getCurrentWorkspace() === null) { - setCurrentWorkspace(defaultWorkspace!) +if (getCurrentWorkspace() === null && defaultWorkspace) { + setCurrentWorkspace(defaultWorkspace) } ``` - [ ] **Apply this suggestion**
Suggestion importance[1-10]: 7 Why:
7
rajdip-b commented 2 months ago

@kriptonian1 can you review this once?

kriptonian1 commented 2 months ago

The use of local storage was intentional, we want the data to persist. I appreciate the PR, but this is not valid.