MCPcopy Create free account
hub / github.com/coder/coder / DashboardProvider

Function DashboardProvider

site/src/modules/dashboard/DashboardProvider.tsx:36–89  ·  view source on GitHub ↗
({ children })

Source from the content-addressed store, hash-verified

34);
35
36export 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};

Callers

nothing calls this directly

Calls 8

useAuthenticatedFunction · 0.90
entitlementsFunction · 0.90
experimentsFunction · 0.90
appearanceFunction · 0.90
buildInfoFunction · 0.90
organizationsFunction · 0.90
selectFeatureVisibilityFunction · 0.90
canViewAnyOrganizationFunction · 0.90

Tested by

no test coverage detected