Skip to content

Commit 00ce76a

Browse files
Adwoa-Konadu-Appiahjpgough-msoliviajanejohns
authored
Visualize Calm Instance Without Uploading File (finos#1020)
* WIP: Visualize Calm Instance Without Uploading File * WIP: Visualize Calm Instance from Uploading File and Calm Hub * finos#989 correct removed file * finos#989 added data as a dependecy to the use affect --------- Co-authored-by: jpgough-ms <152306432+jpgough-ms@users.noreply.github.com> Co-authored-by: Olivia Johnson <35664512+oliviajanejohns@users.noreply.github.com>
1 parent 2a0e5a5 commit 00ce76a

File tree

5 files changed

+44
-18
lines changed

5 files changed

+44
-18
lines changed

calm-hub-ui/src/hub/Hub.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import {
77
FlowID,
88
ArchitectureID,
99
Version,
10-
Pattern,
11-
Flow,
12-
Architecture,
10+
Data,
1311
} from '../model/calm.js';
1412
import {
1513
fetchNamespaces,
@@ -35,7 +33,7 @@ function Hub() {
3533
const [currentVersion, setCurrentVersion] = useState<Version | undefined>();
3634
const [currentCalmType, setCurrentCalmType] = useState<string | undefined>();
3735

38-
const [data, setData] = useState<Pattern | Flow | Architecture | undefined>();
36+
const [data, setData] = useState<Data | undefined>();
3937
const [versions, setVersions] = useState<Version[]>([]);
4038

4139
useEffect(() => {
@@ -152,7 +150,7 @@ function Hub() {
152150
/>
153151
)}
154152
</div>
155-
<JsonRenderer jsonString={data} />
153+
<JsonRenderer jsonString={ data } />
156154
</div>
157155
</>
158156
);
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,31 @@
1+
import { useNavigate } from 'react-router-dom';
12
import { allExpanded, defaultStyles, JsonView } from 'react-json-view-lite';
23
import 'react-json-view-lite/dist/index.css';
4+
import { Data } from '../../model/calm.js';
35

46
interface JsonRendererProps {
5-
jsonString: string | undefined;
7+
jsonString: Data | undefined;
68
}
79

810
export function JsonRenderer({ jsonString }: JsonRendererProps) {
911
const defaultMessage = <div className=" text-center">Please select a document to load.</div>;
12+
const navigate = useNavigate();
1013
const jsonView = (
11-
<JsonView data={jsonString || ''} shouldExpandNode={allExpanded} style={defaultStyles} />
14+
<div>
15+
<button className="bg-primary hover:bg-blue-500 text-white font-bold py-2 px-4 rounded float-right" onClick={handleClick}>
16+
Visualize
17+
</button>
18+
<JsonView data={jsonString || ''} shouldExpandNode={allExpanded} style={defaultStyles} />
19+
</div>
20+
1221
);
22+
function handleClick() {
23+
navigate('/visualizer', { state: jsonString });
24+
}
1325

1426
const content = jsonString ? jsonView : defaultMessage;
1527

16-
return <div className="p-5 flex-1 overflow-auto bg-[#eee]">{content}</div>;
28+
return (
29+
<div className="p-5 flex-1 overflow-auto bg-[#eee]">{content}</div>
30+
);
1731
}

calm-hub-ui/src/model/calm.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ export type ArchitectureID = string;
66
export type FlowID = string;
77
export type Flow = string;
88
export type Version = string;
9+
export type Data = {
10+
name: Namespace,
11+
data: Pattern | Architecture | Flow | undefined
12+
};

calm-hub-ui/src/service/calm-service.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import {
22
Namespace,
3-
Pattern,
43
PatternID,
54
Version,
6-
Flow,
75
FlowID,
8-
Architecture,
96
ArchitectureID,
7+
Data,
108
} from '../model/calm.js';
119
import { getToken } from "../authService";
1210

@@ -113,7 +111,7 @@ export async function fetchPattern(
113111
namespace: string,
114112
patternID: string,
115113
version: string,
116-
setPattern: (pattern: Pattern) => void
114+
setPattern: (pattern: Data) => void
117115
) {
118116
try {
119117
const accessToken = await getToken();
@@ -122,7 +120,8 @@ export async function fetchPattern(
122120
method: 'GET',
123121
headers: {'Authorization': `Bearer ${accessToken}`,},
124122
});
125-
const data = await res.json();
123+
const response = await res.json();
124+
const data: Data = { name: namespace, data: response}
126125
setPattern(data);
127126
} catch (error) {
128127
console.error(
@@ -139,7 +138,7 @@ export async function fetchFlow(
139138
namespace: string,
140139
flowID: string,
141140
version: string,
142-
setFlow: (flow: Flow) => void
141+
setFlow: (flow: Data) => void
143142
) {
144143
try {
145144
const accessToken = await getToken();
@@ -148,7 +147,8 @@ export async function fetchFlow(
148147
method: 'GET',
149148
headers: {'Authorization': `Bearer ${accessToken}`,},
150149
});
151-
const data = await res.json();
150+
const response = await res.json();
151+
const data: Data = { name: namespace, data: response}
152152
setFlow(data);
153153
} catch (error) {
154154
console.error(
@@ -207,7 +207,7 @@ export async function fetchArchitecture(
207207
namespace: string,
208208
architectureID: string,
209209
version: string,
210-
setArchitecture: (architecture: Architecture) => void
210+
setArchitecture: (architecture: Data) => void
211211
) {
212212
try {
213213
const accessToken = await getToken();
@@ -216,7 +216,8 @@ export async function fetchArchitecture(
216216
method: 'GET',
217217
headers: {'Authorization': `Bearer ${accessToken}`,},
218218
});
219-
const data = await res.json();
219+
const response = await res.json();
220+
const data: Data = { name: namespace, data: response}
220221
setArchitecture(data);
221222
} catch (error) {
222223
console.error(

calm-hub-ui/src/visualizer/Visualizer.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
import { useState } from 'react';
1+
import { useEffect, useState } from 'react';
22
import './Visualizer.css';
33
import Drawer from './components/drawer/Drawer.js';
44
import Navbar from '../components/navbar/Navbar.js';
55
import React from 'react';
66
import { ZoomProvider } from './components/zoom-context.provider.js';
77
import { CALMArchitecture } from '../../../shared/src/types.js';
88
import Menu from './components/menu/Menu.js';
9+
import { useLocation } from "react-router-dom";
910

1011
function Visualizer() {
1112
const [title, setTitle] = useState<string | undefined>(undefined);
1213
const [instance, setCALMInstance] = useState<CALMArchitecture | undefined>(undefined);
1314
const [isConDescActive, setConDescActive] = React.useState(false);
1415
const [isNodeDescActive, setNodeDescActive] = React.useState(false);
1516

17+
const location = useLocation();
18+
const data = location.state || {};
19+
1620
async function handleFile(instanceFile: File) {
1721
const title = instanceFile.name;
1822
const file = await instanceFile.text();
@@ -21,6 +25,11 @@ function Visualizer() {
2125
setTitle(title);
2226
setCALMInstance(instance);
2327
}
28+
29+
useEffect(() => {
30+
setTitle(data?.name)
31+
setCALMInstance(data?.data);
32+
}, [data]);
2433

2534
return (
2635
<ZoomProvider>

0 commit comments

Comments
 (0)