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
[automate-1755] Reset checked projects list upon opening create… #1851
Conversation
There were actually two pieces of state to adjust. 1. Uncheck all the projects in the dropdown upon opening the modal for creating teams and tokens. 2. Update the label on the closed dropdown that reflects the state of that list. Signed-off-by: michael sorens <msorens@chef.io>
Signed-off-by: michael sorens <msorens@chef.io>
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.
Some pre-review comments.
@@ -48,7 +48,8 @@ <h2 slot="title">Create {{ objectNoun | titlecase }}</h2> | |||
<app-projects-dropdown | |||
[projects]="projects" | |||
(onProjectChecked)="onProjectChecked($event)" | |||
[disabled]="dropdownDisabled()"> | |||
[disabled]="dropdownDisabled()" | |||
[projectsUpdated]="projectsUpdatedEvent"> |
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.
Conduit to let the dropdown know to update the closed dropdown label.
// if a new list of projects to populate dropdown with is passed in we update the dropdown | ||
const checked = false; | ||
if (hasIn('assignableProjects.currentValue', changes)) { | ||
// update project dropdown if list changes | ||
if (changes.assignableProjects) { | ||
this.projects = {}; | ||
changes.assignableProjects.currentValue.forEach((proj: Project) => | ||
this.projects[proj.id] = { ...proj, checked }); | ||
this.projects[proj.id] = { ...proj, checked: false }); |
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.
PR extras: there are a variety of small cleanups such as the above in this PR unrelated to the issue being fixed.
// clear checked projects when opening | ||
if (changes.visible && (changes.visible.currentValue as boolean)) { | ||
Object.values(this.projects).forEach(p => p.checked = false); | ||
this.projectsUpdatedEvent.emit(); |
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.
This is half of the fix: resetting all the projects to unchecked upon opening the modal.
(keydown.enter)="closeColumnDropdown()" | ||
(keydown.esc)="closeColumnDropdown()" | ||
(keydown.enter)="closeDropdown()" | ||
(keydown.esc)="closeDropdown()" |
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.
PR extra: bug fix! This function had been renamed some time ago but these were missed.
ngOnInit(): void { | ||
if (this.projectsUpdated) { // an optional setting | ||
this.projectsUpdated.subscribe(() => { | ||
this.updateLabel(); | ||
}); | ||
} |
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.
This is the other half of the fix: resyncing the label to the now all-unchecked list of projects.
@@ -8,7 +8,7 @@ export const projectsFilterState = state => state.projectsFilter; | |||
export const options = createSelector(projectsFilterState, state => state.options); | |||
|
|||
export const assignableProjects = createSelector(projectsFilterState, state => { | |||
let projectOptions = state.options.filter((p: ProjectsFilterOption) => p.checked); | |||
let projectOptions = (state.options as ProjectsFilterOption[]).filter(p => p.checked); |
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.
Introduce strong type at the start so everything else in this block is now typed, too.
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.
works well, thanks for fixing this!!
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.
Looks good! 👍
🔩 Description: What code changed, and why?
The
CreateObjectModalComponent
(used for creating tokens and teams at present) appeared to retain the last set of selected projects. However, that was a phantom. They were not really selected. So upon saving the new token/team, it would show in the tokens/teams list with just(unassigned)
, leaving the user confused.Two separate things to fix:
Resetting all projects on the dropdown to unchecked.
Updating the dropdown label when it is closed to reflect that no projects are checked.
⛓️ Related Resources
NA
👍 Definition of Done
Opening the "create team" (or "create token") modal for the second time in succession shows an unchecked projects list.
👟 How to Build and Test the Change
rebuild automate-ui
Create one or more projects (Settings >> Projects >> Create Project)
Create a team (Settings >> Teams >> Create Team), selecting one or more projects (1).
Save that team.
Select "Create Team" a second time (2).
Observe the projects dropdown labels should say
(unassigned)
and the projects dropdown list of projects should show all unchecked.📷 Screenshots, if applicable