-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(TabbedGroupPicker): Emit selected values on cancel (#1613)
* fix(TabbedGroupPicker): Emit selected values on cancel * style(TabbedGroupPicker): remove unused import * Emit cancel event * Emit current tabs on cancel instead of only selected data * Add unit test for cancel
- Loading branch information
Showing
8 changed files
with
154 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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
1 change: 1 addition & 0 deletions
1
projects/novo-examples/src/components/tabbed-group-picker/index.ts
This file contains 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
export * from './tabbed-group-picker-no-selection-example'; | ||
export * from './tabbed-group-picker-basic'; | ||
export * from './tabbed-group-picker-big-groups-example'; | ||
export * from './tabbed-group-picker-footer-example'; | ||
export * from './tabbed-group-picker-groups-example'; | ||
export * from './tabbed-group-picker-quick-select-example'; |
1 change: 1 addition & 0 deletions
1
...o-examples/src/components/tabbed-group-picker/tabbed-group-picker-footer-example/index.ts
This file contains 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 @@ | ||
export * from './tabbed-group-picker-footer-example'; |
16 changes: 16 additions & 0 deletions
16
...d-group-picker/tabbed-group-picker-footer-example/tabbed-group-picker-footer-example.html
This file contains 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,16 @@ | ||
<div class="tabbed-group-picker-example"> | ||
<novo-tabbed-group-picker | ||
[tabs]="example_tab" | ||
[quickSelectConfig]="example_quickSelectConfig" | ||
[buttonConfig]="example_buttonConfig" | ||
(selectionChange)="onSelectionChange($event)" | ||
(cancelChange)="onCancelChange($event)" | ||
[showFooter]="true" | ||
></novo-tabbed-group-picker> | ||
<div class="selected-data-wrapper"> | ||
<h6>Selected Animal IDs:</h6> | ||
<div>{{ selectedAnimals.join(', ') }}</div> | ||
<h6>Selected Animal Category IDs:</h6> | ||
<div>{{ selectedAnimalCategories.join(', ') }}</div> | ||
</div> | ||
</div> |
103 changes: 103 additions & 0 deletions
103
...bed-group-picker/tabbed-group-picker-footer-example/tabbed-group-picker-footer-example.ts
This file contains 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,103 @@ | ||
import { Component } from '@angular/core'; | ||
import { ChildTab, ParentTab, TabbedGroupPickerTab } from 'novo-elements'; | ||
|
||
/** | ||
* @title Tabbed Group Picker - Footer Example | ||
*/ | ||
@Component({ | ||
selector: 'tabbed-group-picker-footer-example', | ||
templateUrl: 'tabbed-group-picker-footer-example.html', | ||
styleUrls: ['../tabbed-group-picker-example.scss'], | ||
}) | ||
export class TabbedGroupPickerFooterExample { | ||
getAnimals = (): { animalId: number; name: string }[] => | ||
['Dog', 'Cat', 'Mouse', 'Horse', 'Cow', 'Chicken', 'Pig', 'Sheep', 'Goat', 'Goose'].map((name, index) => ({ | ||
name, | ||
animalId: index + 1, | ||
})); | ||
|
||
getAnimalCategories = (): { groupId: number; name: string; children?: { animalId: number; name: string }[] }[] => { | ||
const animals = this.getAnimals(); | ||
const birds = ['Chicken', 'Goose'].map((name) => animals.find((animal) => animal.name === name)); | ||
const livestock = ['Cow', 'Pig', 'Sheep', 'Goat'].map((name) => animals.find((animal) => animal.name === name)); | ||
return [ | ||
{ | ||
name: 'Birds', | ||
groupId: 1, | ||
children: birds, | ||
}, | ||
{ | ||
name: 'Livestock', | ||
groupId: 2, | ||
children: livestock, | ||
}, | ||
]; | ||
}; | ||
example_tab = [ | ||
{ | ||
typeName: 'animals', | ||
typeLabel: 'Animals', | ||
valueField: 'animalId', | ||
labelField: 'name', | ||
data: this.getAnimals(), | ||
}, | ||
{ | ||
typeName: 'animalCategories', | ||
typeLabel: 'Animal Categories', | ||
valueField: 'groupId', | ||
labelField: 'name', | ||
childTypeName: 'animals', | ||
data: this.getAnimalCategories(), | ||
}, | ||
]; | ||
public example_quickSelectConfig = { | ||
label: 'Quick Select', | ||
items: [ | ||
{ | ||
childTypeName: 'animals', | ||
children: [2], | ||
label: 'Pure Evil', | ||
}, | ||
{ | ||
childTypeName: 'animals', | ||
children: [1, 6, 9], | ||
label: 'My Pets', | ||
}, | ||
{ | ||
childTypeName: 'animals', | ||
all: true, | ||
label: 'All Animals', | ||
}, | ||
], | ||
}; | ||
|
||
public buttonLabel: string = 'Nothing Selected'; | ||
public example_buttonConfig = { | ||
theme: 'select', | ||
side: 'right', | ||
icon: 'collapse', | ||
label: this.buttonLabel, | ||
selector: 'buttonConfig', | ||
}; | ||
|
||
selectedAnimals: string[] = []; | ||
selectedAnimalCategories: string[] = []; | ||
|
||
onSelectionChange(selectedData: TabbedGroupPickerTab[]) { | ||
this.selectedAnimals = (selectedData.find(({ typeName }) => typeName === 'animals') as ChildTab).data.map(({ animalId }) => animalId); | ||
this.selectedAnimalCategories = (selectedData.find(({ typeName }) => typeName === 'animalCategories') as ParentTab).data.map( | ||
({ groupId }) => groupId, | ||
); | ||
this.example_buttonConfig.label = this.buildButtonLabel(); | ||
} | ||
|
||
onCancelChange([animalsTab, animalCategoriesTab]: TabbedGroupPickerTab[]) { | ||
this.selectedAnimals = animalsTab.data.filter((animal) => animal.selected).map(({ animalId }) => animalId); | ||
this.selectedAnimalCategories = animalCategoriesTab.data.filter((group) => group.selected).map(({ groupId }) => groupId); | ||
this.example_buttonConfig.label = this.buildButtonLabel(); | ||
} | ||
|
||
buildButtonLabel(): string { | ||
return this.selectedAnimals.length ? `Animals (${this.selectedAnimals.length})` : 'Nothing Selected'; | ||
} | ||
} |
This file contains 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 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