Skip to content

Commit 6da924a

Browse files
Merge pull request #246 from ty-d/OpenCSPWithoutProgress
Open CSP pages and improve AfterUserAction
2 parents 6619739 + 3531bab commit 6da924a

File tree

1 file changed

+44
-38
lines changed

1 file changed

+44
-38
lines changed

src/commands/studio.ts

Lines changed: 44 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -251,45 +251,51 @@ class StudioActions {
251251
title: `Executing ${afterUserAction ? "AfterUserAction" : "UserAction"}: ${action.label}`,
252252
},
253253
() => {
254-
return this.api
255-
.actionQuery(query, parameters)
256-
.then(async (data) => {
257-
if (action.save) {
258-
await this.processSaveFlag(action.save);
259-
}
260-
if (!afterUserAction) {
261-
outputConsole(data.console);
262-
}
263-
if (!data.result.content.length) {
264-
// nothing to-do, just ignore it
265-
return;
266-
}
267-
const actionToProcess = data.result.content.pop();
254+
return new Promise((resolve, reject) => {
255+
this.api
256+
.actionQuery(query, parameters)
257+
.then(async (data) => {
258+
if (action.save) {
259+
await this.processSaveFlag(action.save);
260+
}
261+
if (!afterUserAction) {
262+
outputConsole(data.console);
263+
}
264+
if (!data.result.content.length) {
265+
// nothing to-do, just ignore it
266+
return;
267+
}
268+
const actionToProcess = data.result.content.pop();
268269

269-
// CSP pages should not have a progress bar
270-
if (actionToProcess.action === 2) {
271-
return;
272-
}
273-
return actionToProcess;
274-
})
275-
.then(
276-
(actionToProcess) =>
277-
actionToProcess &&
278-
!afterUserAction &&
279-
this.processUserAction(actionToProcess).then((answer) =>
280-
answer && (answer.msg || answer.msg === "")
281-
? this.userAction(action, true, answer.answer, answer.msg, type)
282-
: this.userAction(action, true, answer, "", type)
283-
)
284-
)
285-
.catch((err) => {
286-
console.log(err);
287-
outputChannel.appendLine(
288-
`Studio Action "${action.label}" not supported on ${this.api.config.host}:${this.api.config.port}[${this.api.config.ns}]`
289-
);
290-
outputChannel.show();
291-
return Promise.reject();
292-
});
270+
// CSP pages should not have a progress bar
271+
if (actionToProcess.action === 2) {
272+
resolve();
273+
}
274+
return actionToProcess;
275+
})
276+
.then(
277+
(actionToProcess) =>
278+
actionToProcess &&
279+
!afterUserAction &&
280+
this.processUserAction(actionToProcess).then((answer) => {
281+
// call AfterUserAction only if there is a valid answer
282+
if (answer) {
283+
answer.msg || answer.msg === ""
284+
? this.userAction(action, true, answer.answer, answer.msg, type)
285+
: this.userAction(action, true, answer, "", type);
286+
}
287+
})
288+
)
289+
.then(() => resolve())
290+
.catch((err) => {
291+
console.log(err);
292+
outputChannel.appendLine(
293+
`Studio Action "${action.label}" not supported on ${this.api.config.host}:${this.api.config.port}[${this.api.config.ns}]`
294+
);
295+
outputChannel.show();
296+
reject();
297+
});
298+
});
293299
}
294300
);
295301
}

0 commit comments

Comments
 (0)