-
Notifications
You must be signed in to change notification settings - Fork 928
chore: expose all organization ids from AuthContext #13268
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
6 commits
Select commit
Hold shift + click to select a range
c7b1889
chore: add setting to enabled multi-organization ui
aslilac 45545c4
🧹
aslilac fbd5daa
chore: expose all organization ids from `AuthContext`
aslilac 7eb193e
Merge branch 'main' into multi-org-state
aslilac 387b3a2
🧹
aslilac cd7b026
fix test
aslilac 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
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,4 +1,9 @@ | ||
import { createContext, type FC, type PropsWithChildren } from "react"; | ||
import { | ||
createContext, | ||
type FC, | ||
type PropsWithChildren, | ||
useState, | ||
} from "react"; | ||
import { useQuery } from "react-query"; | ||
import { appearance } from "api/queries/appearance"; | ||
import { entitlements } from "api/queries/entitlements"; | ||
|
@@ -9,9 +14,13 @@ import type { | |
Experiments, | ||
} from "api/typesGenerated"; | ||
import { Loader } from "components/Loader/Loader"; | ||
import { useAuthenticated } from "contexts/auth/RequireAuth"; | ||
import { useEffectEvent } from "hooks/hookPolyfills"; | ||
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata"; | ||
|
||
export interface DashboardValue { | ||
organizationId: string; | ||
setOrganizationId: (id: string) => void; | ||
entitlements: Entitlements; | ||
experiments: Experiments; | ||
appearance: AppearanceConfig; | ||
|
@@ -23,20 +32,40 @@ export const DashboardContext = createContext<DashboardValue | undefined>( | |
|
||
export const DashboardProvider: FC<PropsWithChildren> = ({ children }) => { | ||
const { metadata } = useEmbeddedMetadata(); | ||
const { user, organizationIds } = useAuthenticated(); | ||
const entitlementsQuery = useQuery(entitlements(metadata.entitlements)); | ||
const experimentsQuery = useQuery(experiments(metadata.experiments)); | ||
const appearanceQuery = useQuery(appearance(metadata.appearance)); | ||
|
||
const isLoading = | ||
!entitlementsQuery.data || !appearanceQuery.data || !experimentsQuery.data; | ||
|
||
const lastUsedOrganizationId = localStorage.getItem( | ||
`user:${user.id}.lastUsedOrganizationId`, | ||
); | ||
const [activeOrganizationId, setActiveOrganizationId] = useState(() => | ||
lastUsedOrganizationId && organizationIds.includes(lastUsedOrganizationId) | ||
? lastUsedOrganizationId | ||
: organizationIds[0], | ||
); | ||
|
||
const setOrganizationId = useEffectEvent((id: string) => { | ||
if (!organizationIds.includes(id)) { | ||
throw new ReferenceError("Invalid organization ID"); | ||
} | ||
localStorage.setItem(`user:${user.id}.lastUsedOrganizationId`, id); | ||
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. Smart assigning to a user! |
||
setActiveOrganizationId(id); | ||
}); | ||
|
||
if (isLoading) { | ||
return <Loader fullscreen />; | ||
} | ||
|
||
return ( | ||
<DashboardContext.Provider | ||
value={{ | ||
organizationId: activeOrganizationId, | ||
setOrganizationId: setOrganizationId, | ||
entitlements: entitlementsQuery.data, | ||
experiments: experimentsQuery.data, | ||
appearance: appearanceQuery.data, | ||
|
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
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
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
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.
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.
Talked to @aslilac, we are not going to introduce the concept of "Default Org" to the FE. It is a stop gap on the backend to accommodate features like group sync, role sync, SCIM, etc. Those features need to be upgraded to not rely on default org.
If a deployment exists with more than 1 org, this is no more broken than it currently is today.