Skip to content

Commit 04bb3d1

Browse files
authored
Merge pull request #1400 from chhsiao1981/refactor-drawer
replace drawerSlice with reducers.drawer
2 parents f732a61 + 675b6d7 commit 04bb3d1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1431
-1113
lines changed

src/components/AddPipeline/AddPipeline.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import { SpinContainer } from "../Common";
1111
import Pipelines from "../PipelinesCopy";
1212
import { PipelineContext, Types } from "../PipelinesCopy/context";
1313

14-
const AddPipeline = ({
15-
addNodeLocally,
16-
}: {
14+
type Props = {
1715
addNodeLocally: (instance: PluginInstance | PluginInstance[]) => void;
18-
}) => {
16+
isStaff: boolean;
17+
};
18+
export default (props: Props) => {
19+
const { addNodeLocally, isStaff } = props;
1920
const { state, dispatch } = useContext(PipelineContext);
2021
const { pipelineToAdd, selectedPipeline, computeInfo, titleInfo } = state;
2122
const reactDispatch = useAppDispatch();
@@ -155,7 +156,7 @@ const AddPipeline = ({
155156
</Fragment>,
156157
]}
157158
>
158-
<Pipelines />
159+
<Pipelines isStaff={isStaff} />
159160
{mutation.isError || mutation.isSuccess || mutation.isPending ? (
160161
<div id="indicators">
161162
{mutation.isError && (
@@ -170,5 +171,3 @@ const AddPipeline = ({
170171
</Modal>
171172
);
172173
};
173-
174-
export default AddPipeline;

src/components/ComputePage/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { ThunkModuleToFunc, UseThunk } from "@chhsiao1981/use-thunk";
22
import { PageSection } from "@patternfly/react-core";
33
import { useEffect } from "react";
4+
import type * as DoDrawer from "../../reducers/drawer";
45
import type * as DoUI from "../../reducers/ui";
56
import type * as DoUser from "../../reducers/user";
67
import Wrapper from "../Wrapper";
@@ -9,21 +10,28 @@ import Title from "./Title";
910

1011
type TDoUI = ThunkModuleToFunc<typeof DoUI>;
1112
type TDoUser = ThunkModuleToFunc<typeof DoUser>;
13+
type TDoDrawer = ThunkModuleToFunc<typeof DoDrawer>;
1214

1315
type Props = {
1416
useUI: UseThunk<DoUI.State, TDoUI>;
1517
useUser: UseThunk<DoUser.State, TDoUser>;
18+
useDrawer: UseThunk<DoDrawer.State, TDoDrawer>;
1619
};
1720

1821
export default (props: Props) => {
19-
const { useUI, useUser } = props;
22+
const { useUI, useUser, useDrawer } = props;
2023

2124
useEffect(() => {
2225
document.title = "Compute Catalog";
2326
}, []);
2427

2528
return (
26-
<Wrapper useUI={useUI} useUser={useUser} titleComponent={Title}>
29+
<Wrapper
30+
useUI={useUI}
31+
useUser={useUser}
32+
useDrawer={useDrawer}
33+
title={Title}
34+
>
2735
<PageSection>
2836
<ComputeCatalog />
2937
</PageSection>

src/components/CreateFeed/utils.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
1-
import type {
2-
Pipeline,
3-
PluginInstance,
4-
PluginMeta,
5-
Tag,
6-
} from "@fnndsc/chrisapi";
1+
import type { Pipeline, PluginMeta, Tag } from "@fnndsc/chrisapi";
72
import type { EventDataNode } from "rc-tree/lib/interface";
83
import ChrisAPIClient from "../../api/chrisapiclient";
94
import { fetchResource, fetchResources } from "../../api/common";
10-
import { fetchFolders } from "../NewLibrary";
11-
import type { ChRISFeed, DataBreadcrumb } from "./types/feed";
12-
13-
import constants from "../../datasets/constants";
14-
155
import type {
166
NodeInfo,
177
PipelineDefaultParameters,
188
Piping,
199
} from "../../api/types";
2010

11+
import constants from "../../datasets/constants";
12+
import fetchFolders from "../NewLibrary/utils/fetchFolders";
13+
import type { ChRISFeed, DataBreadcrumb } from "./types/feed";
14+
2115
export const computeWorkflowNodesInfo = (
2216
pipings: Piping[],
2317
params: PipelineDefaultParameters[],

src/components/DarkTheme/useTheme.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
useReducer,
77
} from "react";
88

9-
interface ThemeContextType {
9+
type ThemeContextType = {
1010
isDarkTheme: boolean;
1111
toggleTheme: () => void;
12-
}
12+
};
1313

1414
const THEME_STORAGE_KEY = "themePreference";
1515

@@ -40,10 +40,10 @@ const themeReducer = (
4040
}
4141
};
4242

43-
type ThemeContextProviderProps = {
43+
type Props = {
4444
children: ReactNode;
4545
};
46-
const ThemeContextProvider = (props: ThemeContextProviderProps) => {
46+
const ThemeContextProvider = (props: Props) => {
4747
const { children } = props;
4848
const [themeState, dispatch] = useReducer(themeReducer, {
4949
isDarkTheme: localStorage.getItem(THEME_STORAGE_KEY) !== "light",

src/components/Dashboard/index.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import {
1111
PageSection,
1212
} from "@patternfly/react-core";
1313
import { useEffect } from "react";
14-
import BUILD_VERSION from "../../getBuildVersion";
15-
import { InfoSection } from "../Common";
1614
import Wrapper from "../Wrapper";
1715
import FeedGraph from "./FeedGraph";
1816
import "./dashboard.css";
@@ -22,6 +20,7 @@ import {
2220
type UseThunk,
2321
} from "@chhsiao1981/use-thunk";
2422
import { useNavigate } from "react-router";
23+
import type * as DoDrawer from "../../reducers/drawer";
2524
import type * as DoUI from "../../reducers/ui";
2625
import * as DoUser from "../../reducers/user";
2726
import Title from "./Title";
@@ -33,14 +32,16 @@ import {
3332

3433
type TDoUI = ThunkModuleToFunc<typeof DoUI>;
3534
type TDoUser = ThunkModuleToFunc<typeof DoUser>;
35+
type TDoDrawer = ThunkModuleToFunc<typeof DoDrawer>;
3636

3737
type Props = {
3838
useUI: UseThunk<DoUI.State, TDoUI>;
3939
useUser: UseThunk<DoUser.State, TDoUser>;
40+
useDrawer: UseThunk<DoDrawer.State, TDoDrawer>;
4041
};
4142

4243
export default (props: Props) => {
43-
const { useUI, useUser } = props;
44+
const { useUI, useUser, useDrawer } = props;
4445
const [classStateUser, _] = useUser;
4546
const user = getState(classStateUser) || DoUser.defaultState;
4647
const { isLoggedIn } = user;
@@ -57,7 +58,12 @@ export default (props: Props) => {
5758
}, [isLoggedIn]);
5859

5960
return (
60-
<Wrapper titleComponent={Title} useUI={useUI} useUser={useUser}>
61+
<Wrapper
62+
title={Title}
63+
useUI={useUI}
64+
useUser={useUser}
65+
useDrawer={useDrawer}
66+
>
6167
<PageSection>
6268
<Grid hasGutter>
6369
<GridItem span={12}>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import {
2+
getRootID,
3+
type ThunkModuleToFunc,
4+
type UseThunk,
5+
} from "@chhsiao1981/use-thunk";
6+
import type { ReactNode } from "react";
7+
import type * as DoDrawer from "../../reducers/drawer";
8+
import type { ActionType } from "../../reducers/drawer";
9+
import { ButtonWithTooltip } from "../Feeds/DrawerUtils";
10+
11+
type TDoDrawer = ThunkModuleToFunc<typeof DoDrawer>;
12+
13+
type Props = {
14+
actionType: ActionType;
15+
icon: ReactNode;
16+
title: string;
17+
isDisabled: boolean;
18+
19+
useDrawer: UseThunk<DoDrawer.State, TDoDrawer>;
20+
};
21+
22+
export default (props: Props) => {
23+
const { actionType, icon, title, isDisabled, useDrawer } = props;
24+
const [classStateDrawer, doDrawer] = useDrawer;
25+
const drawerID = getRootID(classStateDrawer);
26+
return (
27+
<ButtonWithTooltip
28+
position="bottom"
29+
className="button-style large-button"
30+
content={<span>{title}</span>}
31+
Icon={icon}
32+
variant="primary"
33+
onClick={() => {
34+
doDrawer.toggle(drawerID, actionType);
35+
}}
36+
isDisabled={isDisabled}
37+
/>
38+
);
39+
};

0 commit comments

Comments
 (0)