MCPcopy Create free account
hub / github.com/bytebase/bytebase / useEnvironment

Function useEnvironment

frontend/src/react/hooks/useAppState.ts:203–224  ·  view source on GitHub ↗
(name: string | undefined)

Source from the content-addressed store, hash-verified

201}
202
203export function useEnvironment(name: string | undefined) {
204 const environmentList = useEnvironmentList();
205 return useMemo(() => {
206 if (!name || name === NULL_ENVIRONMENT_NAME) {
207 return nullEnvironment();
208 }
209 const environment = environmentList.find((env) => env.name === name);
210 if (environment) {
211 return environment;
212 }
213 if (!isValidEnvironmentName(name)) {
214 return unknownEnvironment();
215 }
216 const id = name.replace(/^environments\//, "");
217 return {
218 ...unknownEnvironment(),
219 id,
220 name,
221 title: id,
222 };
223 }, [environmentList, name]);
224}
225
226export function usePlanFeature(feature: PlanFeature) {
227 const loadSubscription = useAppStore((state) => state.loadSubscription);

Callers 3

EnvironmentLabelFunction · 0.90
EnvironmentResourceLinkFunction · 0.90
DatabaseDetailHeaderFunction · 0.90

Calls 4

nullEnvironmentFunction · 0.90
isValidEnvironmentNameFunction · 0.90
unknownEnvironmentFunction · 0.90
useEnvironmentListFunction · 0.85

Tested by

no test coverage detected