MCPcopy Index your code
hub / github.com/bytebase/bytebase / ProjectRouteShell

Function ProjectRouteShell

frontend/src/react/components/ProjectRouteShell.tsx:25–173  ·  view source on GitHub ↗
({
  projectId,
  routeKey,
  onReady,
}: ProjectRouteShellProps)

Source from the content-addressed store, hash-verified

23}
24
25export function ProjectRouteShell({
26 projectId,
27 routeKey,
28 onReady,
29}: ProjectRouteShellProps) {
30 const { t } = useTranslation();
31 const route = useCurrentRoute();
32 const navigate = useNavigate();
33 const navigateRef = useRef(navigate);
34 navigateRef.current = navigate;
35 const onReadyRef = useRef(onReady);
36 onReadyRef.current = onReady;
37 const notify = useNotify();
38 const projectName = projectResourceNameFromId(projectId);
39 const project = useAppStore((state) => state.projectsByName[projectName]);
40 const defaultProjectName = useAppStore(
41 (state) => state.serverInfo?.defaultProject ?? ""
42 );
43 const allowEdit = useAppStore((state) =>
44 project
45 ? project.state !== State.DELETED &&
46 state.hasProjectPermission(project, "bb.projects.update")
47 : false
48 );
49 const fetchProject = useAppStore((state) => state.fetchProject);
50 const loadServerInfo = useAppStore((state) => state.loadServerInfo);
51 const loadCurrentUser = useAppStore((state) => state.loadCurrentUser);
52 const loadProjectIamPolicy = useAppStore(
53 (state) => state.loadProjectIamPolicy
54 );
55 const setRecentProject = useAppStore((state) => state.setRecentProject);
56 const removeRecentVisit = useAppStore((state) => state.removeRecentVisit);
57 const [readyProjectName, setReadyProjectName] = useState("");
58
59 useEffect(() => {
60 let stale = false;
61 setReadyProjectName("");
62 onReadyRef.current?.(null);
63
64 const load = async () => {
65 await Promise.all([loadCurrentUser(), loadServerInfo()]);
66 const nextProject = await fetchProject(projectName);
67 if (stale) return;
68 if (!nextProject) {
69 const projectRoute = navigateRef.current.resolve({
70 name: PROJECT_V1_ROUTE_DETAIL,
71 params: { projectId },
72 });
73 removeRecentVisit(projectRoute.fullPath);
74 const error = useAppStore.getState().projectErrorsByName[projectName];
75 if (error) {
76 notify({
77 module: "bytebase",
78 style: "CRITICAL",
79 title: `Failed to fetch project ${projectId}`,
80 description: error.message,
81 });
82 }

Callers

nothing calls this directly

Calls 8

useCurrentRouteFunction · 0.90
useNavigateFunction · 0.90
useNotifyFunction · 0.90
setDocumentTitleFunction · 0.90
useAppStoreFunction · 0.70
loadFunction · 0.70
tFunction · 0.50

Tested by

no test coverage detected