Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/components/app-switcher/app-switcher.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
<kbq-dropdown [class]="'kbq-app-switcher-sites'">
<div kbqDropdownStaticContent class="kbq-app-switcher-site">
@for (site of filteredSites; track site) {
@if (site.apps) {
@if (trigger.sitesMode && site.apps) {
<kbq-optgroup label="{{ site.name }}" />
}

Expand Down
34 changes: 19 additions & 15 deletions packages/components/app-switcher/app-switcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,21 +318,16 @@ export class KbqAppSwitcherTrigger
/** Number of applications to choose from
* @docs-private */
get appsCount(): number {
if (this.sitesMode) {
return this.originalSites.reduce((acc, site) => acc + site.apps.length, 0);
}

return this.originalApps.length;
return this.originalSites.reduce((acc, site) => acc + site.apps.length, 0);
}

/** Whether the sites are used or not
* @docs-private */
get sitesMode(): boolean {
return this.originalSites?.length > 0;
return this.originalSites.length > 1;
}

/** Whether the sites are used or not
* @docs-private */
/** @docs-private */
get currentApps() {
return this.sitesMode ? this.selectedSite.apps : this._parsedApps;
}
Expand All @@ -358,20 +353,29 @@ export class KbqAppSwitcherTrigger
set sites(value: KbqAppSwitcherSite[]) {
this.originalSites = value;

this._parsedSites = [];
if (this.originalSites.length === 1) {
this._parsedApps = this.makeGroupsForApps(
this.originalSites[0].apps,
KBQ_MIN_NUMBER_OF_APPS_TO_ENABLE_GROUPING
);
} else {
this._parsedSites = [];

value.forEach((site: KbqAppSwitcherSite) => {
const newSite: KbqAppSwitcherSite = { ...site, apps: [] };
value.forEach((site: KbqAppSwitcherSite) => {
const newSite: KbqAppSwitcherSite = { ...site, apps: [] };

newSite.apps = this.makeGroupsForApps(site.apps, KBQ_MIN_NUMBER_OF_APPS_TO_ENABLE_GROUPING);
newSite.apps = this.makeGroupsForApps(site.apps, KBQ_MIN_NUMBER_OF_APPS_TO_ENABLE_GROUPING);

this._parsedSites.push(newSite);
});
this._parsedSites.push(newSite);
});
}
}

private _parsedSites: KbqAppSwitcherSite[];

/** Array of applications */
/**
* @deprecated Will be removed in next major release, use `sites` with one element instead.
*/
@Input()
get apps(): KbqAppSwitcherApp[] {
return this._parsedApps;
Expand Down
86 changes: 46 additions & 40 deletions packages/components/app-switcher/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { KbqIconModule } from '@koobiq/components/icon';
imports: [KbqAppSwitcherModule, KbqButtonModule, KbqIconModule, KbqAppSwitcherComponent],
template: `
<div data-testid="e2eScreenshotTarget" style="width: 330px; height: 390px; padding: 8px">
<button #trigger="kbqAppSwitcher" kbq-button kbqAppSwitcher [apps]="apps" [(selectedApp)]="selected">
<button #trigger="kbqAppSwitcher" kbq-button kbqAppSwitcher [sites]="sites" [(selectedApp)]="selected">
<i kbq-icon="kbq-bento-menu_16"></i>
</button>

Expand All @@ -37,48 +37,54 @@ export class E2eAppSwitcherStates {
fill="white" />
</svg>
`;
apps: KbqAppSwitcherApp[] = [
{
name: 'Byte Sentinel',
caption: 'Byte 001',
id: 'SZFO_01',
icon: this.SVGIcon
},
{
name: 'CryptoWall',
id: 'SZFO_02',
icon: this.SVGIcon
},
{
name: 'App Instance 1',
caption: 'Instance Alias One',
id: 'SZFO_03',
icon: this.SVGIcon
},
{
name: 'App Instance 2',
id: 'SZFO_04',
icon: this.SVGIcon
},
{
name: 'App Instance 3',
caption: 'Instance Alias Three',
id: 'SZFO_05',
icon: this.SVGIcon
},
{
name: 'App Instance 4',
caption: 'Instance Alias Four',
id: 'SZFO_06',
icon: this.SVGIcon
},
sites: KbqAppSwitcherSite[] = [
{
name: 'Phantom Gate',
id: 'SZFO_07',
icon: this.SVGIcon
name: 'СЗФО',
id: '02',
apps: [
{
name: 'Byte Sentinel',
caption: 'Byte 001',
id: 'SZFO_01',
icon: this.SVGIcon
},
{
name: 'CryptoWall',
id: 'SZFO_02',
icon: this.SVGIcon
},
{
name: 'App Instance 1',
caption: 'Instance Alias One',
id: 'SZFO_03',
icon: this.SVGIcon
},
{
name: 'App Instance 2',
id: 'SZFO_04',
icon: this.SVGIcon
},
{
name: 'App Instance 3',
caption: 'Instance Alias Three',
id: 'SZFO_05',
icon: this.SVGIcon
},
{
name: 'App Instance 4',
caption: 'Instance Alias Four',
id: 'SZFO_06',
icon: this.SVGIcon
},
{
name: 'Phantom Gate',
id: 'SZFO_07',
icon: this.SVGIcon
}
]
}
];
selected: KbqAppSwitcherApp = this.apps[0];
selected: KbqAppSwitcherApp = this.sites[0].apps[0];
}

@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { KbqAppSwitcherApp, KbqAppSwitcherModule } from '@koobiq/components/app-switcher';
import { KbqAppSwitcherApp, KbqAppSwitcherModule, KbqAppSwitcherSite } from '@koobiq/components/app-switcher';
import { KbqButtonModule } from '@koobiq/components/button';
import { KbqIcon } from '@koobiq/components/icon';

Expand All @@ -17,7 +17,7 @@ import { KbqIcon } from '@koobiq/components/icon';
App: {{ selectedApp.name }}
<br />
<br />
<button kbq-button kbqAppSwitcher [apps]="apps" [(selectedApp)]="selectedApp">
<button kbq-button kbqAppSwitcher [sites]="sites" [(selectedApp)]="selectedApp">
<i kbq-icon="kbq-bento-menu_16"></i>
</button>
`,
Expand All @@ -34,46 +34,53 @@ export class AppSwitcherOverviewExample {
fill="white" />
</svg>
`;
apps: KbqAppSwitcherApp[] = [
{
name: 'Byte Sentinel',
caption: 'Byte 001',
id: 'SZFO_01',
icon: this.SVGIcon
},
{
name: 'CryptoWall',
id: 'SZFO_02',
icon: this.SVGIcon
},
{
name: 'App Instance 1',
caption: 'Instance Alias One',
id: 'SZFO_03',
icon: this.SVGIcon
},
{
name: 'App Instance 2',
id: 'SZFO_04',
icon: this.SVGIcon
},
{
name: 'App Instance 3',
caption: 'Instance Alias Three',
id: 'SZFO_05',
icon: this.SVGIcon
},
{
name: 'App Instance 4',
caption: 'Instance Alias Four',
id: 'SZFO_06',
icon: this.SVGIcon
},

sites: KbqAppSwitcherSite[] = [
{
name: 'Phantom Gate',
id: 'SZFO_07',
icon: this.SVGIcon
name: 'СЗФО',
id: '02',
apps: [
{
name: 'Byte Sentinel',
caption: 'Byte 001',
id: 'SZFO_01',
icon: this.SVGIcon
},
{
name: 'CryptoWall',
id: 'SZFO_02',
icon: this.SVGIcon
},
{
name: 'App Instance 1',
caption: 'Instance Alias One',
id: 'SZFO_03',
icon: this.SVGIcon
},
{
name: 'App Instance 2',
id: 'SZFO_04',
icon: this.SVGIcon
},
{
name: 'App Instance 3',
caption: 'Instance Alias Three',
id: 'SZFO_05',
icon: this.SVGIcon
},
{
name: 'App Instance 4',
caption: 'Instance Alias Four',
id: 'SZFO_06',
icon: this.SVGIcon
},
{
name: 'Phantom Gate',
id: 'SZFO_07',
icon: this.SVGIcon
}
]
}
];
selectedApp: KbqAppSwitcherApp = this.apps[0];
selectedApp: KbqAppSwitcherApp = this.sites[0].apps[1];
}
1 change: 1 addition & 0 deletions tools/public_api_guard/components/app-switcher.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ export interface KbqAppSwitcherSite {

// @public (undocumented)
export class KbqAppSwitcherTrigger extends KbqPopUpTrigger<KbqAppSwitcherComponent> implements AfterContentInit, OnInit {
// @deprecated (undocumented)
get apps(): KbqAppSwitcherApp[];
set apps(apps: KbqAppSwitcherApp[]);
get appsCount(): number;
Expand Down