-
Notifications
You must be signed in to change notification settings - Fork 4
Allow available instrument sessions to be updated dynamically #165
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5007daf
Add instrumentSessionList to localStorage
EmsArnold 52c4ba8
Create button which queries for sessions, allow for no sessions and n…
EmsArnold 1673408
Tidy up linting issues
EmsArnold 03d53d7
remove unnecessary variables
EmsArnold 8f9d2cf
Overhaul tests
EmsArnold fe03765
Add tests, logic to instrument session view to handle case where no s…
EmsArnold e84a231
Merge branch 'main' into 162_dynamic_instrument_sessions
EmsArnold 52cc998
add additional instrumentSessionReference
EmsArnold 504ad79
Handle no instrument session set in RunPlanButton, add test
EmsArnold c19da44
Merge branch 'main' into 162_dynamic_instrument_sessions
EmsArnold 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import { useLazyQuery } from "@apollo/client/react"; | ||
| import { getInstrumentSessionsQuery } from "../graphql/getInstrumentSessionsQuery.ts"; | ||
| import type { TypedDocumentNode } from "@apollo/client"; | ||
| import type { | ||
| InstrumentSessionQuery, | ||
| InstrumentSessionQueryVariables, | ||
| } from "../graphql/getInstrumentSessionsQuery.generated.ts"; | ||
| import { useInstrumentSession } from "@atlas/app-shell"; | ||
| import { Button } from "@mui/material"; | ||
|
|
||
| export const InstrumentSessionButton = () => { | ||
| const { setInstrumentSession, setInstrumentSessionList } = | ||
| useInstrumentSession(); | ||
|
|
||
| const GET_SESSIONS: TypedDocumentNode< | ||
| InstrumentSessionQuery, | ||
| InstrumentSessionQueryVariables | ||
| > = getInstrumentSessionsQuery; | ||
|
|
||
| const [fetchSessions] = useLazyQuery(GET_SESSIONS); | ||
|
|
||
| const handleButtonClick = async () => { | ||
| try { | ||
| const { data } = await fetchSessions({ | ||
| variables: { instrumentKey: "I15-1" }, | ||
| }); | ||
|
|
||
| const edges = data?.instrumentByKey?.instrumentSessions?.edges; | ||
| if (edges && edges.length > 0) { | ||
| const sessionsList = edges.flatMap((edge) => { | ||
| const ref = edge?.node?.instrumentSessionReference; | ||
| return ref ? [ref.toLocaleLowerCase()] : []; | ||
| }); | ||
| setInstrumentSessionList(sessionsList); | ||
| if (sessionsList.length == 1) { | ||
| setInstrumentSession(sessionsList[0]); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| console.error("Failed to fetch sessions:", err); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Button variant="contained" onClick={handleButtonClick}> | ||
| Get Sessions | ||
| </Button> | ||
| ); | ||
| }; |
10 changes: 10 additions & 0 deletions
10
apps/i15-1/src/graphql/getInstrumentSessionsQuery.generated.ts
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 |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| /** Internal type. DO NOT USE DIRECTLY. */ | ||
| type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; | ||
| /** Internal type. DO NOT USE DIRECTLY. */ | ||
| export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; | ||
| export type InstrumentSessionQueryVariables = Exact<{ | ||
| instrumentKey: string; | ||
| }>; | ||
|
|
||
|
|
||
| export type InstrumentSessionQuery = { instrumentByKey: { __typename: 'Instrument', instrumentSessions: { __typename: 'InstrumentSessionConnection', edges: Array<{ __typename: 'InstrumentSessionEdge', node: { __typename: 'InstrumentSession', instrumentSessionReference: string | null } }> } } | null }; |
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { gql } from "@apollo/client"; | ||
|
|
||
| export const getInstrumentSessionsQuery = gql` | ||
| query InstrumentSession($instrumentKey: String!) { | ||
| instrumentByKey(key: $instrumentKey) { | ||
| instrumentSessions(filterBy: { state: { eq: IN_PROGRESS } }) { | ||
| edges { | ||
| node { | ||
| instrumentSessionReference | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `; |
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
Oops, something went wrong.
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.