Skip to content

Commit

Permalink
Merge pull request #196 from TouK/NU-1086/fix-breadcrumbs
Browse files Browse the repository at this point in the history
Nu-1086/breadcrumbs
  • Loading branch information
JulianWielga authored Oct 4, 2023
2 parents fb808e0 + 77743fd commit 2e8ab7b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/deleteSubscriptionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const DeleteSubscriptionDialog = observer(() => {
confirmText={"Delete subscription"}
onSubmitSuccess={async () => {
await topic.fetchSubscriptionsTask();
navigate(`/${topic.name}`);
navigate(topic.name);
}}
/>
);
Expand Down
5 changes: 3 additions & 2 deletions src/components/deleteTopicDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { observer } from "mobx-react-lite";
import React from "react";
import { useNavigate } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";
import { useStore } from "../store/storeProvider";
import { ConfirmDialog } from "./confirmDialog";

export const DeleteTopicDialog = observer(() => {
const { dialogs, topics } = useStore();
const { pathname } = useLocation();
const navigate = useNavigate();
const dialog = dialogs.deleteTopicDialog;
const { topic } = dialog.params;
Expand All @@ -22,7 +23,7 @@ export const DeleteTopicDialog = observer(() => {
confirmText={"Remove topic"}
onSubmitSuccess={async () => {
await topics.fetchTask();
navigate("/");
navigate(pathname.replace(topic.name, ""));
}}
/>
);
Expand Down
16 changes: 11 additions & 5 deletions src/components/navigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ export const NavigationBar = observer(() => {
const { pathname } = useLocation();
const rootPath = useContext(RootPath);
const normalizedPathname = pathname.indexOf(rootPath) === 0 ? pathname.substring(rootPath.length) : pathname;
const pathnames = normalizedPathname.split("/").filter(Boolean);

const pathnames = pathname.includes("topics")
? normalizedPathname
.replace(/^\/topics[^/]*\//, "/")
.split("/")
.filter(Boolean)
: normalizedPathname.split("/").filter(Boolean);

const homeText = groups.areGroupsHidden ? "Topics list" : "Groups and topics";

Expand All @@ -37,7 +43,6 @@ export const NavigationBar = observer(() => {
topics.getTopicDisplayName?.(match?.params.topic) || <LinePlaceholder dark length={match?.params.topic.length} />,
"/:topic/:subscription": (match) => match?.params.subscription,
});

return (
<LayoutRow justifyContent="space-between" alignItems="baseline">
<Breadcrumbs
Expand All @@ -49,14 +54,15 @@ export const NavigationBar = observer(() => {

{pathnames.map((value, index) => {
const last = index === pathnames.length - 1;
const to = `/${pathnames.slice(0, index + 1).join("/")}`;
const to = `${pathnames.slice(0, index + 1).join("/")}`;

return last ? (
<Typography key={to} fontWeight="bold">
{nameGetter(to)}
{nameGetter(`/${to}`)}
</Typography>
) : (
<LinkRouter to={to} key={to}>
{nameGetter(to)}
{nameGetter(`/${to}`)}
</LinkRouter>
);
})}
Expand Down
11 changes: 9 additions & 2 deletions src/components/subscriptionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Field, FormikErrors } from "formik";
import { CheckboxWithLabel, RadioGroup, TextField } from "formik-mui";
import { observer, useObserver } from "mobx-react-lite";
import React from "react";
import { useNavigate } from "react-router-dom";
import { useLocation, useNavigate } from "react-router-dom";
import { getSubscriptionData } from "../devData";
import { AdvancedSubscriptionFormikValues, SubscriptionFormikValues } from "../models";
import { Dialog } from "../store/dialog";
Expand Down Expand Up @@ -194,6 +194,7 @@ export const AddSubscriptionDialog = observer(() => {
export const AddClonedSubscriptionDialog = observer(() => {
const { dialogs } = useStore();
const dialog = dialogs.addClonedSubscription;
const { pathname } = useLocation();
const { topic, subscription } = dialog.params;

const initialValues = (): SubscriptionFormikValues =>
Expand All @@ -211,7 +212,13 @@ export const AddClonedSubscriptionDialog = observer(() => {
sub.assignValuesFromForm(values);
await topic.postSubscriptionTask(sub);
await topic.fetchSubscriptionsTask();
navigate(`/${topic.name}/${values.name}`);
const path = getFirstPartOfPath(pathname);
navigate(`${path}/${topic.name}/${values.name}`);
};

const getFirstPartOfPath = (path: string) => {
const parts = path.split("/");
return parts.slice(0, 2).join("/");
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/components/topicDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const TopicDialog = observer(
await groups.fetchTask();
await topics.fetchTask();
const topicName = Topic.joinName(group, topic);
navigate(`/${topicName}`);
navigate(topicName);
};

const basicFields = (errors: FormikErrors<TopicFormikValues>): JSX.Element[] => [
Expand Down

0 comments on commit 2e8ab7b

Please sign in to comment.