({ children })
| 34 | ); |
| 35 | |
| 36 | export const DashboardProvider: FC<PropsWithChildren> = ({ children }) => { |
| 37 | const { metadata } = useEmbeddedMetadata(); |
| 38 | const { permissions } = useAuthenticated(); |
| 39 | const entitlementsQuery = useQuery(entitlements(metadata.entitlements)); |
| 40 | const experimentsQuery = useQuery(experiments(metadata.experiments)); |
| 41 | const appearanceQuery = useQuery(appearance(metadata.appearance)); |
| 42 | const buildInfoQuery = useQuery(buildInfo(metadata["build-info"])); |
| 43 | const organizationsQuery = useQuery(organizations(metadata.organizations)); |
| 44 | |
| 45 | const error = |
| 46 | entitlementsQuery.error || |
| 47 | appearanceQuery.error || |
| 48 | experimentsQuery.error || |
| 49 | buildInfoQuery.error || |
| 50 | organizationsQuery.error; |
| 51 | |
| 52 | if (error) { |
| 53 | return <ErrorAlert error={error} />; |
| 54 | } |
| 55 | |
| 56 | const isLoading = |
| 57 | !entitlementsQuery.data || |
| 58 | !appearanceQuery.data || |
| 59 | !experimentsQuery.data || |
| 60 | !buildInfoQuery.data || |
| 61 | !organizationsQuery.data; |
| 62 | |
| 63 | if (isLoading) { |
| 64 | return <Loader fullscreen />; |
| 65 | } |
| 66 | |
| 67 | const hasMultipleOrganizations = organizationsQuery.data.length > 1; |
| 68 | const organizationsEnabled = selectFeatureVisibility( |
| 69 | entitlementsQuery.data, |
| 70 | ).multiple_organizations; |
| 71 | const showOrganizations = hasMultipleOrganizations || organizationsEnabled; |
| 72 | |
| 73 | return ( |
| 74 | <DashboardContext.Provider |
| 75 | value={{ |
| 76 | entitlements: entitlementsQuery.data, |
| 77 | experiments: experimentsQuery.data, |
| 78 | appearance: appearanceQuery.data, |
| 79 | buildInfo: buildInfoQuery.data, |
| 80 | organizations: organizationsQuery.data, |
| 81 | showOrganizations, |
| 82 | canViewOrganizationSettings: |
| 83 | showOrganizations && canViewAnyOrganization(permissions), |
| 84 | }} |
| 85 | > |
| 86 | {children} |
| 87 | </DashboardContext.Provider> |
| 88 | ); |
| 89 | }; |
nothing calls this directly
no test coverage detected