Skip to content

Commit

Permalink
put forms debugger to extra component
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Tilsch committed Oct 27, 2023
1 parent d6f8961 commit 031fdeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 46 deletions.
6 changes: 5 additions & 1 deletion apps/exhibition-live/components/form/FormDebuggingTools.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { JsonView } from "react-json-view-lite";
import { Divider, Grid, Typography } from "@mui/material";
import React from "react";
import { useSettings } from "../state/useLocalSettings";

type FormDebuggingToolsProps = {
jsonData?: Record<string, any>;
};
const FormDebuggingTools = ({ jsonData }: FormDebuggingToolsProps) => {
export const FormDebuggingTools = ({ jsonData }: FormDebuggingToolsProps) => {
const { features } = useSettings();
if (!features?.enableDebug) return null;

return (
<Grid container direction={"column"} spacing={2}>
{Object.entries(jsonData).map(([key, value]) => {
Expand Down
53 changes: 8 additions & 45 deletions apps/exhibition-live/components/form/SemanticJsonForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import {
useSPARQL_CRUD,
} from "../state/useSPARQL_CRUD";
import SimilarityFinder from "./SimilarityFinder";
import { FormDebuggingTools } from "./FormDebuggingTools";

export type CRUDOpsType = {
load: () => Promise<void>;
Expand Down Expand Up @@ -329,38 +330,6 @@ const SemanticJsonForm: FunctionComponent<SemanticJsonFormsProps> = ({
toolbarRef.current,
)}
</Hidden>
{features?.enableDebug && (
<>
<Switch
checked={jsonViewerEnabled}
onChange={(e) => setJsonViewerEnabled(Boolean(e.target.checked))}
title={"debug"}
/>
{jsonViewerEnabled && (
<Switch
checked={isUpdate}
onChange={(e) => setIsUpdate(Boolean(e.target.checked))}
title={"upsert"}
/>
)}
</>
)}
{hideToolbar && features?.enableDebug && (
<>
<Switch
checked={jsonViewerEnabled}
onChange={(e) => setJsonViewerEnabled(Boolean(e.target.checked))}
title={"debug"}
/>
{jsonViewerEnabled && (
<Switch
checked={isUpdate}
onChange={(e) => setIsUpdate(Boolean(e.target.checked))}
title={"upsert"}
/>
)}
</>
)}
<Grid
container
spacing={2}
Expand All @@ -386,19 +355,13 @@ const SemanticJsonForm: FunctionComponent<SemanticJsonFormsProps> = ({
/>
</CardContent>
</Card>
{jsonViewerEnabled &&
[data, jsonldData, formData].map((data_, idx) => (
<Card key={idx}>
<CardContent>
{entityIRI}
<JsonView
data={data_}
shouldInitiallyExpand={(lvl) => lvl < 5}
/>
<Divider />
</CardContent>
</Card>
))}
<FormDebuggingTools
jsonData={{
rawData: data,
jsonldData: jsonldData,
formData: formData,
}}
/>
</Grid>
{!hideSimilarityFinder && (
<>
Expand Down

0 comments on commit 031fdeb

Please sign in to comment.