Skip to content

Commit e91bd1a

Browse files
authored
Merge pull request #1347 from chhsiao1981/clinician-default-view
clinician default view
2 parents 22f3fde + 7ecf88f commit e91bd1a

File tree

12 files changed

+285
-117
lines changed

12 files changed

+285
-117
lines changed

src/api/api.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ const collectionJsonItemToJson = (item: any) =>
7070
return r;
7171
}, {});
7272

73-
const collectionJsonToJson = (theData: any) =>
74-
theData.collection.items.map(collectionJsonItemToJson);
73+
export const collectionJsonToJson = (theData: any) => {
74+
const ret = theData.collection.items.map(collectionJsonItemToJson);
75+
return typeof theData.collection.total === "undefined" ? ret[0] : ret;
76+
};
7577

7678
const callApi = async <T>(
7779
endpoint: string,
@@ -186,11 +188,7 @@ const fetchCore = async <T>(
186188
collectionJsonData,
187189
);
188190

189-
const data =
190-
!isJson &&
191-
typeof collectionJsonData.collection.total === "undefined"
192-
? jsonData[0]
193-
: jsonData;
191+
const data = jsonData;
194192

195193
return { status: res.status, data: data };
196194
})

src/api/types.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export interface Feed {
1616
cancelled_jobs: number;
1717
}
1818

