Skip to content

Commit 396135f

Browse files
authored
Merge pull request #1398 from chhsiao1981/refactor-ui
replace uiSlice to reducers.ui (use-thunk)
2 parents 29cdc82 + 1ad6b53 commit 396135f

File tree

34 files changed

+422
-302
lines changed

34 files changed

+422
-302
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"react-dropzone": "^14.2.3",
8989
"react-error-boundary": "^4.0.13",
9090
"react-force-graph-2d": "^1.25.5",
91-
"@chhsiao1981/use-thunk": "^9.0.0",
91+
"@chhsiao1981/use-thunk": "^9.0.2",
9292
"react-redux": "^9.1.2",
9393
"react-resizable-panels": "^2.1.4",
9494
"react-responsive": "^10.0.0",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/ComputePage/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1+
import type { ThunkModuleToFunc, UseThunk } from "@chhsiao1981/use-thunk";
12
import { PageSection } from "@patternfly/react-core";
23
import React from "react";
4+
import type * as DoUI from "../../reducers/ui";
35
import { InfoSection } from "../Common";
4-
import WrapperConnect from "../Wrapper";
6+
import Wrapper from "../Wrapper";
57
import ComputeCatalog from "./ComputeCatalog";
68

9+
type TDoUI = ThunkModuleToFunc<typeof DoUI>;
10+
11+
type Props = {
12+
useUI: UseThunk<DoUI.State, TDoUI>;
13+
};
14+
715
const TitleComponent = (
816
<InfoSection
917
title="Compute"
@@ -21,17 +29,16 @@ const TitleComponent = (
2129
/>
2230
);
2331

24-
const ComputePage = () => {
32+
export default (props: Props) => {
33+
const { useUI } = props;
2534
React.useEffect(() => {
2635
document.title = "Compute Catalog";
2736
}, []);
2837
return (
29-
<WrapperConnect titleComponent={TitleComponent}>
38+
<Wrapper useUI={useUI} titleComponent={TitleComponent}>
3039
<PageSection>
3140
<ComputeCatalog />
3241
</PageSection>
33-
</WrapperConnect>
42+
</Wrapper>
3443
);
3544
};
36-
37-
export default ComputePage;

src/components/Dashboard/index.tsx

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@ import {
1010
GridItem,
1111
PageSection,
1212
} from "@patternfly/react-core";
13-
import type React from "react";
1413
import { useEffect } from "react";
1514
import BUILD_VERSION from "../../getBuildVersion";
1615
import { InfoSection } from "../Common";
17-
import WrapperConnect from "../Wrapper";
16+
import Wrapper from "../Wrapper";
1817
import FeedGraph from "./FeedGraph";
1918
import "./dashboard.css";
19+
import type { ThunkModuleToFunc, UseThunk } from "@chhsiao1981/use-thunk";
20+
import type * as DoUI from "../../reducers/ui";
2021
import {
2122
covidnetDataset,
2223
fetalBrainReconstructionDataset,
2324
lldDataset,
2425
} from "./util";
2526

26-
const DashboardPage: React.FC = () => {
27+
type TDoUI = ThunkModuleToFunc<typeof DoUI>;
28+
29+
type Props = {
30+
useUI: UseThunk<DoUI.State, TDoUI>;
31+
};
32+
33+
export default (props: Props) => {
34+
const { useUI } = props;
35+
2736
useEffect(() => {
2837
document.title = "Overview";
2938
}, []);
@@ -44,7 +53,7 @@ const DashboardPage: React.FC = () => {
4453
);
4554

4655
return (
47-
<WrapperConnect titleComponent={TitleComponent}>
56+
<Wrapper titleComponent={TitleComponent} useUI={useUI}>
4857
<PageSection>
4958
<Grid hasGutter>
5059
<GridItem span={12}>
@@ -133,8 +142,6 @@ const DashboardPage: React.FC = () => {
133142
</GridItem>
134143
</Grid>
135144
</PageSection>
136-
</WrapperConnect>
145+
</Wrapper>
137146
);
138147
};
139-
140-
export default DashboardPage;

src/components/Feeds/FeedListView.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { ThunkModuleToFunc, UseThunk } from "@chhsiao1981/use-thunk";
12
import type { Feed, FileBrowserFolder } from "@fnndsc/chrisapi";
23
import { ChartDonutUtilization } from "@patternfly/react-charts";
34
import {
@@ -9,9 +10,6 @@ import {
910
Pagination,
1011
Skeleton,
1112
Title,
12-
ToggleGroup,
13-
ToggleGroupItem,
14-
type ToggleGroupItemProps,
1513
Tooltip,
1614
} from "@patternfly/react-core";
1715
import {
@@ -27,23 +25,20 @@ import { useQuery } from "@tanstack/react-query";
2725
import { format } from "date-fns";
2826
import { debounce } from "lodash";
2927
import type React from "react";
30-
import { useContext, useEffect, useMemo, useState, useRef } from "react";
28+
import { useContext, useEffect, useMemo, useRef, useState } from "react";
3129
import { useMediaQuery } from "react-responsive";
3230
import { useNavigate } from "react-router";
31+
import type * as DoUI from "../../reducers/ui";
3332
import { useAppSelector } from "../../store/hooks";
34-
import { AddNodeProvider } from "../AddNode/context";
3533
import { Typography } from "../Antd";
3634
import { InfoSection } from "../Common";
37-
import CreateFeed from "../CreateFeed/CreateFeed";
38-
import { CreateFeedProvider } from "../CreateFeed/context";
3935
import { ThemeContext } from "../DarkTheme/useTheme";
4036
import { SearchIcon } from "../Icons";
4137
import { FolderContextMenu } from "../NewLibrary/components/ContextMenu";
4238
import Operations from "../NewLibrary/components/Operations";
4339
import { OperationContext } from "../NewLibrary/context";
4440
import useLongPress from "../NewLibrary/utils/longpress";
45-
import { PipelineProvider } from "../PipelinesCopy/context";
46-
import WrapperConnect from "../Wrapper";
41+
import Wrapper from "../Wrapper";
4742
import FeedSearch from "./FeedsSearch";
4843
import { useFeedListData } from "./useFeedListData";
4944
import {
@@ -53,6 +48,8 @@ import {
5348
type PluginInstanceDetails,
5449
} from "./utilties";
5550

51+
type TDoUI = ThunkModuleToFunc<typeof DoUI>;
52+
5653
const { Paragraph } = Typography;
5754

5855
interface ColumnDefinition {
@@ -96,13 +93,14 @@ const COLUMN_DEFINITIONS: ColumnDefinition[] = [
9693
},
9794
];
9895

99-
interface Props {
96+
type Props = {
10097
title: string;
10198
isShared: boolean;
102-
}
99+
useUI: UseThunk<DoUI.State, TDoUI>;
100+
};
103101

104-
const TableSelectable = (props: Props) => {
105-
const { title, isShared } = props;
102+
export default (props: Props) => {
103+
const { title, isShared, useUI } = props;
106104
const theType = isShared ? "public" : "private";
107105

108106
const navigate = useNavigate();
@@ -252,7 +250,7 @@ const TableSelectable = (props: Props) => {
252250
const isMobile = useMediaQuery({ maxWidth: 768 });
253251

254252
return (
255-
<WrapperConnect titleComponent={TitleComponent}>
253+
<Wrapper useUI={useUI} titleComponent={TitleComponent}>
256254
<PageSection
257255
stickyOnBreakpoint={{ default: "top" }}
258256
style={{ paddingTop: "0.25em", paddingBottom: "0" }}
@@ -323,12 +321,10 @@ const TableSelectable = (props: Props) => {
323321
<EmptyStateTable />
324322
)}
325323
</PageSection>
326-
</WrapperConnect>
324+
</Wrapper>
327325
);
328326
};
329327

330-
export default TableSelectable;
331-
332328
// -------------- TableRow Props --------------
333329
interface TableRowProps {
334330
rowIndex: number;
@@ -523,7 +519,7 @@ const fetchFeedDetails = async (
523519
feedId: number,
524520
type: string,
525521
): Promise<PluginInstanceDetails> => {
526-
let updatedFeed: Feed | undefined = undefined;
522+
let updatedFeed: Feed | undefined;
527523

528524
try {
529525
if (type === "private") {

src/components/Feeds/FeedView.tsx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,29 @@ import FeedGraph from "../FeedTree/FeedGraph";
2323
import ParentComponent from "../FeedTree/ParentComponent";
2424
import { AnalysisIcon } from "../Icons";
2525
import NodeDetails from "../NodeDetails/NodeDetails";
26-
import WrapperConnect from "../Wrapper";
26+
import Wrapper from "../Wrapper";
2727
import { DrawerActionButton } from "./DrawerUtils";
2828
import usePaginatedTreeQuery from "./usePaginatedTreeQuery";
2929
import "./Feeds.css"; // Import your CSS file
30+
import type { ThunkModuleToFunc, UseThunk } from "@chhsiao1981/use-thunk";
3031
import { collectionJsonToJson } from "../../api/api";
3132
import {
3233
PluginInstanceStatus,
3334
type PluginInstance as PluginInstanceType,
3435
} from "../../api/types";
36+
import type * as DoUI from "../../reducers/ui";
3537
import { Role } from "../../store/user/userSlice";
3638
import { useFetchFeed } from "./useFetchFeed";
3739
import { useSearchQueryParams } from "./usePaginate";
3840
import { usePollAllPluginStatuses } from "./usePolledStatuses";
3941
import { handleMaximize, handleMinimize } from "./utilties";
4042

43+
type TDoUI = ThunkModuleToFunc<typeof DoUI>;
44+
45+
type Props = {
46+
useUI: UseThunk<DoUI.State, TDoUI>;
47+
};
48+
4149
// Custom title component to replace Typography.Title
4250
const CustomTitle = ({
4351
// @ts-expect-error children as any
@@ -62,7 +70,8 @@ const CustomTitle = ({
6270
</h4>
6371
);
6472

65-
const FeedView = () => {
73+
export default (props: Props) => {
74+
const { useUI } = props;
6675
const [currentLayout, setCurrentLayout] = useState(false);
6776
const drawerState = useAppSelector((state) => state.drawers);
6877
const dispatch = useAppDispatch();
@@ -89,15 +98,6 @@ const FeedView = () => {
8998
}
9099
}, [theType, isLoggedIn, location, navigate]);
91100

92-
console.info(
93-
"FeedView: feed:",
94-
feed,
95-
"statuses:",
96-
statuses,
97-
"treeQuery:",
98-
treeQuery,
99-
);
100-
101101
// init
102102
useEffect(() => {
103103
document.title = "My Analyses - CHRIS UI";
@@ -207,7 +207,7 @@ const FeedView = () => {
207207
}
208208

209209
return (
210-
<WrapperConnect titleComponent={TitleComponent}>
210+
<Wrapper useUI={useUI} titleComponent={TitleComponent}>
211211
{contextHolder}
212212
<PanelGroup autoSaveId="conditional" direction="vertical">
213213
{/* Top Panels: Graph and Node Details */}
@@ -288,8 +288,6 @@ const FeedView = () => {
288288
/>
289289
</Panel>
290290
</PanelGroup>
291-
</WrapperConnect>
291+
</Wrapper>
292292
);
293293
};
294-
295-
export default React.memo(FeedView);

src/components/GnomeLibrary/index.tsx

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,27 @@
1-
import { useCallback, useEffect, useState, useMemo } from "react";
1+
import type { ThunkModuleToFunc, UseThunk } from "@chhsiao1981/use-thunk";
2+
import type { FileBrowserFolder } from "@fnndsc/chrisapi";
3+
import { useQueryClient } from "@tanstack/react-query";
4+
import { useCallback, useEffect, useMemo, useState } from "react";
25
import { useLocation, useNavigate } from "react-router-dom";
6+
import type * as DoUI from "../../reducers/ui";
37
import { useAppSelector } from "../../store/hooks";
4-
import { EmptyStateComponent, SpinContainer, InfoSection } from "../Common";
8+
import { EmptyStateComponent, InfoSection, SpinContainer } from "../Common";
59
import { OperationContext, OperationsProvider } from "../NewLibrary/context";
6-
import WrapperConnect from "../Wrapper";
10+
import Wrapper from "../Wrapper";
711
import GnomeCentralBreadcrumb from "./GnomeCentralBreadcrumb";
812
import GnomeLibraryTable from "./GnomeList";
913
import GnomeLibrarySidebar from "./GnomeSidebar";
1014
import styles from "./gnome.module.css";
1115
import useFolders from "./utils/hooks/useFolders";
12-
import type { FileBrowserFolder } from "@fnndsc/chrisapi";
13-
import { useQueryClient } from "@tanstack/react-query";
1416

15-
const GnomeLibrary = () => {
17+
type TDoUI = ThunkModuleToFunc<typeof DoUI>;
18+
19+
type Props = {
20+
useUI: UseThunk<DoUI.State, TDoUI>;
21+
};
22+
23+
export default (props: Props) => {
24+
const { useUI } = props;
1625
const [activeSidebarItem, setActiveSidebarItem] = useState<string>("home");
1726
const [pageNumber, setPageNumber] = useState(1);
1827
const [isFirstLoad, setIsFirstLoad] = useState(true);
@@ -129,7 +138,8 @@ const GnomeLibrary = () => {
129138

130139
return (
131140
<OperationsProvider>
132-
<WrapperConnect
141+
<Wrapper
142+
useUI={useUI}
133143
titleComponent={
134144
<InfoSection
135145
title="Library"
@@ -199,9 +209,7 @@ const GnomeLibrary = () => {
199209
</span>
200210
</div>
201211
</div>
202-
</WrapperConnect>
212+
</Wrapper>
203213
</OperationsProvider>
204214
);
205215
};
206-
207-
export default GnomeLibrary;

0 commit comments

Comments
 (0)