🐛 fix(ApiModal/index.tsx): fix linting issues and improve code readability
✨ feat(ApiModal/index.tsx): add support for displaying tweaks code in a separate tab if there are any tweaks present
This commit is contained in:
parent
c954f8d338
commit
7c777bf692
2 changed files with 57 additions and 61 deletions
3
src/frontend/package-lock.json
generated
3
src/frontend/package-lock.json
generated
|
|
@ -3563,7 +3563,7 @@
|
||||||
"version": "16.18.12",
|
"version": "16.18.12",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.12.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.12.tgz",
|
||||||
"integrity": "sha512-vzLe5NaNMjIE3mcddFVGlAXN1LEWueUsMsOJWaT6wWMJGyljHAWHznqfnKUQWGzu7TLPrGvWdNAsvQYW+C0xtw==",
|
"integrity": "sha512-vzLe5NaNMjIE3mcddFVGlAXN1LEWueUsMsOJWaT6wWMJGyljHAWHznqfnKUQWGzu7TLPrGvWdNAsvQYW+C0xtw==",
|
||||||
"dev": true
|
"devOptional": true
|
||||||
},
|
},
|
||||||
"node_modules/@types/parse-json": {
|
"node_modules/@types/parse-json": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
|
|
@ -5633,7 +5633,6 @@
|
||||||
"version": "2.3.2",
|
"version": "2.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||||
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||||
"dev": true,
|
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"os": [
|
"os": [
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,55 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
|
||||||
}, 2000);
|
}, 2000);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const pythonApiCode = getPythonApiCode(flow, tweak.current);
|
||||||
|
const curl_code = getCurlCode(flow, tweak.current);
|
||||||
|
const pythonCode = getPythonCode(flow, tweak.current);
|
||||||
|
const tweaksCode = buildTweaks(flow);
|
||||||
|
const tabs = [
|
||||||
|
{
|
||||||
|
name: "cURL",
|
||||||
|
mode: "bash",
|
||||||
|
image: "https://curl.se/logo/curl-symbol-transparent.png",
|
||||||
|
code: curl_code,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Python API",
|
||||||
|
mode: "python",
|
||||||
|
image:
|
||||||
|
"https://images.squarespace-cdn.com/content/v1/5df3d8c5d2be5962e4f87890/1628015119369-OY4TV3XJJ53ECO0W2OLQ/Python+API+Training+Logo.png?format=1000w",
|
||||||
|
code: pythonApiCode,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Python Code",
|
||||||
|
mode: "python",
|
||||||
|
image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png",
|
||||||
|
code: pythonCode,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (closeEdit !== "") {
|
||||||
|
setActiveTab("3");
|
||||||
|
tweak.current = getTweak;
|
||||||
|
openAccordions();
|
||||||
|
} else {
|
||||||
|
startTweaks();
|
||||||
|
}
|
||||||
|
}, [closeEdit]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
filterNodes();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
if (Object.keys(tweaksCode).length > 0) {
|
||||||
|
tabs.push({
|
||||||
|
name: "Tweaks",
|
||||||
|
mode: "python",
|
||||||
|
image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png",
|
||||||
|
code: pythonCode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function setModalOpen(x: boolean) {
|
function setModalOpen(x: boolean) {
|
||||||
setOpen(x);
|
setOpen(x);
|
||||||
if (x === false) {
|
if (x === false) {
|
||||||
|
|
@ -84,26 +133,6 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (closeEdit !== "") {
|
|
||||||
setActiveTab("3");
|
|
||||||
tweak.current = getTweak;
|
|
||||||
openAccordions();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
startTweaks();
|
|
||||||
}
|
|
||||||
}, [closeEdit]);
|
|
||||||
|
|
||||||
const pythonApiCode = getPythonApiCode(flow, tweak.current);
|
|
||||||
const curl_code = getCurlCode(flow, tweak.current);
|
|
||||||
const pythonCode = getPythonCode(flow, tweak.current);
|
|
||||||
const tweaksCode = buildTweaks(flow);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
filterNodes();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
function startTweaks() {
|
function startTweaks() {
|
||||||
tweak.current.push(buildTweaks(flow));
|
tweak.current.push(buildTweaks(flow));
|
||||||
}
|
}
|
||||||
|
|
@ -135,37 +164,6 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const tabs = [
|
|
||||||
{
|
|
||||||
name: "cURL",
|
|
||||||
mode: "bash",
|
|
||||||
image: "https://curl.se/logo/curl-symbol-transparent.png",
|
|
||||||
code: curl_code,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Python API",
|
|
||||||
mode: "python",
|
|
||||||
image:
|
|
||||||
"https://images.squarespace-cdn.com/content/v1/5df3d8c5d2be5962e4f87890/1628015119369-OY4TV3XJJ53ECO0W2OLQ/Python+API+Training+Logo.png?format=1000w",
|
|
||||||
code: pythonApiCode,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Python Code",
|
|
||||||
mode: "python",
|
|
||||||
image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png",
|
|
||||||
code: pythonCode,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
if (Object.keys(tweaksCode).length > 0) {
|
|
||||||
tabs.push({
|
|
||||||
name: "Tweaks",
|
|
||||||
mode: "python",
|
|
||||||
image: "https://cdn-icons-png.flaticon.com/512/5968/5968350.png",
|
|
||||||
code: pythonCode,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function buildTweakObject(tw, changes, template) {
|
function buildTweakObject(tw, changes, template) {
|
||||||
if (template.type === "float") {
|
if (template.type === "float") {
|
||||||
changes = parseFloat(changes);
|
changes = parseFloat(changes);
|
||||||
|
|
@ -201,7 +199,6 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
tweak.current.push(newTweak);
|
tweak.current.push(newTweak);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const pythonApiCode = getPythonApiCode(flow, tweak.current);
|
const pythonApiCode = getPythonApiCode(flow, tweak.current);
|
||||||
|
|
@ -229,7 +226,7 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
|
||||||
|
|
||||||
if (getTweak.length > 0) {
|
if (getTweak.length > 0) {
|
||||||
for (const obj of getTweak) {
|
for (const obj of getTweak) {
|
||||||
Object.keys(obj).forEach(key =>{
|
Object.keys(obj).forEach((key) => {
|
||||||
const value = obj[key];
|
const value = obj[key];
|
||||||
if (key == node["id"]) {
|
if (key == node["id"]) {
|
||||||
Object.keys(value).forEach((key) => {
|
Object.keys(value).forEach((key) => {
|
||||||
|
|
@ -238,7 +235,7 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return value ?? "";
|
return value ?? "";
|
||||||
|
|
@ -251,7 +248,7 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
|
||||||
tweak.current.forEach((el) => {
|
tweak.current.forEach((el) => {
|
||||||
Object.keys(el).forEach((key) => {
|
Object.keys(el).forEach((key) => {
|
||||||
if (Object.keys(el[key]).length > 0) {
|
if (Object.keys(el[key]).length > 0) {
|
||||||
accordionsToOpen.push(key)
|
accordionsToOpen.push(key);
|
||||||
setOpenAccordion(accordionsToOpen);
|
setOpenAccordion(accordionsToOpen);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -279,7 +276,7 @@ export default function ApiModal({ flow }: { flow: FlowType }) {
|
||||||
onValueChange={(value) => {
|
onValueChange={(value) => {
|
||||||
setActiveTab(value);
|
setActiveTab(value);
|
||||||
if (value === "3") {
|
if (value === "3") {
|
||||||
openAccordions()
|
openAccordions();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue