Skip to content

Commit

Permalink
Fixed lint errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
manas-qm committed Jul 22, 2024
1 parent 305a330 commit 72806cf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
38 changes: 25 additions & 13 deletions frontend/src/modules/Data/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,35 @@ export const JSONEditor = ({ title, jsonDataProp, height }: { title: string; jso

try {
// Convert search term to JSONPath query
let jsonPathQuery = term.replace("#", "$").replace(/\*/g, "*").replace(/\//g, ".");
const jsonPathQuery = term.replace("#", "$").replace(/\*/g, "*").replace(/\//g, ".");

// Perform the JSONPath query
const result = jp.nodes(data, jsonPathQuery);

// Reconstruct the filtered data structure
return result.reduce((acc: any, { path, value }: { path: jp.PathComponent[]; value: any }) => {
let current = acc;
for (let i = 1; i < path.length - 1; i++) {
const key = path[i] as string;
if (!current[key]) current[key] = {};
current = current[key];
}
const lastKey = path[path.length - 1] as string;
current[lastKey] = value;
return acc;
}, {});
return result.reduce(
(
acc: Record<string, unknown>,
{
path,
value,
}: {
path: jp.PathComponent[];
value: unknown;
}
) => {
let current = acc;
for (let i = 1; i < path.length - 1; i++) {
const key = path[i] as string;
if (!current[key]) current[key] = {};
current = current[key] as Record<string, unknown>;
}
const lastKey = path[path.length - 1] as string;
current[lastKey] = value;
return acc;
},
{}
);
} catch (error) {
console.error("Invalid JSONPath query:", error);
return data;
Expand Down Expand Up @@ -166,7 +178,7 @@ export const JSONEditor = ({ title, jsonDataProp, height }: { title: string; jso
<InputField value={searchTerm} title={"Search"} onChange={(_e, event) => handleSearch(event.target.value, event)}></InputField>
<JsonViewer
rootName={false}
onSelect={(path, _a) => handleOnSelect(path)}
onSelect={(path) => handleOnSelect(path)}
theme={"dark"}
value={jsonData}
valueTypes={[imageDataType]}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { NodeElement, NodeMap } from "./NodeElement";
// eslint-disable-next-line css-modules/no-unused-class
import styles from "../../NodesPage.module.scss";

interface INodeListProps {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/modules/Nodes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import { NodesContextProvider, useNodesContext } from "./context/NodesContext";
// eslint-disable-next-line css-modules/no-unused-class
import styles from "../Nodes/NodesPage.module.scss";
import { NodeElementList } from "./components/NodeElement/NodeElementList";
import PageName from "../../DEPRECATED_components/common/Page/PageName";
Expand Down

0 comments on commit 72806cf

Please sign in to comment.