-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9c19dd5
commit 44902d2
Showing
11 changed files
with
498 additions
and
328 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/*! | ||
* Copyright 2024 - Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
import cx from "classnames"; | ||
import { Eye, Sliders } from "react-bootstrap-icons"; | ||
import { Nav, NavItem } from "reactstrap"; | ||
import RenkuNavLinkV2 from "./RenkuNavLinkV2"; | ||
|
||
export interface PageNavOptions { | ||
overviewUrl: string; | ||
settingsUrl: string; | ||
} | ||
export default function PageNav({ options }: { options: PageNavOptions }) { | ||
return ( | ||
<> | ||
<Nav tabs> | ||
<NavItem> | ||
<RenkuNavLinkV2 end to={options.overviewUrl} title="Overview"> | ||
<Eye className={cx("bi", "me-1")} /> | ||
Overview | ||
</RenkuNavLinkV2> | ||
</NavItem> | ||
<NavItem> | ||
<RenkuNavLinkV2 end to={options.settingsUrl} title="Settings"> | ||
<Sliders className={cx("bi", "me-1")} /> | ||
Settings | ||
</RenkuNavLinkV2> | ||
</NavItem> | ||
</Nav> | ||
</> | ||
); | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*! | ||
* Copyright 2024 - Swiss Data Science Center (SDSC) | ||
* A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and | ||
* Eidgenössische Technische Hochschule Zürich (ETHZ). | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Suspense, lazy } from "react"; | ||
import PageLoader from "../../components/PageLoader"; | ||
|
||
const GroupV2Container = lazy(() => import("./show/GroupPageContainer")); | ||
|
||
export default function LazyGroupContainer() { | ||
return ( | ||
<Suspense fallback={<PageLoader />}> | ||
<GroupV2Container /> | ||
</Suspense> | ||
); | ||
} |
This file contains 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 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 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
127 changes: 127 additions & 0 deletions
127
client/src/features/groupsV2/show/GroupPageContainer.tsx
This file contains 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 |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import { skipToken } from "@reduxjs/toolkit/query"; | ||
import cx from "classnames"; | ||
import { useEffect } from "react"; | ||
import { | ||
generatePath, | ||
Outlet, | ||
useNavigate, | ||
useOutletContext, | ||
useParams, | ||
} from "react-router-dom-v5-compat"; | ||
import { Col, Row } from "reactstrap"; | ||
import ContainerWrap from "../../../components/container/ContainerWrap.tsx"; | ||
import { Loader } from "../../../components/Loader.tsx"; | ||
import PageNav, { PageNavOptions } from "../../../components/PageNav.tsx"; | ||
import LazyNotFound from "../../../not-found/LazyNotFound.tsx"; | ||
import { ABSOLUTE_ROUTES } from "../../../routing/routes.constants.ts"; | ||
import { GroupResponse } from "../../projectsV2/api/namespace.api.ts"; | ||
import { | ||
useGetGroupsByGroupSlugQuery, | ||
useGetNamespacesByNamespaceSlugQuery, | ||
} from "../../projectsV2/api/projectV2.enhanced-api.ts"; | ||
import GroupNotFound from "../../projectsV2/notFound/GroupNotFound.tsx"; | ||
import UserAvatar, { | ||
AvatarTypeWrap, | ||
UserAvatarSize, | ||
} from "../../usersV2/show/UserAvatar.tsx"; | ||
|
||
export default function GroupPageContainer() { | ||
const { slug } = useParams<{ slug: string }>(); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const { | ||
data: namespace, | ||
isLoading: isLoadingNamespace, | ||
error: namespaceError, | ||
} = useGetNamespacesByNamespaceSlugQuery( | ||
slug ? { namespaceSlug: slug } : skipToken | ||
); | ||
const { | ||
data: group, | ||
isLoading: isLoadingGroup, | ||
error: groupError, | ||
} = useGetGroupsByGroupSlugQuery(slug ? { groupSlug: slug } : skipToken); | ||
|
||
const isLoading = isLoadingNamespace || isLoadingGroup; | ||
const error = namespaceError ?? groupError; | ||
|
||
useEffect(() => { | ||
if (slug && namespace?.namespace_kind === "user") { | ||
navigate( | ||
generatePath(ABSOLUTE_ROUTES.v2.users.show, { username: slug }), | ||
{ | ||
replace: true, | ||
} | ||
); | ||
} | ||
}, [namespace?.namespace_kind, navigate, slug]); | ||
|
||
if (!slug) { | ||
return <LazyNotFound />; | ||
} | ||
|
||
if (isLoading) { | ||
return <Loader className="align-self-center" />; | ||
} | ||
|
||
if (error || !namespace || !group) { | ||
return <GroupNotFound error={error} />; | ||
} | ||
|
||
const options: PageNavOptions = { | ||
overviewUrl: generatePath(ABSOLUTE_ROUTES.v2.groups.show.root, { | ||
slug: group.slug, | ||
}), | ||
settingsUrl: generatePath(ABSOLUTE_ROUTES.v2.groups.show.settings, { | ||
slug: group.slug, | ||
}), | ||
}; | ||
return ( | ||
<ContainerWrap> | ||
<Row> | ||
<Col xs={12}> | ||
<GroupHeader group={group} slug={slug} /> | ||
</Col> | ||
<Col xs={12} className="mb-2"> | ||
<div className="mb-3"> | ||
<PageNav options={options} /> | ||
</div> | ||
</Col> | ||
<Col xs={12}> | ||
<main> | ||
<Outlet context={{ group: group } satisfies ContextType} /> | ||
</main> | ||
</Col> | ||
</Row> | ||
</ContainerWrap> | ||
); | ||
} | ||
|
||
type ContextType = { group: GroupResponse }; | ||
export function useGroup() { | ||
return useOutletContext<ContextType>(); | ||
} | ||
|
||
function GroupHeader({ group, slug }: { group: GroupResponse; slug: string }) { | ||
return ( | ||
<div className={cx("d-flex", "flex-row", "flex-nowrap", "gap-2")}> | ||
<div className={cx("d-flex", "gap-2")}> | ||
<AvatarTypeWrap type={"Group"}> | ||
<UserAvatar | ||
username={group.name || slug} | ||
size={UserAvatarSize.extraLarge} | ||
/> | ||
</AvatarTypeWrap> | ||
<div> | ||
<h2 className="mb-0">{group.name ?? "Unknown group"}</h2> | ||
{group.description && ( | ||
<section> | ||
<p>{group.description}</p> | ||
</section> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.