-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use session storage to persist filter and search #3114
Open
gordonfarrell
wants to merge
11
commits into
main
Choose a base branch
from
gordon/filters-session-storage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+160
−5
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2d2ef9d
saving urlParams to session storage, testing retrieval and setting
gordonfarrell ac01ce0
save to session storage on name click, apply to back button
gordonfarrell 38870f2
add tests for new session storage utils
gordonfarrell e3c9ee3
Merge branch 'main' into gordon/filters-session-storage
gordonfarrell a94d9a6
typo fix
gordonfarrell de986fc
Add playwright test, fix session storage undefined error
gordonfarrell 7bccae1
Add undefined return type and return undefined if session storage doe…
gordonfarrell 03cfcfe
change undefined return to null
gordonfarrell ad52756
update description
gordonfarrell 7430129
mock session storage for playwright test
gordonfarrell b07ab97
update to use locator method
gordonfarrell 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 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 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 |
---|---|---|
|
@@ -8,6 +8,7 @@ import { usePathname, useSearchParams, useRouter } from "next/navigation"; | |
import { range } from "../view-data/utils/utils"; | ||
import classNames from "classnames"; | ||
import Link from "next/link"; | ||
import { saveToSessionStorage } from "./utils"; | ||
|
||
type EcrTableClientProps = { | ||
data: EcrDisplay[]; | ||
|
@@ -66,7 +67,7 @@ const initialHeaders = [ | |
{ | ||
id: "reportable_condition", | ||
value: "Reportable Condition", | ||
className: "library-condition-colum", | ||
className: "library-condition-column", | ||
dataSortable: false, | ||
sortDirection: "", | ||
}, | ||
|
@@ -283,6 +284,8 @@ const DataRow = ({ item }: { item: EcrDisplay }) => { | |
const patientReportDate = formatDate(patientReportDateObj); | ||
const patientReportTime = formatTime(patientReportDateObj); | ||
|
||
const searchParams = useSearchParams(); | ||
|
||
const conditionsList = ( | ||
<ul className="ecr-table-list"> | ||
{item.reportable_conditions.map((rc, index) => ( | ||
|
@@ -298,11 +301,14 @@ const DataRow = ({ item }: { item: EcrDisplay }) => { | |
))} | ||
</ul> | ||
); | ||
const saveUrl = () => { | ||
saveToSessionStorage("urlParams", searchParams.toString()); | ||
}; | ||
|
||
return ( | ||
<tr> | ||
<td> | ||
<Link href={`/view-data?id=${item.ecrId}`}> | ||
<Link onClick={saveUrl} href={`/view-data?id=${item.ecrId}`}> | ||
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. so simple! ❤️ |
||
{patient_first_name} {patient_last_name} | ||
</Link> | ||
<br /> | ||
|
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,34 @@ | ||
/** | ||
* Saves a key-value pair to session storage. | ||
* @param key - The key under which the value will be stored. | ||
* @param value - The value to be stored. Can be a string or any serializable object. | ||
*/ | ||
export const saveToSessionStorage = ( | ||
key: string, | ||
value: string | object, | ||
): void => { | ||
const serializedValue = JSON.stringify(value); | ||
|
||
if (typeof window !== "undefined" && window.sessionStorage) { | ||
sessionStorage.setItem(key, serializedValue); | ||
} else { | ||
console.warn("sessionStorage is not available"); | ||
} | ||
}; | ||
|
||
/** | ||
* Retrieves a key-value pair from session storage. | ||
* @param key - The key under which the value was stored. | ||
* @returns string or null - The stored value from session storage or null if it finds nothing | ||
*/ | ||
export const retrieveFromSessionStorage = ( | ||
key: string, | ||
): string | object | null => { | ||
if (typeof window !== "undefined" && window.sessionStorage) { | ||
const storedValue = sessionStorage.getItem(key); | ||
return JSON.parse(<string>storedValue); | ||
} else { | ||
console.warn("sessionStorage is not available"); | ||
return null; | ||
} | ||
}; |
62 changes: 62 additions & 0 deletions
62
containers/ecr-viewer/src/app/tests/components/Utils.test.tsx
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,62 @@ | ||
import { | ||
saveToSessionStorage, | ||
retrieveFromSessionStorage, | ||
} from "../../components/utils.ts"; | ||
|
||
describe("Session Storage saving utils", () => { | ||
beforeEach(() => { | ||
sessionStorage.clear(); | ||
}); | ||
|
||
describe("saveToSessionStorage", () => { | ||
it("should save a string value to session storage", () => { | ||
const key = "Bread"; | ||
const value = "Baguette"; | ||
saveToSessionStorage(key, value); | ||
|
||
expect(sessionStorage.getItem(key)).toBe(JSON.stringify(value)); | ||
}); | ||
|
||
it("should save an object value to session storage", () => { | ||
const key = "testKey"; | ||
const value = { name: "Heironymous", age: 37 }; | ||
saveToSessionStorage(key, value); | ||
|
||
expect(sessionStorage.getItem(key)).toBe(JSON.stringify(value)); | ||
}); | ||
}); | ||
|
||
describe("retrieveFromSessionStorage", () => { | ||
it("should retrieve a string value from session storage", () => { | ||
const key = "fruit"; | ||
const value = "Apples"; | ||
sessionStorage.setItem(key, JSON.stringify(value)); | ||
|
||
const retrievedValue = retrieveFromSessionStorage(key); | ||
expect(retrievedValue).toBe(value); | ||
}); | ||
|
||
it("should retrieve an object value from session storage", () => { | ||
const key = "patient"; | ||
const value = { name: "Arabelle", age: 22 }; | ||
sessionStorage.setItem(key, JSON.stringify(value)); | ||
|
||
const retrievedValue = retrieveFromSessionStorage(key); | ||
expect(retrievedValue).toEqual(value); | ||
}); | ||
|
||
it("should return null if the key does not exist", () => { | ||
const key = "nonExistentKey"; | ||
const retrievedValue = retrieveFromSessionStorage(key); | ||
|
||
expect(retrievedValue).toBeNull(); | ||
}); | ||
|
||
it("should throw an error for invalid JSON in session storage", () => { | ||
const key = "aKey"; | ||
sessionStorage.setItem(key, "invalid-json"); | ||
|
||
expect(() => retrieveFromSessionStorage(key)).toThrow(SyntaxError); | ||
}); | ||
}); | ||
}); |
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
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we add an e2e test that covers this functionality?