-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Audit fix progress bar and overwrite confirmation UX #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cs-raj
wants to merge
3
commits into
v2-dev
Choose a base branch
from
fix/DX-5326
base: v2-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -194,7 +194,22 @@ export default class Workflows extends BaseClass { | |
|
|
||
| log.debug(`Loaded ${Object.keys(newWorkflowSchema).length} workflows for fixing`, this.config.auditContext); | ||
|
|
||
| if (Object.keys(newWorkflowSchema).length !== 0) { | ||
| const hasWorkflowsToFix = Object.keys(newWorkflowSchema).length !== 0; | ||
| let userConfirm: boolean; | ||
| if (!hasWorkflowsToFix) { | ||
| userConfirm = true; | ||
| } else if ( | ||
| this.config.flags['copy-dir'] || | ||
| this.config.flags['external-config']?.skipConfirm || | ||
| this.config.flags.yes | ||
| ) { | ||
| userConfirm = true; | ||
| } else { | ||
| this.completeProgress(true); | ||
| userConfirm = await cliux.confirm(commonMsg.FIX_CONFIRMATION); | ||
| } | ||
|
|
||
| if (hasWorkflowsToFix) { | ||
| log.debug(`Processing ${this.workflowSchema.length} workflows for fixes`, this.config.auditContext); | ||
|
|
||
| for (const workflow of this.workflowSchema) { | ||
|
|
@@ -237,7 +252,7 @@ export default class Workflows extends BaseClass { | |
|
|
||
| cliux.print(warningMessage, { color: 'yellow' }); | ||
|
|
||
| if (this.config.flags.yes || (await cliux.confirm(commonMsg.WORKFLOW_FIX_CONFIRMATION))) { | ||
| if (userConfirm) { | ||
| log.debug(`Deleting workflow ${name} (${uid})`, this.config.auditContext); | ||
| delete newWorkflowSchema[workflow.uid]; | ||
| } else { | ||
|
|
@@ -250,24 +265,36 @@ export default class Workflows extends BaseClass { | |
| } | ||
|
|
||
| log.debug(`Workflow schema fix completed`, this.config.auditContext); | ||
| await this.writeFixContent(newWorkflowSchema); | ||
| await this.writeFixContent(newWorkflowSchema, userConfirm); | ||
| } | ||
|
|
||
| async writeFixContent(newWorkflowSchema: Record<string, Workflow>) { | ||
| async writeFixContent(newWorkflowSchema: Record<string, Workflow>, preConfirmed?: boolean) { | ||
| log.debug(`Writing fix content`, this.config.auditContext); | ||
| log.debug(`Fix mode: ${this.fix}`, this.config.auditContext); | ||
| log.debug(`Copy directory flag: ${this.config.flags['copy-dir']}`, this.config.auditContext); | ||
| log.debug(`External config skip confirm: ${this.config.flags['external-config']?.skipConfirm}`, this.config.auditContext); | ||
| log.debug(`Yes flag: ${this.config.flags.yes}`, this.config.auditContext); | ||
| log.debug(`Workflows to write: ${Object.keys(newWorkflowSchema).length}`, this.config.auditContext); | ||
|
|
||
| if ( | ||
| this.fix && | ||
| (this.config.flags['copy-dir'] || | ||
| this.config.flags['external-config']?.skipConfirm || | ||
| this.config.flags.yes || | ||
| (await cliux.confirm(commonMsg.FIX_CONFIRMATION))) | ||
| let shouldWrite: boolean; | ||
| if (!this.fix) { | ||
| shouldWrite = false; | ||
| } else if (preConfirmed === true) { | ||
| shouldWrite = true; | ||
| } else if (preConfirmed === false) { | ||
| shouldWrite = false; | ||
| } else if ( | ||
| this.config.flags['copy-dir'] || | ||
| this.config.flags['external-config']?.skipConfirm || | ||
| this.config.flags.yes | ||
| ) { | ||
| shouldWrite = true; | ||
| } else { | ||
| this.completeProgress(true); | ||
| shouldWrite = await cliux.confirm(commonMsg.FIX_CONFIRMATION); | ||
| } | ||
|
Comment on lines
+280
to
+295
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cs-raj , Combined preConfirmed === true/false into a single check: preConfirmed !== undefined Redundant code. |
||
|
|
||
| if (shouldWrite) { | ||
| const outputPath = join(this.folderPath, this.config.moduleConfig[this.moduleName].fileName); | ||
| log.debug(`Writing fixed workflows to: ${outputPath}`, this.config.auditContext); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| /** | ||
| * Loaded by Mocha via --file before any test. Forces log config to non-debug | ||
| * so the real Logger never enables the debug path and unit tests don't throw | ||
| * when user has run: csdx config:set:log --level debug | ||
| */ | ||
| const cliUtils = require('@contentstack/cli-utilities'); | ||
| const configHandler = cliUtils.configHandler; | ||
| const originalGet = configHandler.get.bind(configHandler); | ||
| configHandler.get = function (key) { | ||
| if (key === 'log') return { level: 'info' }; | ||
| return originalGet(key); | ||
| }; |
4 changes: 4 additions & 0 deletions
4
...ontentstack-audit/test/unit/mock/contents/entries/empty_title_ct/en-us/empty-entries.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "entry-empty-title": { "title": "" }, | ||
| "entry-no-title": {} | ||
| } |
1 change: 1 addition & 0 deletions
1
packages/contentstack-audit/test/unit/mock/contents/entries/empty_title_ct/en-us/index.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"1":"empty-entries.json"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cs-raj , Combined preConfirmed === true/false into a single check: preConfirmed !== undefined