diff --git a/src/components/Modals/JsonSchemaModal.js b/src/components/Modals/JsonSchemaModal.js
new file mode 100644
index 0000000..f6d4017
--- /dev/null
+++ b/src/components/Modals/JsonSchemaModal.js
@@ -0,0 +1,42 @@
+import React from 'react';
+
+const JsonSchemaModal = ({ isActive, onClose, schema }) => {
+ const handleCopy = () => {
+ navigator.clipboard.writeText(JSON.stringify(schema, null, 2));
+ };
+
+ return (
+
+
+
+
+
+
+
+
+ );
+};
+
+export default JsonSchemaModal;
\ No newline at end of file
diff --git a/src/components/Navigations/SideTabs/TemplateTab.js b/src/components/Navigations/SideTabs/TemplateTab.js
index 7313505..d366d37 100644
--- a/src/components/Navigations/SideTabs/TemplateTab.js
+++ b/src/components/Navigations/SideTabs/TemplateTab.js
@@ -2,10 +2,12 @@ import React, { useState } from "react";
import { useMarkdownTemplates } from "../../../utils/queries/markdown-template-queries";
import PermissionGuard from "../../PermissionGuard";
import { useNavigate } from "react-router-dom";
+import JsonSchemaModal from "../../Modals/JsonSchemaModal";
const TemplateTab = () => {
const { data: templates, isLoading, error } = useMarkdownTemplates();
const [keyword, setKeyword] = useState("");
+ const [selectedSchema, setSelectedSchema] = useState(null);
const navigate = useNavigate();
const filteredTemplates = templates?.filter(template =>
@@ -16,6 +18,99 @@ const TemplateTab = () => {
navigate(`/template/edit/${templateId}`);
};
+ const generateJsonSchema = (template) => {
+ const schema = {
+ type: "object",
+ properties: {},
+ $defs: {}
+ };
+
+ const generateTypeSchema = (param, defName) => {
+ switch (param.type.base_type) {
+ case "string":
+ return {
+ type: "string"
+ };
+ case "markdown":
+ return {
+ type: "string",
+ description: "Markdown content"
+ };
+ case "enum":
+ return {
+ type: "string",
+ enum: param.type.definition.enums
+ };
+ case "list":
+ if (param.type.extend_type.base_type === "string") {
+ return {
+ type: "array",
+ items: {
+ type: "string"
+ }
+ };
+ } else if (param.type.extend_type.base_type === "list" ||
+ param.type.extend_type.base_type === "template") {
+ const itemsDefName = `${defName}_items`;
+ schema.$defs[itemsDefName] = generateTypeSchema(
+ { type: param.type.extend_type },
+ itemsDefName
+ );
+ return {
+ type: "array",
+ items: {
+ $ref: `#/$defs/${itemsDefName}`
+ }
+ };
+ } else {
+ return {
+ type: "array",
+ items: generateTypeSchema(
+ { type: param.type.extend_type },
+ `${defName}_items`
+ )
+ };
+ }
+ case "template":
+ const nestedTemplate = templates.find(t => t.id === param.type.definition.template.id);
+ if (nestedTemplate) {
+ const nestedSchema = {
+ type: "object",
+ properties: {}
+ };
+ nestedTemplate.parameters.forEach(nestedParam => {
+ nestedSchema.properties[nestedParam.name] = generateTypeSchema(
+ nestedParam,
+ `${defName}_${nestedParam.name}`
+ );
+ });
+ return nestedSchema;
+ } else {
+ return {
+ type: "object",
+ properties: {}
+ };
+ }
+ default:
+ return {
+ type: "object",
+ properties: {}
+ };
+ }
+ };
+
+ template.parameters.forEach(param => {
+ const defName = `param_${param.name}`;
+ schema.properties[param.name] = generateTypeSchema(param, defName);
+ });
+
+ if (Object.keys(schema.$defs).length === 0) {
+ delete schema.$defs;
+ }
+
+ return schema;
+ };
+
if (isLoading) return Loading...
;
if (error) return Error loading templates
;
@@ -38,23 +133,40 @@ const TemplateTab = () => {
Create New Template
-
- {!filteredTemplates || filteredTemplates.length === 0 ? (
- No templates found
- ) : (
-
- {filteredTemplates.map(template => (
-
- ))}
-
- )}
+
+ {filteredTemplates?.map((template) => (
+ -
+
+
{template.title}
+
+
+
+
+
+
+ ))}
+
+ setSelectedSchema(null)}
+ schema={selectedSchema}
+ />
);
};