Skip to content

Commit

Permalink
changed behaviout to ignore empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
molotgor committed Apr 16, 2024
1 parent c08853a commit a2d489e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/components/JSONViewer/FileChoosing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const FileChoosing = ({
const lines = result.split('\n');
const data: TreeNode[][] = [];
for (let i = 0; i < lines.length; i++) {
data.push(parseText(lines[i]));
if (lines[i] !== '') data.push(parseText(lines[i]));
}
fileData.push(...data.reduce((res, current) => res.concat(current), []));
}
Expand Down
38 changes: 25 additions & 13 deletions src/components/JSONViewer/NotebookParamsCell.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react';
import { observer } from 'mobx-react-lite';
import { nanoid } from 'nanoid';
import { NotebookParameter, NotebookParameters, TreeNode } from '../../models/JSONSchema';
import api from '../../api';
import '../../styles/jupyter.scss';
Expand Down Expand Up @@ -39,20 +40,29 @@ const NotebookParamsCell = ({ notebook }: { notebook: string }) => {
const getResults = async (path: string) => {
const { result } = await api.jsonViewer.getResults(path);
if (result.includes('{')) {
const nodeName = `Result of ${notebook}'s run`;
const fileData: TreeNode[] = [];
const node: TreeNode = {
id: nanoid(),
key: `Result of ${notebook}'s run`,
failed: false,
viewInstruction: '',
simpleFields: [{ key: 'filepath', value: path }],
complexFields: [],
};
try {
fileData.push(...parseText(result, nodeName));
node.complexFields.push(...parseText(result));
} catch {
const lines = result.split('\n');
const data: TreeNode[][] = [];
for (let i = 0; i < lines.length; i++) {
data.push(parseText(lines[i]));
if (lines[i] !== '') {
node.complexFields.push(...parseText(lines[i], String(i)));
}
}
fileData.push(...data.reduce((res, current) => res.concat(current), []));
}
JSONViewerStore.addNodes(fileData);
JSONViewerStore.selectTreeNode(fileData[0]);
node.failed = node.complexFields.some(v => v.failed);
if (node.complexFields.length > 0) {
JSONViewerStore.addNodes([node]);
JSONViewerStore.selectTreeNode(node);
}
setParamsValue({});
setIsRunLoading(false);
setIsExpanded(false);
Expand Down Expand Up @@ -117,11 +127,13 @@ const NotebookParamsCell = ({ notebook }: { notebook: string }) => {
<div className='notebookCell-body-table'>
<table>
<thead>
<tr style={{ textAlign: 'left' }}>
<th>Name</th>
<th>Type</th>
<th>Value</th>
</tr>
{parameters.length > 0 && (
<tr style={{ textAlign: 'left' }}>
<th>Name</th>
<th>Type</th>
<th>Value</th>
</tr>
)}
</thead>
<tbody>
{parameters.map(parameter => (
Expand Down
2 changes: 1 addition & 1 deletion src/components/workspace/JSONViewerWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const JSONViewerWorkspace = () => {
const lines = text.split('\n');
const data: TreeNode[] = [];
for (let i = 0; i < lines.length; i++) {
data.push(...parseText(lines[i]));
if (lines[i] !== '') data.push(...parseText(lines[i]));
}
return data;
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/JSONViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export const convertJSONtoNode = (obj: object, key = ''): TreeNode => {
export const parseText = (text: string, name = ''): TreeNode[] => {
const js = JSON.parse(text);
const node = convertJSONtoNode(js);
if (node.simpleFields.length > 1) {
if (node.simpleFields.length > 0) {
return [
{
...node,
Expand Down
2 changes: 1 addition & 1 deletion src/models/JSONSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface SimpleField {
export interface TreeNode {
id: string;
key: string;
failed?: boolean;
failed: boolean;
viewInstruction: string;
complexFields: TreeNode[];
simpleFields: SimpleField[];
Expand Down

0 comments on commit a2d489e

Please sign in to comment.