Skip to content

Commit 894c6c9

Browse files
committed
integrate end to end the upload scan flow
1 parent 3abf6b3 commit 894c6c9

7 files changed

Lines changed: 76 additions & 22 deletions

File tree

packages/flowtest-cli/bin/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const argv = yargs(hideBin(process.argv))
4545
})
4646
.option('timeout', {
4747
alias: 't',
48-
describe: 'timeout for graph run in ms',
48+
describe: 'timeout for flow run in ms',
4949
demandOption: false,
5050
type: 'number',
5151
})
@@ -78,7 +78,7 @@ const argv = yargs(hideBin(process.argv))
7878
argv.env ? getEnvVariables(argv.env) : {},
7979
logger,
8080
);
81-
console.log(chalk.yellow('Running Graph \n'));
81+
console.log(chalk.yellow('Running Flow \n'));
8282
if (flowData.nodes.find((n) => n.type === 'complexNode')) {
8383
console.log(
8484
chalk.blue(
@@ -89,9 +89,9 @@ const argv = yargs(hideBin(process.argv))
8989
const result = await g.run();
9090
console.log('\n');
9191
if (result.status === 'Success') {
92-
console.log(chalk.bold('Graph Run: ') + chalk.green(` ✓ `) + chalk.dim(result.status));
92+
console.log(chalk.bold('Flow Run: ') + chalk.green(` ✓ `) + chalk.dim(result.status));
9393
} else {
94-
console.log(chalk.bold('Graph Run: ') + chalk.red(` ✕ `) + chalk.dim(result.status));
94+
console.log(chalk.bold('Flow Run: ') + chalk.red(` ✕ `) + chalk.dim(result.status));
9595
}
9696
logger.add(LogLevel.INFO, `Total time: ${Date.now() - startTime} ms`);
9797
console.log(chalk.bold('Total Time: ') + chalk.dim(`${Date.now() - startTime} ms`));
@@ -108,18 +108,18 @@ const argv = yargs(hideBin(process.argv))
108108
'/upload',
109109
bytesToBase64(new TextEncoder().encode(JSON.stringify(data))),
110110
);
111-
console.log(chalk.bold('Build Scan: ') + chalk.dim(`${baseUrl}/scan/${response.data.data[0].id}`));
111+
console.log(chalk.bold('Flow Scan: ') + chalk.dim(`${baseUrl}/scan/${response.data.data[0].id}`));
112112
} catch (error) {
113113
if (error?.response) {
114-
if (error.response?.status === 403 || error.response?.status === 429) {
114+
if (error.response?.status >= 400 && error.response?.status < 500) {
115115
console.log(chalk.red(` ${JSON.stringify(error.response?.data)}`));
116116
}
117117

118118
if (error.response?.status === 500) {
119119
console.log(chalk.red(' Internal Server Error'));
120120
}
121121
}
122-
console.log(chalk.red(` ✕ `) + chalk.dim('Unable to upload build scan'));
122+
console.log(chalk.red(` ✕ `) + chalk.dim('Unable to upload flow scan'));
123123
}
124124
}
125125

packages/flowtest-electron/electron-main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const url = require('url');
55
const template = require('./electron-menu');
66
const Watcher = require('./src/app/watcher');
77
const registerRendererEventHandlers = require('./src/ipc/collection');
8+
const registerSettingsEventHandlers = require('./src/ipc/settings');
89

910
let mainWindow;
1011
let watcher;
@@ -59,6 +60,7 @@ app.on('ready', async () => {
5960
watcher = new Watcher();
6061

6162
registerRendererEventHandlers(mainWindow, watcher);
63+
registerSettingsEventHandlers(mainWindow);
6264
});
6365

6466
// Quit when all windows are closed, except on macOS. There, it's common

packages/flowtest-electron/src/ipc/collection.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,25 +361,25 @@ const registerRendererEventHandlers = (mainWindow, watcher) => {
361361
};
362362
} catch (error) {
363363
if (error?.response) {
364-
if (error.response?.status === 403 || error.response?.status === 429) {
364+
if (error.response?.status >= 400 && error.response?.status < 500) {
365365
return {
366366
upload: 'fail',
367-
message: 'Unable to upload build scan',
367+
message: 'Unable to upload flow scan',
368368
reason: `${JSON.stringify(error.response?.data)}`,
369369
};
370370
}
371371

372372
if (error.response?.status === 500) {
373373
return {
374374
upload: 'fail',
375-
message: 'Unable to upload build scan',
375+
message: 'Unable to upload flow scan',
376376
reason: 'Internal Server Error',
377377
};
378378
}
379379
}
380380
return {
381381
upload: 'fail',
382-
message: 'Unable to upload build scan',
382+
message: 'Unable to upload flow scan',
383383
};
384384
}
385385
} catch (error) {

src/components/molecules/flow/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Button from 'components/atoms/common/Button';
2727
import { BUTTON_INTENT_TYPES, BUTTON_TYPES } from 'constants/Common';
2828
import GraphLogger, { LogLevel } from './graph/GraphLogger';
2929
import Mousetrap from 'mousetrap';
30-
import useSettingsStore from 'stores/SettingsStore';
30+
import { uploadGraphRunLogs } from 'service/collection';
3131

3232
const StartNode = () => (
3333
<FlowNode title='Start' handleLeft={false} handleRight={true} handleRightData={{ type: 'source' }}></FlowNode>
@@ -88,7 +88,6 @@ const Flow = ({ tab, collectionId }) => {
8888
useCanvasStore(selector);
8989

9090
const setLogs = useTabStore((state) => state.updateFlowTestLogs);
91-
const logSyncConfig = useSettingsStore((state) => state.logSyncConfig);
9291

9392
const [reactFlowInstance, setReactFlowInstance] = useState(null);
9493

@@ -195,8 +194,10 @@ const Flow = ({ tab, collectionId }) => {
195194
return true;
196195
};
197196

198-
const onGraphComplete = (status, logs) => {
199-
setLogs(tab.id, logs);
197+
const onGraphComplete = async (status, logs) => {
198+
const response = await uploadGraphRunLogs(tab.name, logs);
199+
console.log(response);
200+
setLogs(tab.id, logs, response);
200201
if (status == 'Success') {
201202
toast.success(`FlowTest Run Success!`);
202203
} else if (status == 'Failed') {
@@ -275,10 +276,10 @@ const Flow = ({ tab, collectionId }) => {
275276
);
276277
const result = await g.run();
277278
logger.add(LogLevel.INFO, `Total time: ${Date.now() - startTime} ms`);
278-
onGraphComplete(result.status, logger.get());
279+
await onGraphComplete(result.status, logger.get());
279280
} catch (error) {
280281
logger.add(LogLevel.INFO, `Total time: ${Date.now() - startTime} ms`);
281-
onGraphComplete('Failed', logger.get());
282+
await onGraphComplete('Failed', logger.get());
282283
toast.error(`Internal error running graph`);
283284
runnableEdges(false);
284285
}

src/components/molecules/headers/TabPanelHeader.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import HorizontalDivider from 'components/atoms/common/HorizontalDivider';
1616
import { JsonView, allExpanded, collapseAllNested, darkStyles, defaultStyles } from 'react-json-view-lite';
1717
import 'react-json-view-lite/dist/index.css';
1818
import { LogLevel } from '../flow/graph/GraphLogger';
19+
import { ShieldCheckIcon, BarsArrowUpIcon, ExclamationTriangleIcon } from '@heroicons/react/24/outline';
1920

2021
const TabPanelHeader = () => {
2122
const focusTabId = useTabStore((state) => state.focusTabId);
@@ -111,6 +112,31 @@ const TabPanelHeader = () => {
111112
}
112113
};
113114

115+
// this gives forced reflow warning?
116+
const renderFlowScan = (flowScan) => {
117+
if (flowScan.upload === 'disabled') {
118+
return (
119+
<div className='flex flex-col items-start'>
120+
<Tippy content={flowScan.message} placement='top'>
121+
<BarsArrowUpIcon className='h-4 w-4' />
122+
{'Activate Flow Scan'}
123+
</Tippy>
124+
</div>
125+
);
126+
} else if (flowScan.upload === 'success') {
127+
<div className='flex flex-col items-start'>
128+
<ShieldCheckIcon className='h-4 w-4' />
129+
{flowScan.url}
130+
</div>;
131+
} else if (flowScan.upload === 'fail') {
132+
<div className='flex flex-col items-start'>
133+
<ExclamationTriangleIcon className='h-4 w-4' />
134+
{flowScan.message}
135+
{flowScan?.reason}
136+
</div>;
137+
}
138+
};
139+
114140
return (
115141
<>
116142
{focusTab ? (
@@ -134,7 +160,7 @@ const TabPanelHeader = () => {
134160
<div className='flex h-12 items-center justify-center'>
135161
<SaveFlowModal tab={focusTab} />
136162
</div>
137-
{focusTab.type === OBJ_TYPES.flowtest && focusTab.logs && focusTab.logs.length != 0 ? (
163+
{focusTab.type === OBJ_TYPES.flowtest && focusTab.run.logs && focusTab.run.logs.length != 0 ? (
138164
<div>
139165
<Button
140166
id='graph-logs-side-sheet'
@@ -178,7 +204,8 @@ const TabPanelHeader = () => {
178204
className='drawer-overlay'
179205
></label>
180206
<ul className='menu min-h-full bg-base-200 p-4 text-base-content'>
181-
{focusTab.logs.map((item, index) => (
207+
<li key='scan'>{renderFlowScan(focusTab.run.scan)}</li>
208+
{focusTab.run.logs.map((item, index) => (
182209
<li key={index}>{renderLog(item)}</li>
183210
))}
184211
</ul>

src/service/collection.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { useTabStore } from 'stores/TabStore';
88
import useCanvasStore from 'stores/CanvasStore';
99
import { initFlowData } from 'components/molecules/flow/utils';
1010
import { cloneDeep } from 'lodash';
11+
import useSettingsStore from 'stores/SettingsStore';
1112

1213
export const createCollection = (openAPISpecFilePath, collectionFolderPath) => {
1314
const { ipcRenderer } = window;
@@ -401,3 +402,23 @@ export const deleteFlowTest = (pathname, collectionId) => {
401402
return Promise.reject(new Error('Error deleting flowtest'));
402403
}
403404
};
405+
406+
export const uploadGraphRunLogs = async (name, logs) => {
407+
try {
408+
const { ipcRenderer } = window;
409+
const logSyncConfig = useSettingsStore.getState().logSyncConfig;
410+
if (logSyncConfig.enabled) {
411+
return await ipcRenderer.invoke('renderer:upload-logs', name, logSyncConfig, logs);
412+
} else {
413+
return {
414+
upload: 'disabled',
415+
message: 'Enable flow scans today to get more value out of your APIs',
416+
};
417+
}
418+
} catch (error) {
419+
return {
420+
upload: 'fail',
421+
message: 'Unable to upload flow scan',
422+
};
423+
}
424+
};

src/stores/TabStore.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const useTabStore = create((set, get) => ({
2727
name: flowtest.name,
2828
pathname: flowtest.pathname,
2929
flowData: flowtest.flowData,
30-
logs: [],
30+
run: {},
3131
};
3232

3333
set((state) => ({ tabs: [...state.tabs, newTab] }));
@@ -81,12 +81,15 @@ export const useTabStore = create((set, get) => ({
8181
}),
8282
);
8383
},
84-
updateFlowTestLogs: (tabId, logs) => {
84+
updateFlowTestLogs: (tabId, logs, flowScan) => {
8585
set(
8686
produce((state) => {
8787
const existingTab = state.tabs.find((t) => t.id === tabId);
8888
if (existingTab) {
89-
existingTab.logs = logs;
89+
existingTab.run = {
90+
scan: flowScan,
91+
logs,
92+
};
9093
}
9194
}),
9295
);

0 commit comments

Comments
 (0)