Skip to content

Commit

Permalink
feat: line wrap for json editor and handle null
Browse files Browse the repository at this point in the history
  • Loading branch information
invm authored and Michael Ionov committed Oct 1, 2023
1 parent 800ea01 commit e3885f7
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createEffect, createSignal } from "solid-js";
import { TabulatorFull as Tabulator } from "tabulator-tables";
import { dracula } from "@uiw/codemirror-theme-dracula";
import { search } from "@codemirror/search";
import { basicSetup } from "codemirror";
import { basicSetup, EditorView } from "codemirror";
import { json } from "@codemirror/lang-json";
import {
createCodeMirror,
Expand All @@ -14,7 +14,7 @@ const parseObjRecursive = (obj: any): Record<string, any> => {
if (typeof obj === "object") {
if (Array.isArray(obj)) {
return obj.map(parseObjRecursive);
} else {
} else if (obj !== null) {
return Object.fromEntries(
Object.entries(obj).map(([k, v]) => [k, parseObjRecursive(v)])
);
Expand All @@ -39,6 +39,9 @@ export const ResultsTable = (props: { rows: Row[] }) => {
createExtension(basicSetup);
createExtension(json);

const lineWrapping = EditorView.lineWrapping;
createExtension(lineWrapping);

createEffect(() => {
let columns: { title: string; field: string; resizeable: boolean }[] = [];
if (props.rows.length) {
Expand Down Expand Up @@ -70,6 +73,7 @@ export const ResultsTable = (props: { rows: Row[] }) => {
label: "Show row in JSON",
action: function(_e, row) {
// @ts-ignore
console.log(row._row.data)
const data = parseObjRecursive(row._row.data);
setCode(JSON.stringify(data, null, 4));
// @ts-ignore
Expand Down

0 comments on commit e3885f7

Please sign in to comment.