Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve full sub-path when switching projects #509

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/pages/storage/Storage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import HelpLink from "components/HelpLink";

const TABS: string[] = ["Pools", "Volumes", "Cached images", "Custom ISOs"];

export const STORAGE_TAB_PATHS = TABS.map((tab) => slugify(tab));

const Storage: FC = () => {
const navigate = useNavigate();
const notify = useNotify();
Expand All @@ -24,12 +26,12 @@ const Storage: FC = () => {
return <>Missing project</>;
}

const handleTabChange = (newTab: string) => {
const handleTabChange = (newTabPath: string) => {
notify.clear();
if (newTab === slugify(TABS[0])) {
if (newTabPath === STORAGE_TAB_PATHS[0]) {
navigate(`/ui/project/${project}/storage`);
} else {
navigate(`/ui/project/${project}/storage/${newTab}`);
navigate(`/ui/project/${project}/storage/${newTabPath}`);
}
};

Expand All @@ -47,13 +49,16 @@ const Storage: FC = () => {
<NotificationRow />
<Row>
<Tabs
links={TABS.map((tab) => ({
label: tab,
id: slugify(tab),
active:
slugify(tab) === activeTab || (tab === TABS[0] && !activeTab),
onClick: () => handleTabChange(slugify(tab)),
}))}
links={TABS.map((tab, index) => {
const tabPath = STORAGE_TAB_PATHS[index];

return {
label: tab,
id: tabPath,
active: tabPath === activeTab || (tab === TABS[0] && !activeTab),
onClick: () => handleTabChange(tabPath),
};
})}
/>

{!activeTab && (
Expand Down
14 changes: 12 additions & 2 deletions src/util/projects.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { STORAGE_TAB_PATHS } from "pages/storage/Storage";
import { LxdProject } from "types/project";

export const projectSubpages = [
Expand All @@ -12,9 +13,18 @@ export const projectSubpages = [

export const getSubpageFromUrl = (url: string) => {
const parts = url.split("/");
if (projectSubpages.includes(parts[4])) {
return parts[4];

const mainSubpage = parts[4];
const tabSubpage = parts[5];

if (mainSubpage === "storage" && STORAGE_TAB_PATHS.includes(tabSubpage)) {
return `${mainSubpage}/${tabSubpage}`;
}

if (projectSubpages.includes(mainSubpage)) {
return mainSubpage;
}

return undefined;
};

Expand Down
Loading