From b2471643364ca37ad35ecb54e24cfc4e33cc84b7 Mon Sep 17 00:00:00 2001 From: "Robert So (robester0403)" <85914248+robester0403@users.noreply.github.com> Date: Thu, 4 Apr 2024 10:30:02 -0400 Subject: [PATCH 1/7] PLAT-14359 Added set command to modules --- index.js | 27 ++++++++++++++++++++++++++ scripts/setModuleDetails.js | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 scripts/setModuleDetails.js diff --git a/index.js b/index.js index 7eed525..ca0c1ed 100755 --- a/index.js +++ b/index.js @@ -45,6 +45,7 @@ import { HAS_ASKED_OPT_IN_NAME } from "./scripts/analytics/config.js"; import { EVENT } from "./scripts/analytics/constants.js"; import { askOptIn } from "./scripts/analytics/scripts.js"; import { sentryMonitoring } from "./scripts/utils/sentry.js"; +import { setModuleDetails } from "./scripts/setModuleDetails.js"; const pkg = JSON.parse( fs.readFileSync(new URL("package.json", import.meta.url), "utf8") @@ -308,6 +309,7 @@ demo`; let id; const action = args._[1]; + let extraArgs; if (!action.length) { // TODO - Print help? @@ -338,6 +340,31 @@ demo`; await modulesGet(id); break; + case "set": + id = args._[2]; + extraArgs = args._[3]; + + if (!id) { + return invalid( + "Please provide the id of the module to change info for, i.e. modules archive <123>" + ); + } + + if (!extraArgs) { + return invalid( + "Please provide the details to change for the module, available options --name, --description, --acceptance-criteria, & --search-description" + ); + } + + await setModuleDetails(id, { + name: args["--name"], + description: args["--description"], + acceptanceCriteria: args["--acceptance-criteria"], + searchDescription: args["--search-description"] + }); + + break; + case "archive": id = args._[2]; if (!id) { diff --git a/scripts/setModuleDetails.js b/scripts/setModuleDetails.js new file mode 100644 index 0000000..42fd39c --- /dev/null +++ b/scripts/setModuleDetails.js @@ -0,0 +1,38 @@ +import ora from "ora"; +import { invalid, valid } from "../utils.js"; +import { apiClient } from "./utils/apiClient.js"; + +export const setModuleDetails = async ( + id, + { name, description, searchDescription, acceptanceCriteria } +) => { + const patchBody = {}; + + if (name) { + patchBody.title = name; + } + if (description) { + patchBody.description = description; + } + if (searchDescription) { + patchBody.search_description = searchDescription; + } + if (acceptanceCriteria) { + patchBody.acceptance_criteria = acceptanceCriteria; + } + const patchSpinner = ora( + "Updating module details." + ).start(); + + const patchResponse = await apiClient.patch({ + path: `/v1/catalog/module/${id}`, + body: patchBody + }); + + if (patchResponse.ok) { + valid(`Module details updated for ${id}.`); + } else { + invalid(`Unable to update module details for ${id}.`); + } + patchSpinner.stop(); +}; From e23cc0fcae1fa0f913638239917bd24440e53746 Mon Sep 17 00:00:00 2001 From: "Robert So (robester0403)" <85914248+robester0403@users.noreply.github.com> Date: Thu, 4 Apr 2024 12:32:25 -0400 Subject: [PATCH 2/7] PLAT-14359 Added messages, args and fixed spinner behavior --- index.js | 26 ++++++++++++++++++-------- scripts/setModuleDetails.js | 27 ++++++++++++++++----------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index ca0c1ed..d36a02d 100755 --- a/index.js +++ b/index.js @@ -304,7 +304,11 @@ demo`; "--visibility": String, "--status": String, "--page": String, - "--unarchive": Boolean + "--unarchive": Boolean, + "--name": String, + "--description": String, + "--acceptance-criteria": String, + "--search-description": String }); let id; @@ -346,7 +350,7 @@ demo`; if (!id) { return invalid( - "Please provide the id of the module to change info for, i.e. modules archive <123>" + "Please provide the id of the module to change info for, i.e. modules set <123>" ); } @@ -356,12 +360,12 @@ demo`; ); } - await setModuleDetails(id, { - name: args["--name"], - description: args["--description"], - acceptanceCriteria: args["--acceptance-criteria"], - searchDescription: args["--search-description"] - }); + await setModuleDetails(id, + args["--name"], + args["--description"], + args["--acceptance-criteria"], + args["--search-description"] + ); break; @@ -474,6 +478,12 @@ Install one or modules to your demo app: Remove one or modules from your demo app: cb remove +Get information about a module by id: + cb modules get + +Set information about a module by id such as name, description, acceptance criteria, and search description: + cb modules set --name --description --acceptance-criteria --search-description + Install modules from other directory: cb add --source ../other-repository diff --git a/scripts/setModuleDetails.js b/scripts/setModuleDetails.js index 42fd39c..d6d9181 100644 --- a/scripts/setModuleDetails.js +++ b/scripts/setModuleDetails.js @@ -3,8 +3,7 @@ import { invalid, valid } from "../utils.js"; import { apiClient } from "./utils/apiClient.js"; export const setModuleDetails = async ( - id, - { name, description, searchDescription, acceptanceCriteria } + id, name, description, searchDescription, acceptanceCriteria ) => { const patchBody = {}; @@ -20,19 +19,25 @@ export const setModuleDetails = async ( if (acceptanceCriteria) { patchBody.acceptance_criteria = acceptanceCriteria; } + const patchSpinner = ora( "Updating module details." ).start(); - const patchResponse = await apiClient.patch({ - path: `/v1/catalog/module/${id}`, - body: patchBody - }); + try { + const patchResponse = await apiClient.patch({ + path: `/v1/catalog/module/${id}`, + body: patchBody + }); - if (patchResponse.ok) { - valid(`Module details updated for ${id}.`); - } else { - invalid(`Unable to update module details for ${id}.`); + if (patchResponse.ok) { + patchSpinner.stop(); + valid(`Module details updated for ${id}.`); + } else { + patchSpinner.stop(); + invalid(`Unable to update module details for ${id}. Please try again.`); + } + } catch (error) { + invalid(`An error occurred: ${error.message}. Please try again.`); } - patchSpinner.stop(); }; From cdaf7bc56fb6adddd4a683894d12fffc6cb90b9a Mon Sep 17 00:00:00 2001 From: "Robert So (robester0403)" <85914248+robester0403@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:00:11 -0400 Subject: [PATCH 3/7] PLAT_14359 removed invalid check and added descriptions and warnings to the help and set commands --- index.js | 14 +++++--------- scripts/setModuleDetails.js | 4 +++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index d36a02d..86eb6cf 100755 --- a/index.js +++ b/index.js @@ -313,7 +313,6 @@ demo`; let id; const action = args._[1]; - let extraArgs; if (!action.length) { // TODO - Print help? @@ -346,7 +345,6 @@ demo`; case "set": id = args._[2]; - extraArgs = args._[3]; if (!id) { return invalid( @@ -354,12 +352,6 @@ demo`; ); } - if (!extraArgs) { - return invalid( - "Please provide the details to change for the module, available options --name, --description, --acceptance-criteria, & --search-description" - ); - } - await setModuleDetails(id, args["--name"], args["--description"], @@ -440,6 +432,9 @@ Commands available: demo Generate a local React Native and Django demo app add Install a module in the demo app remove Remove a module from the demo app + get Get information about a module by id + set Set information about a module by id such as name, description, acceptance criteria, and search description. The new values must be wrapped in quotes "". + create Create a new module of a given type create Create a new module of a given type commit Update an existing module from the demo source code init Initialize a blank modules repository @@ -482,7 +477,8 @@ Get information about a module by id: cb modules get Set information about a module by id such as name, description, acceptance criteria, and search description: - cb modules set --name --description --acceptance-criteria --search-description + cb modules set --name "" --description "" --acceptance-criteria "" --search-description "" + The new values must be wrapped in quotes "". Install modules from other directory: cb add --source ../other-repository diff --git a/scripts/setModuleDetails.js b/scripts/setModuleDetails.js index d6d9181..48815c1 100644 --- a/scripts/setModuleDetails.js +++ b/scripts/setModuleDetails.js @@ -1,5 +1,5 @@ import ora from "ora"; -import { invalid, valid } from "../utils.js"; +import { invalid, section, valid } from "../utils.js"; import { apiClient } from "./utils/apiClient.js"; export const setModuleDetails = async ( @@ -7,6 +7,8 @@ export const setModuleDetails = async ( ) => { const patchBody = {}; + section("To ensure the entire string is saved, please use double quotes around the string value."); + if (name) { patchBody.title = name; } From 1179dce05e15fd236b9dd773e265d6ffa4b46b92 Mon Sep 17 00:00:00 2001 From: "Robert So (robester0403)" <85914248+robester0403@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:40:54 -0400 Subject: [PATCH 4/7] PLAT-14359 added better error messages and a check for if no patch body value is detected --- scripts/setModuleDetails.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/scripts/setModuleDetails.js b/scripts/setModuleDetails.js index 48815c1..81578d0 100644 --- a/scripts/setModuleDetails.js +++ b/scripts/setModuleDetails.js @@ -21,25 +21,24 @@ export const setModuleDetails = async ( if (acceptanceCriteria) { patchBody.acceptance_criteria = acceptanceCriteria; } - + if (Object.keys(patchBody).length === 0) { + invalid("No module details was provided to update. Did you mean to include a value?"); + return; + } const patchSpinner = ora( "Updating module details." ).start(); - try { - const patchResponse = await apiClient.patch({ - path: `/v1/catalog/module/${id}`, - body: patchBody - }); + const patchResponse = await apiClient.patch({ + path: `/v1/catalog/module/${id}`, + body: patchBody + }).then(patchSpinner.stop()); - if (patchResponse.ok) { - patchSpinner.stop(); - valid(`Module details updated for ${id}.`); - } else { - patchSpinner.stop(); - invalid(`Unable to update module details for ${id}. Please try again.`); - } - } catch (error) { - invalid(`An error occurred: ${error.message}. Please try again.`); + if (patchResponse.ok) { + valid(`Module details updated for ${id}.`); + } else if (patchResponse.status === 404) { + invalid(`Cannot find requested module with id ${id}.`); + } else { + invalid("Unable to update modules details. Please try again later."); } }; From 93b6849c334791e7f70dca3757073b59ecd8c58c Mon Sep 17 00:00:00 2001 From: "Robert So (robester0403)" <85914248+robester0403@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:51:07 -0400 Subject: [PATCH 5/7] PLAT-14359 Put some better messaging on the response --- scripts/setModuleDetails.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/setModuleDetails.js b/scripts/setModuleDetails.js index 81578d0..3aba9dc 100644 --- a/scripts/setModuleDetails.js +++ b/scripts/setModuleDetails.js @@ -7,8 +7,6 @@ export const setModuleDetails = async ( ) => { const patchBody = {}; - section("To ensure the entire string is saved, please use double quotes around the string value."); - if (name) { patchBody.title = name; } @@ -22,7 +20,7 @@ export const setModuleDetails = async ( patchBody.acceptance_criteria = acceptanceCriteria; } if (Object.keys(patchBody).length === 0) { - invalid("No module details was provided to update. Did you mean to include a value?"); + invalid(" No module details were provided for the update. To correctly save the new value, please enclose it in double quotes. For example, use --description \"Your detailed description here\"."); return; } const patchSpinner = ora( From 149e5f5b7cd10ea581d4ed70e8d936841022ae61 Mon Sep 17 00:00:00 2001 From: "Robert So (robester0403)" <85914248+robester0403@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:51:40 -0400 Subject: [PATCH 6/7] PLAT-14359 small typo --- scripts/setModuleDetails.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setModuleDetails.js b/scripts/setModuleDetails.js index 3aba9dc..8d1c1a7 100644 --- a/scripts/setModuleDetails.js +++ b/scripts/setModuleDetails.js @@ -20,7 +20,7 @@ export const setModuleDetails = async ( patchBody.acceptance_criteria = acceptanceCriteria; } if (Object.keys(patchBody).length === 0) { - invalid(" No module details were provided for the update. To correctly save the new value, please enclose it in double quotes. For example, use --description \"Your detailed description here\"."); + invalid("No module details were provided for the update. To correctly save the new value, please enclose it in double quotes. For example, use --description \"Your detailed description here\"."); return; } const patchSpinner = ora( From 8f95e58aca433644b431c53740fe3283dbc269ef Mon Sep 17 00:00:00 2001 From: "Robert So (robester0403)" <85914248+robester0403@users.noreply.github.com> Date: Thu, 4 Apr 2024 13:53:16 -0400 Subject: [PATCH 7/7] PLAT-14359 unused import --- scripts/setModuleDetails.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/setModuleDetails.js b/scripts/setModuleDetails.js index 8d1c1a7..0355242 100644 --- a/scripts/setModuleDetails.js +++ b/scripts/setModuleDetails.js @@ -1,5 +1,5 @@ import ora from "ora"; -import { invalid, section, valid } from "../utils.js"; +import { invalid, valid } from "../utils.js"; import { apiClient } from "./utils/apiClient.js"; export const setModuleDetails = async (