19+
export enum PluginInstanceStatus {
20+
SUCCESS = "finishedSuccessfully",
21+
}
22+
1923
export interface PluginInstance {
2024
id: number;
2125
title: string;
@@ -29,7 +33,7 @@ export interface PluginInstance {
2933
start_date: string; // yyyy-mm-ddTHH:MM:SS.ffffffTZ
3034
end_date: string; // yyyy-mm-ddTHH:MM:SS.ffffffTZ
3135
output_path: string;
32-
status: string;
36+
status: PluginInstanceStatus;
3337
pipeline_id: number;
3438
}
3539

@@ -70,6 +74,16 @@ export interface NodeInfo {
7074
title: string;
7175
}
7276

77+
export interface Piping {
78+
id: number;
79+
pipeline_id: number;
80+
plugin_id: number;
81+
plugin_name: string;
82+
plugin_version: string;
83+
title: string;
84+
previous_id: number;
85+
}
86+
7387
export interface PipelineDefaultParameters {
7488
id: number;
7589
param_id: number;

src/components/CreateFeed/createFeedHelper.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
createPluginInstance as serverCreatePluginInstance,
2020
updateFeedName,
2121
} from "../../api/serverApi";
22+
import { collectionJsonToJson } from "../../api/api";
2223

2324
const createFeedCore = async (
2425
dirpath: ChRISFeed[],
@@ -55,19 +56,34 @@ const createFeedCore = async (
5556
pipelineState;
5657

5758
const pipelineID = pipelineToAdd?.data.id;
58-
const resources = selectedPipeline?.[pipelineID];
59+
const pipeline = selectedPipeline?.[pipelineID];
5960

6061
console.info(
6162
"createFeedCore: pipelineID:",
6263
pipelineID,
63-
"resources:",
64-
resources,
64+
"pipeline:",
65+
pipeline,
66+
"pipelineToAdd:",
67+
pipelineToAdd,
68+
"pipelineState:",
69+
pipelineState,
6570
);
6671

67-
if (resources) {
68-
const { parameters } = resources;
72+
if (pipeline) {
73+
const { pluginPipings: propsPluginPipings, parameters } = pipeline;
6974

70-
const nodes_info = computeWorkflowNodesInfo(parameters.data);
75+
const pluginPipings = propsPluginPipings.map((eachPluginPiping) =>
76+
collectionJsonToJson(eachPluginPiping),
77+
);
78+
79+
console.info(
80+
"createFeedCore: pluginPipings:",
81+
pluginPipings,
82+
"params:",
83+
parameters.data,
84+
);
85+
86+
const nodes_info = computeWorkflowNodesInfo(pluginPipings, parameters.data);
7187

7288
for (const node of nodes_info) {
7389
// Set compute info

src/components/CreateFeed/utils.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,40 +12,34 @@ import type { ChRISFeed, DataBreadcrumb } from "./types/feed";
1212

1313
import constants from "../../datasets/constants";
1414

15-
import type { NodeInfo, PipelineDefaultParameters } from "../../api/types";
16-
import { info } from "console";
15+
import type {
16+
NodeInfo,
17+
PipelineDefaultParameters,
18+
Piping,
19+
} from "../../api/types";
1720

1821
export const computeWorkflowNodesInfo = (
22+
pipings: Piping[],
1923
params: PipelineDefaultParameters[],
2024
): NodeInfo[] => {
21-
const pipingSet = new Set();
22-
const dedupParams = params.filter((each) => {
23-
if (pipingSet.has(each.plugin_piping_id)) {
24-
return false;
25-
}
26-
27-
pipingSet.add(each.plugin_piping_id);
28-
29-
return true;
30-
});
31-
32-
const theRet = dedupParams.map((each): NodeInfo => {
25+
const theRet = pipings.map((each): NodeInfo => {
3326
return {
34-
piping_id: each.plugin_piping_id,
35-
previous_piping_id: each.previous_plugin_piping_id,
27+
piping_id: each.id,
28+
previous_piping_id: each.previous_id,
3629
compute_resource_name: "host",
37-
title: each.plugin_piping_title,
30+
title: each.title,
3831
};
3932
});
4033

4134
console.info(
42-
"utils.computeWorkflowNodesInfo: params:",
43-
params,
35+
"utils.computeWorkflowNodesInfo: pipings:",
36+
pipings,
4437
"theRet:",
4538
theRet,
4639
);
4740
return theRet;
4841
};
42+
4943
export const getFullFeedName = (
5044
analysisPrefix: string,
5145
chrisFeed: ChRISFeed,

src/components/FeedOutputBrowser/FeedOutputBrowser.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ const FeedOutputBrowser: React.FC<FeedOutputBrowserProps> = (props) => {
3333
handlePagination,
3434
finished,
3535
} = useFeedBrowser(props.statuses);
36+
37+
console.info(
38+
"FeedOutputBrowser: pluginFilesPayload:",
39+
pluginFilesPayload,
40+
"selected:",
41+
selected,
42+
"statuses:",
43+
props.statuses,
44+
);
45+
3646
return (
3747
<div style={{ height: "100%" }} className="feed-output-browser">
3848
{!finished ? (

src/components/FeedTree/FeedGraph.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const FeedGraph: React.FC<IFeedProps> = ({
3232
const selectedPlugin = useAppSelector(
3333
(state) => state.instance.selectedPlugin,
3434
);
35+
36+
console.info("FeedGraph: selectedPlugin:", selectedPlugin);
3537
//const { data: instances, loading } = pluginInstances;
3638
const graphRef = React.useRef<HTMLDivElement | null>(null);
3739
const fgRef = React.useRef<ForceGraphMethods>();

src/components/FeedTree/ParentComponent.tsx

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import { SpinContainer } from "../Common";
77
import FeedTree from "./FeedTree";
88
import type { TreeNodeDatum } from "./data";
99
import type { PaginatedTreeQueryReturn } from "../Feeds/usePaginatedTreeQuery";
10-
import type { Feed } from "@fnndsc/chrisapi";
10+
import type { Feed, PluginInstance } from "@fnndsc/chrisapi";
11+
import { collectionJsonToJson } from "../../api/api";
12+
import type { PluginInstance as PluginInstanceType } from "../../api/types";
1113

1214
interface ParentComponentProps {
1315
changeLayout: () => void;
@@ -44,14 +46,43 @@ const ParentComponent: React.FC<ParentComponentProps> = ({
4446

4547
const stableRootNode = useMemo(() => rootNode, [rootNode]);
4648

49+
const lastPluginInstance = pluginInstances.reduce(
50+
(r: PluginInstance | null, x, i) => {
51+
if (r === null) {
52+
return x;
53+
}
54+
const rJson = collectionJsonToJson(r);
55+
const xJson = collectionJsonToJson(x);
56+
57+
return rJson.id <= xJson.id ? x : r;
58+
},
59+
null,
60+
);
61+
62+
console.info(
63+
"ParentComponent: pluginInstances:",
64+
pluginInstances,
65+
"lastPluginInstance:",
66+
lastPluginInstance,
67+
);
68+
4769
useEffect(() => {
48-
if (stableRootNode?.item && !selectedPlugin) {
49-
dispatch(getSelectedPlugin(stableRootNode.item));
70+
if (!stableRootNode?.item || selectedPlugin || !lastPluginInstance) {
71+
return;
5072
}
51-
}, [stableRootNode, dispatch, selectedPlugin]);
73+
74+
console.info(
75+
"ParentComponent: stableRootNode:",
76+
stableRootNode,
77+
"lastPluginInstance:",
78+
lastPluginInstance,
79+
);
80+
dispatch(getSelectedPlugin(lastPluginInstance));
81+
}, [stableRootNode, dispatch, selectedPlugin, lastPluginInstance]);
5282

5383
const onNodeClick = useCallback(
5484
(node: TreeNodeDatum) => {
85+
console.info("ParentComponent: onNodeClick: node:", node.item);
5586
node.item && dispatch(getSelectedPlugin(node.item));
5687
},
5788
[dispatch],

0 commit comments

Comments
 (0)