From df3cc6a257e7fb8c887f87850e9244c50435814d Mon Sep 17 00:00:00 2001 From: Tomer Epstein <57438361+tomer-epstein@users.noreply.github.com> Date: Wed, 20 May 2020 11:42:35 +0300 Subject: [PATCH] [FEATURE] Clickable Steps (#282) * [FEATURE] Clickable Steps * "version": "1.0.9" --- backend/package.json | 2 +- backend/src/replayUtils.ts | 8 ++- backend/src/yeomanui.ts | 4 +- backend/tests/yeomanui.spec.ts | 2 +- frontend/src/App.vue | 15 ++++-- frontend/src/components/Navigation.vue | 24 +++++++-- frontend/tests/App.spec.js | 46 ++++++++++++++-- frontend/tests/components/Navigation.spec.js | 55 ++++++++++++++++++++ 8 files changed, 139 insertions(+), 17 deletions(-) diff --git a/backend/package.json b/backend/package.json index 1c4141df..e009dd7f 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "yeoman-ui", - "version": "1.0.8", + "version": "1.0.9", "displayName": "Application Wizard", "publisher": "SAPOS", "author": { diff --git a/backend/src/replayUtils.ts b/backend/src/replayUtils.ts index a2e49f30..b4b36aa2 100644 --- a/backend/src/replayUtils.ts +++ b/backend/src/replayUtils.ts @@ -12,6 +12,7 @@ export class ReplayUtils { private answersCache: Map; private replayStack: Array; private replayQueue: Array; + private numOfSteps: number; private prompts: Array; public isReplaying: boolean; @@ -26,10 +27,12 @@ export class ReplayUtils { this.replayStack = []; this.prompts = []; this.answersCache.clear(); + this.numOfSteps = 0; } - start(questions: Environment.Adapter.Questions, answers: Environment.Adapter.Answers): void { + start(questions: Environment.Adapter.Questions, answers: Environment.Adapter.Answers, numOfSteps: number): void { this._rememberAnswers(questions, answers); + this.numOfSteps = numOfSteps; this.replayQueue = JSON.parse(JSON.stringify(this.replayStack)); this.isReplaying = true; } @@ -41,6 +44,7 @@ export class ReplayUtils { this.replayQueue = []; const answers: Environment.Adapter.Answers = this.replayStack.pop(); ReplayUtils.setDefaults(questions, answers); + this.replayStack.splice(this.replayStack.length - this.numOfSteps + 1); return prompts; } @@ -74,7 +78,7 @@ export class ReplayUtils { getReplayState(): ReplayState{ if (this.isReplaying) { - if (this.replayQueue.length > 1) { + if (this.replayQueue.length > this.numOfSteps) { return ReplayState.Replaying; } else { return ReplayState.EndingReplay; diff --git a/backend/src/yeomanui.ts b/backend/src/yeomanui.ts index 1e3fedf9..8058a7c0 100644 --- a/backend/src/yeomanui.ts +++ b/backend/src/yeomanui.ts @@ -281,8 +281,8 @@ export class YeomanUI { return answers; } - private back(partialAnswers: Environment.Adapter.Answers): void { - this.replayUtils.start(this.currentQuestions, partialAnswers); + private back(partialAnswers: Environment.Adapter.Answers, numOfSteps: number): void { + this.replayUtils.start(this.currentQuestions, partialAnswers, numOfSteps); this.runGenerator(this.generatorName); } diff --git a/backend/tests/yeomanui.spec.ts b/backend/tests/yeomanui.spec.ts index cb98f159..795fcb0e 100644 --- a/backend/tests/yeomanui.spec.ts +++ b/backend/tests/yeomanui.spec.ts @@ -618,7 +618,7 @@ describe('yeomanui unit test', () => { // tslint:disable-next-line: no-unused-expression expect(yeomanUiInstance["replayUtils"]["isReplaying"]).to.be.false; - yeomanUiInstance["back"](undefined); + yeomanUiInstance["back"](undefined,1); // tslint:disable-next-line: no-unused-expression expect(yeomanUiInstance["replayUtils"]["isReplaying"]).to.be.true; diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 21162203..303f4175 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -22,7 +22,7 @@ - + @@ -115,7 +115,8 @@ function initialState() { messages: {}, showBusyIndicator: false, promptsInfoToDisplay: [], - isReplaying: false + isReplaying: false, + numOfSteps: 1 }; } @@ -173,11 +174,15 @@ export default { && !this.isDone); }, back() { + this.gotoStep(1); // go 1 step back + }, + gotoStep(numOfSteps) { // go numOfSteps step back try { this.isReplaying = true; + this.numOfSteps = numOfSteps; const answers = this.currentPrompt.answers; - if (this.promptIndex > 1) { - this.rpc.invoke("back", [answers]); + if (this.promptIndex - numOfSteps > 0) { + this.rpc.invoke("back", [answers, numOfSteps]); } else { this.reload(); } @@ -282,7 +287,7 @@ export default { async showPrompt(questions, name) { this.prepQuestions(questions); if (this.isReplaying) { - this.promptIndex--; + this.promptIndex -= this.numOfSteps; this.isReplaying = false; } const prompt = this.createPrompt(questions, name); diff --git a/frontend/src/components/Navigation.vue b/frontend/src/components/Navigation.vue index d117b471..302079eb 100644 --- a/frontend/src/components/Navigation.vue +++ b/frontend/src/components/Navigation.vue @@ -7,14 +7,17 @@ :key="`${index}-step`" :step="index" :complete="currentStep > index" - >{{ prompts[index - 1] ? prompts[index - 1].name : "" }} + @click="gotoStep(currentStep - index)" + :class="getStepClass(currentStep, index)" + > + {{ prompts[index - 1] ? prompts[index - 1].name : "" }} + -