Skip to content

Commit

Permalink
chore(notify) update react-components and react-router-dom, fix notif…
Browse files Browse the repository at this point in the history
…y.queue calls to not directly submit a notification, but to queue it for the next page

Signed-off-by: David Edler <david.edler@canonical.com>
  • Loading branch information
edlerd committed Jan 20, 2024
1 parent 46296dc commit 38cacc1
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 165 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"serve": "./entrypoint",
"test-js": "react-scripts test src/ --watchAll=false"},
"dependencies": {
"@canonical/react-components": "0.47.1",
"@canonical/react-components": "0.47.3",
"@monaco-editor/react": "4.6.0",
"@tanstack/react-query": "5.17.15",
"@use-it/event-listener": "0.1.7",
Expand All @@ -36,7 +36,7 @@
"react": "18.2.0",
"react-cytoscapejs": "2.0.0",
"react-dom": "18.2.0",
"react-router-dom": "6.17.0",
"react-router-dom": "6.21.3",
"react-scripts": "5.0.1",
"react-useportal": "1.0.19",
"serve": "14.2.1",
Expand Down
10 changes: 8 additions & 2 deletions src/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React, { FC } from "react";
import Navigation from "components/Navigation";
import { NotificationProvider } from "@canonical/react-components";
import {
NotificationProvider,
QueuedNotification,
} from "@canonical/react-components";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import Panels from "components/Panels";
import { AuthProvider } from "context/auth";
Expand All @@ -11,13 +14,16 @@ import Events from "pages/instances/Events";
import App from "./App";
import ErrorBoundary from "components/ErrorBoundary";
import ErrorPage from "components/ErrorPage";
import { useLocation } from "react-router-dom";

const queryClient = new QueryClient();

const Root: FC = () => {
const location = useLocation() as QueuedNotification;

return (
<ErrorBoundary fallback={ErrorPage}>
<NotificationProvider>
<NotificationProvider state={location.state} pathname={location.pathname}>
<QueryClientProvider client={queryClient}>
<AuthProvider>
<ProjectProvider>
Expand Down
5 changes: 2 additions & 3 deletions src/pages/cluster/ClusterGroupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Form,
Input,
Row,
success,
useNotify,
} from "@canonical/react-components";
import { useQuery, useQueryClient } from "@tanstack/react-query";
Expand Down Expand Up @@ -84,9 +85,7 @@ const ClusterGroupForm: FC<Props> = ({ group }) => {
const verb = group ? "saved" : "created";
navigate(
`/ui/cluster/groups/detail/${values.name}`,
notify.queue(
notify.success(`Cluster group ${values.name} ${verb}.`),
),
notify.queue(success(`Cluster group ${values.name} ${verb}.`)),
);
})
.catch((e: Error) => {
Expand Down
8 changes: 6 additions & 2 deletions src/pages/cluster/actions/DeleteClusterGroupBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import ItemName from "components/ItemName";
import { deleteClusterGroup } from "api/cluster";
import { queryKeys } from "util/queryKeys";
import { useQueryClient } from "@tanstack/react-query";
import { ConfirmationButton, useNotify } from "@canonical/react-components";
import {
ConfirmationButton,
success,
useNotify,
} from "@canonical/react-components";

interface Props {
group: string;
Expand All @@ -22,7 +26,7 @@ const DeleteClusterGroupBtn: FC<Props> = ({ group }) => {
.then(() => {
navigate(
`/ui/cluster`,
notify.queue(notify.success(`Cluster group ${group} deleted.`)),
notify.queue(success(`Cluster group ${group} deleted.`)),
);
})
.catch((e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/instances/InstanceDetailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import InstanceStateActions from "pages/instances/actions/InstanceStateActions";
import { useFormik } from "formik";
import * as Yup from "yup";
import { checkDuplicateName } from "util/helpers";
import { useNotify } from "@canonical/react-components";
import { success, useNotify } from "@canonical/react-components";
import { useEventQueue } from "context/eventQueue";

interface Props {
Expand Down Expand Up @@ -59,7 +59,7 @@ const InstanceDetailHeader: FC<Props> = ({ name, instance, project }) => {
() => {
navigate(
`/ui/project/${project}/instances/detail/${values.name}`,
notify.queue(notify.success("Instance renamed.")),
notify.queue(success("Instance renamed.")),
);
void formik.setFieldValue("isRenaming", false);
},
Expand Down
3 changes: 2 additions & 1 deletion src/pages/instances/actions/DeleteInstanceBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useDeleteIcon } from "context/useDeleteIcon";
import {
ConfirmationButton,
Icon,
success,
useNotify,
} from "@canonical/react-components";
import classnames from "classnames";
Expand Down Expand Up @@ -38,7 +39,7 @@ const DeleteInstanceBtn: FC<Props> = ({ instance }) => {
});
navigate(
`/ui/project/${instance.project}/instances`,
notify.queue(notify.success(`Instance ${instance.name} deleted.`)),
notify.queue(success(`Instance ${instance.name} deleted.`)),
);
},
(msg) =>
Expand Down
4 changes: 2 additions & 2 deletions src/pages/networks/CreateNetwork.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useState } from "react";
import { Button, useNotify } from "@canonical/react-components";
import { Button, success, useNotify } from "@canonical/react-components";
import { useFormik } from "formik";
import * as Yup from "yup";
import { useQuery, useQueryClient } from "@tanstack/react-query";
Expand Down Expand Up @@ -91,7 +91,7 @@ const CreateNetwork: FC = () => {
});
navigate(
`/ui/project/${project}/networks`,
notify.queue(notify.success(`Network ${values.name} created.`)),
notify.queue(success(`Network ${values.name} created.`)),
);
})
.catch((e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/networks/NetworkDetailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { checkDuplicateName } from "util/helpers";
import { LxdNetwork } from "types/network";
import { renameNetwork } from "api/networks";
import DeleteNetworkBtn from "pages/networks/actions/DeleteNetworkBtn";
import { useNotify } from "@canonical/react-components";
import { success, useNotify } from "@canonical/react-components";

interface Props {
name: string;
Expand Down Expand Up @@ -48,7 +48,7 @@ const NetworkDetailHeader: FC<Props> = ({ name, network, project }) => {
.then(() => {
navigate(
`/ui/project/${project}/networks/detail/${values.name}`,
notify.queue(notify.success("Network renamed.")),
notify.queue(success("Network renamed.")),
);
void formik.setFieldValue("isRenaming", false);
})
Expand Down
8 changes: 6 additions & 2 deletions src/pages/networks/actions/DeleteNetworkBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { LxdNetwork } from "types/network";
import { deleteNetwork } from "api/networks";
import { queryKeys } from "util/queryKeys";
import { useQueryClient } from "@tanstack/react-query";
import { ConfirmationButton, useNotify } from "@canonical/react-components";
import {
ConfirmationButton,
success,
useNotify,
} from "@canonical/react-components";

interface Props {
network: LxdNetwork;
Expand All @@ -30,7 +34,7 @@ const DeleteNetworkBtn: FC<Props> = ({ network, project }) => {
});
navigate(
`/ui/project/${project}/networks`,
notify.queue(notify.success(`Network ${network.name} deleted.`)),
notify.queue(success(`Network ${network.name} deleted.`)),
);
})
.catch((e) => {
Expand Down
3 changes: 2 additions & 1 deletion src/pages/profiles/CreateProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Form,
Notification,
Row,
success,
useNotify,
} from "@canonical/react-components";
import { useFormik } from "formik";
Expand Down Expand Up @@ -110,7 +111,7 @@ const CreateProfile: FC = () => {
.then(() => {
navigate(
`/ui/project/${project}/profiles`,
notify.queue(notify.success(`Profile ${values.name} created.`)),
notify.queue(success(`Profile ${values.name} created.`)),
);
})
.catch((e: Error) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/profiles/ProfileDetailHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { renameProfile } from "api/profiles";
import { useFormik } from "formik";
import * as Yup from "yup";
import { checkDuplicateName } from "util/helpers";
import { useNotify } from "@canonical/react-components";
import { success, useNotify } from "@canonical/react-components";

interface Props {
name: string;
Expand Down Expand Up @@ -54,7 +54,7 @@ const ProfileDetailHeader: FC<Props> = ({
.then(() => {
navigate(
`/ui/project/${project}/profiles/detail/${values.name}`,
notify.queue(notify.success("Profile renamed.")),
notify.queue(success("Profile renamed.")),
);
void formik.setFieldValue("isRenaming", false);
})
Expand Down
3 changes: 2 additions & 1 deletion src/pages/profiles/actions/DeleteProfileBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useDeleteIcon } from "context/useDeleteIcon";
import {
ConfirmationButton,
Icon,
success,
useNotify,
} from "@canonical/react-components";
import classnames from "classnames";
Expand Down Expand Up @@ -39,7 +40,7 @@ const DeleteProfileBtn: FC<Props> = ({
});
navigate(
`/ui/project/${project}/profiles`,
notify.queue(notify.success(`Profile ${profile.name} deleted.`)),
notify.queue(success(`Profile ${profile.name} deleted.`)),
);
})
.catch((e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/projects/CreateProject.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { FC, useEffect, useState } from "react";
import { Button, useNotify } from "@canonical/react-components";
import { Button, success, useNotify } from "@canonical/react-components";
import { useFormik } from "formik";
import * as Yup from "yup";
import { useQueryClient } from "@tanstack/react-query";
Expand Down Expand Up @@ -99,7 +99,7 @@ const CreateProject: FC = () => {
.then(() => {
navigate(
`/ui/project/${values.name}/instances`,
notify.queue(notify.success(`Project ${values.name} created.`)),
notify.queue(success(`Project ${values.name} created.`)),
);
})
.catch((e: Error) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/projects/ProjectConfigurationHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as Yup from "yup";
import { useFormik } from "formik";
import { checkDuplicateName } from "util/helpers";
import DeleteProjectBtn from "./actions/DeleteProjectBtn";
import { useNotify } from "@canonical/react-components";
import { success, useNotify } from "@canonical/react-components";
import HelpLink from "components/HelpLink";
import { useEventQueue } from "context/eventQueue";
import { useDocs } from "context/useDocs";
Expand Down Expand Up @@ -53,7 +53,7 @@ const ProjectConfigurationHeader: FC<Props> = ({ project }) => {
() => {
navigate(
`/ui/project/${values.name}/configuration`,
notify.queue(notify.success("Project renamed.")),
notify.queue(success("Project renamed.")),
);
void formik.setFieldValue("isRenaming", false);
},
Expand Down
3 changes: 2 additions & 1 deletion src/pages/projects/actions/DeleteProjectBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useDeleteIcon } from "context/useDeleteIcon";
import {
ConfirmationButton,
Icon,
success,
useNotify,
} from "@canonical/react-components";
import classnames from "classnames";
Expand Down Expand Up @@ -43,7 +44,7 @@ const DeleteProjectBtn: FC<Props> = ({ project }) => {
.then(() => {
navigate(
`/ui/project/default/instances`,
notify.queue(notify.success(`Project ${project.name} deleted.`)),
notify.queue(success(`Project ${project.name} deleted.`)),
);
})
.catch((e) => {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/storage/StoragePoolHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { LxdStoragePool } from "types/storage";
import { renameStoragePool } from "api/storage-pools";
import DeleteStoragePoolBtn from "pages/storage/actions/DeleteStoragePoolBtn";
import { testDuplicateStoragePoolName } from "util/storagePool";
import { useNotify } from "@canonical/react-components";
import { success, useNotify } from "@canonical/react-components";

interface Props {
name: string;
Expand Down Expand Up @@ -42,7 +42,7 @@ const StoragePoolHeader: FC<Props> = ({ name, pool, project }) => {
.then(() => {
navigate(
`/ui/project/${project}/storage/detail/${values.name}`,
notify.queue(notify.success("Storage pool renamed.")),
notify.queue(success("Storage pool renamed.")),
);
void formik.setFieldValue("isRenaming", false);
})
Expand Down
4 changes: 2 additions & 2 deletions src/pages/storage/StorageVolumeHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as Yup from "yup";
import { LxdStorageVolume } from "types/storage";
import { renameStorageVolume } from "api/storage-pools";
import { testDuplicateStorageVolumeName } from "util/storageVolume";
import { useNotify } from "@canonical/react-components";
import { success, useNotify } from "@canonical/react-components";
import DeleteStorageVolumeBtn from "pages/storage/actions/DeleteStorageVolumeBtn";

interface Props {
Expand Down Expand Up @@ -49,7 +49,7 @@ const StorageVolumeHeader: FC<Props> = ({ volume, project }) => {
.then(() => {
navigate(
`/ui/project/${project}/storage/detail/${volume.pool}/${volume.type}/${values.name}`,
notify.queue(notify.success("Storage volume renamed.")),
notify.queue(success("Storage volume renamed.")),
);
void formik.setFieldValue("isRenaming", false);
})
Expand Down
23 changes: 2 additions & 21 deletions src/pages/storage/StorageVolumeSnapshots.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { FC, ReactNode, useEffect, useState } from "react";
import React, { FC, useEffect, useState } from "react";
import {
EmptyState,
Icon,
Expand Down Expand Up @@ -62,14 +62,6 @@ const StorageVolumeSnapshots: FC<Props> = ({ volume }) => {
}),
});

const onSuccess = (message: string) => {
notify.queue(notify.success(message));
};

const onFailure = (title: string, error: unknown, message?: ReactNode) => {
notify.failure(title, error, message);
};

const snapshotsDisabled = isSnapshotsDisabled(project);

useEffect(() => {
Expand Down Expand Up @@ -129,12 +121,7 @@ const StorageVolumeSnapshots: FC<Props> = ({ volume }) => {

const rows = filteredSnapshots.map((snapshot) => {
const actions = (
<VolumeSnapshotActions
volume={volume}
snapshot={snapshot}
onSuccess={onSuccess}
onFailure={onFailure}
/>
<VolumeSnapshotActions volume={volume} snapshot={snapshot} />
);

return {
Expand Down Expand Up @@ -227,8 +214,6 @@ const StorageVolumeSnapshots: FC<Props> = ({ volume }) => {
</div>
<VolumeConfigureSnapshotBtn
volume={volume}
onSuccess={onSuccess}
onFailure={onFailure}
className="u-no-margin--right"
/>
<VolumeAddSnapshotBtn
Expand All @@ -244,8 +229,6 @@ const StorageVolumeSnapshots: FC<Props> = ({ volume }) => {
snapshotNames={selectedNames}
onStart={() => setProcessingNames(selectedNames)}
onFinish={() => setProcessingNames([])}
onSuccess={onSuccess}
onFailure={onFailure}
/>
</div>
)}
Expand Down Expand Up @@ -323,8 +306,6 @@ const StorageVolumeSnapshots: FC<Props> = ({ volume }) => {
</p>
<VolumeConfigureSnapshotBtn
volume={volume}
onSuccess={onSuccess}
onFailure={onFailure}
isDisabled={snapshotsDisabled}
/>
<VolumeAddSnapshotBtn
Expand Down
3 changes: 2 additions & 1 deletion src/pages/storage/actions/DeleteStoragePoolBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { FC, useState } from "react";
import {
ConfirmationButton,
Icon,
success,
useNotify,
} from "@canonical/react-components";
import { useQueryClient } from "@tanstack/react-query";
Expand Down Expand Up @@ -39,7 +40,7 @@ const DeleteStoragePoolBtn: FC<Props> = ({
});
navigate(
`/ui/project/${project}/storage`,
notify.queue(notify.success(`Storage pool ${pool.name} deleted.`)),
notify.queue(success(`Storage pool ${pool.name} deleted.`)),
);
})
.catch((e) => {
Expand Down
Loading

0 comments on commit 38cacc1

Please sign in to comment.