diff --git a/src/qqq/components/scripts/ScriptEditor.tsx b/src/qqq/components/scripts/ScriptEditor.tsx index ae25b4b..9ee7ca1 100644 --- a/src/qqq/components/scripts/ScriptEditor.tsx +++ b/src/qqq/components/scripts/ScriptEditor.tsx @@ -101,6 +101,26 @@ function buildInitialFileContentsMap(scriptRevisionRecord: QRecord, scriptTypeFi return (rs); } +function buildFileTypeMap(scriptTypeFileSchemaList: QRecord[]): { [name: string]: string } +{ + const rs: {[name: string]: string} = {}; + + if(!scriptTypeFileSchemaList) + { + console.log("Missing scriptTypeFileSchemaList"); + } + else + { + for (let i = 0; i < scriptTypeFileSchemaList.length; i++) + { + let name = scriptTypeFileSchemaList[i].values.get("name"); + rs[name] = scriptTypeFileSchemaList[i].values.get("fileType"); + } + } + + return (rs); +} + function ScriptEditor({title, scriptId, scriptRevisionRecord, closeCallback, tableName, fieldName, recordId, scriptTypeRecord, scriptTypeFileSchemaList}: ScriptEditorProps): JSX.Element { const [closing, setClosing] = useState(false); @@ -114,6 +134,8 @@ function ScriptEditor({title, scriptId, scriptRevisionRecord, closeCallback, tab const [availableFileNames, setAvailableFileNames] = useState(fileNamesFromSchema); const [openEditorFileNames, setOpenEditorFileNames] = useState([fileNamesFromSchema[0]]) const [fileContents, setFileContents] = useState(buildInitialFileContentsMap(scriptRevisionRecord, scriptTypeFileSchemaList)) + const [fileTypes, setFileTypes] = useState(buildFileTypeMap(scriptTypeFileSchemaList)) + console.log(`file types: ${JSON.stringify(fileTypes)}`); const [commitMessage, setCommitMessage] = useState("") const [openTool, setOpenTool] = useState(null); @@ -459,7 +481,7 @@ function ScriptEditor({title, scriptId, scriptRevisionRecord, closeCallback, tab + (async () => { - testInputValues[field.name] = field.defaultValue ?? ""; - }); + ///////////////////////////////////////////////////////////////////// + // call backend to load details about how to test this script type // + ///////////////////////////////////////////////////////////////////// + const formData = new FormData(); + formData.append("scriptTypeId", scriptType.values.get("id")); + const processResult = await qController.processRun("loadScriptTestDetails", formData, null, true); + + if (processResult instanceof QJobError) + { + const jobError = processResult as QJobError + setTestException(jobError.userFacingError ?? jobError.error) + return; + } + + const jobComplete = processResult as QJobComplete + + const testInputFields = [] as QFieldMetaData[]; + for(let i = 0; i + { + testInputValues[field.name] = field.defaultValue ?? ""; + }); + })(); } const buildFullExceptionMessage = (exception: any): string => @@ -91,9 +130,9 @@ function ScriptTestForm({scriptId, scriptDefinition, tableName, fieldName, recor const testScript = () => { const inputValues = new Map(); - if (scriptDefinition.testInputFields) + if (testInputFields) { - scriptDefinition.testInputFields.forEach((field: QFieldMetaData) => + testInputFields.forEach((field: QFieldMetaData) => { inputValues.set(field.name, testInputValues[field.name]); }); @@ -108,6 +147,7 @@ function ScriptTestForm({scriptId, scriptDefinition, tableName, fieldName, recor try { let output; + /* if(tableName && recordId && fieldName) { ///////////////////////////////////////////////////////////////// @@ -115,15 +155,21 @@ function ScriptTestForm({scriptId, scriptDefinition, tableName, fieldName, recor ///////////////////////////////////////////////////////////////// inputValues.set("apiName", apiName); inputValues.set("apiVersion", apiVersion); - output = await qController.testScript(tableName, recordId, fieldName, code, inputValues); + output = await qController.testScript(tableName, recordId, fieldName, "todo!", inputValues); } else + */ { const formData = new FormData(); formData.append("scriptId", scriptId); formData.append("apiName", apiName); formData.append("apiVersion", apiVersion); - formData.append("code", code); + + formData.append("fileNames", Object.keys(fileContents).join(",")) + for (let fileName in fileContents) + { + formData.append("fileContents:" + fileName, fileContents[fileName]); + } for(let fieldName of inputValues.keys()) { @@ -195,7 +241,7 @@ function ScriptTestForm({scriptId, scriptDefinition, tableName, fieldName, recor Test Input { - scriptDefinition.testInputFields && testInputValues && scriptDefinition.testInputFields.map((field: QFieldMetaData) => + testInputFields && testInputValues && testInputFields.map((field: QFieldMetaData) => { return ( } { - scriptDefinition.testOutputFields && scriptDefinition.testOutputFields.map((f: any) => + testOutputFields && testOutputFields.map((f: any) => { const field = new QFieldMetaData(f); return ( - + {field.label}: - {ValueUtils.getValueForDisplay(field, testOutputValues[field.name], testOutputValues[field.name], "view")} + { + testOutputValues.values ? + ValueUtils.getValueForDisplay(field, testOutputValues.values[field.name], testOutputValues.displayValues[field.name], "view") : + ValueUtils.getValueForDisplay(field, testOutputValues[field.name], testOutputValues[field.name], "view") + } ); diff --git a/src/qqq/components/widgets/misc/ScriptViewer.tsx b/src/qqq/components/widgets/misc/ScriptViewer.tsx index 4040099..3dbd4f2 100644 --- a/src/qqq/components/widgets/misc/ScriptViewer.tsx +++ b/src/qqq/components/widgets/misc/ScriptViewer.tsx @@ -63,6 +63,7 @@ import ValueUtils from "qqq/utils/qqq/ValueUtils"; import "ace-builds/src-noconflict/mode-java"; import "ace-builds/src-noconflict/mode-javascript"; +import "ace-builds/src-noconflict/mode-velocity"; import "ace-builds/src-noconflict/mode-json"; import "ace-builds/src-noconflict/theme-github"; import "ace-builds/src-noconflict/ext-language_tools"; @@ -260,6 +261,20 @@ export default function ScriptViewer({scriptId, associatedScriptTableName, assoc return (getSelectedVersionCode()[selectedFileName] ?? ""); } + const getSelectedFileType = (): string => + { + for (let i = 0; i < scriptTypeFileSchemaList.length; i++) + { + let name = scriptTypeFileSchemaList[i].values.get("name"); + if(name == selectedFileName) + { + return (scriptTypeFileSchemaList[i].values.get("fileType")); + } + } + + return ("javascript"); // have some default... + } + const getSelectedVersionCode = (): {[name: string]: string} => { let rs: {[name: string]: string} = {} @@ -476,7 +491,7 @@ export default function ScriptViewer({scriptId, associatedScriptTableName, assoc }