chore: Migrate rose dropdown to HDS (#2826)

This commit is contained in:
Dharini Jeeva authored and GitHub committed 2025-05-15 11:05:05 -07:00
1 parent 1c774aa783
commit e222d5b909
28 files changed
+375 -518

No files matched your search

+5 -4
View File
@@ -52,7 +52,7 @@ test.describe('Scope tests', () => {
}) => {
const headerNavLocator = authedPage.getByLabel('header-nav');
await expect(headerNavLocator).toBeVisible();
await expect(headerNavLocator.locator('summary')).toHaveText('Global');
await expect(headerNavLocator.locator('.hds-dropdown-toggle-button')).toHaveText('Global');
await expect(
authedPage.getByRole('link', { name: targetA.name }),
@@ -67,7 +67,7 @@ test.describe('Scope tests', () => {
});
await orgAHeaderNavLink.click();
await expect(headerNavLocator.locator('summary')).toHaveText(orgA.name);
await expect(headerNavLocator.locator('.hds-dropdown-toggle-button')).toHaveText(orgA.name);
await expect(
authedPage.getByRole('link', { name: targetA.name }),
).toBeVisible();
@@ -75,13 +75,14 @@ test.describe('Scope tests', () => {
authedPage.getByRole('link', { name: targetB.name }),
).toBeHidden();
await headerNavLocator.click();
const orgBHeaderNavLink = authedPage.getByRole('link', {
name: orgB.name,
});
await expect(orgBHeaderNavLink).toBeVisible();
await orgBHeaderNavLink.click();
await expect(headerNavLocator.locator('summary')).toHaveText(orgB.name);
await expect(headerNavLocator.locator('.hds-dropdown-toggle-button')).toHaveText(orgB.name);
await expect(
authedPage.getByRole('link', { name: targetB.name }),
).toBeVisible();
+24 -23
View File
@@ -3,38 +3,39 @@
SPDX-License-Identifier: BUSL-1.1
}}
<Rose::Dropdown
@text={{if
this.scope.org.isGlobal
(t 'titles.global')
this.scope.org.displayName
}}
@icon={{if this.scope.org.isGlobal 'globe' 'org'}}
as |dropdown|
>
<Hds::Dropdown @enableCollisionDetection={{true}} as |dd|>
<dd.ToggleButton
@text={{if
this.scope.org.isGlobal
(t 'titles.global')
this.scope.org.displayName
}}
@icon={{if this.scope.org.isGlobal 'globe' 'org'}}
@color='secondary'
/>
{{#if this.session.data.authenticated.isGlobal}}
<dropdown.link @route='scopes.scope' @model='global'>
<dd.Interactive @route='scopes.scope' @model='global'>
{{t 'titles.global'}}
</dropdown.link>
<dropdown.separator />
</dd.Interactive>
{{/if}}
{{#each this.scope.orgsList as |org|}}
<dropdown.link @route='scopes.scope' @model={{org.id}}>
<dd.Interactive @route='scopes.scope' @model={{org.id}}>
{{org.displayName}}
</dropdown.link>
</dd.Interactive>
{{/each}}
</Rose::Dropdown>
</Hds::Dropdown>
{{#if this.scope.project}}
<Rose::Dropdown
@text={{this.scope.project.displayName}}
@icon='grid'
as |dropdown|
>
<Hds::Dropdown as |dd|>
<dd.ToggleButton
@icon='grid'
@text={{this.scope.project.displayName}}
@color='secondary'
/>
{{#each this.scope.projectsList as |project|}}
<dropdown.link @route='scopes.scope' @model={{project.id}}>
<dd.Interactive @route='scopes.scope' @model={{project.id}}>
{{project.displayName}}
</dropdown.link>
</dd.Interactive>
{{/each}}
</Rose::Dropdown>
</Hds::Dropdown>
{{/if}}
@@ -8,7 +8,7 @@ import { service } from '@ember/service';
import { action } from '@ember/object';
import { loading } from 'ember-loading';
import { notifySuccess, notifyError } from 'core/decorators/notify';
import { tracked } from '@glimmer/tracking';
export default class ScopesScopeGroupsGroupAddMembersController extends Controller {
// =services
@@ -16,6 +16,9 @@ export default class ScopesScopeGroupsGroupAddMembersController extends Controll
// =attributes
@tracked scopeIds = [];
queryParams = [{ scopeIds: { type: 'array' } }];
/**
* Returns a flat array of scopes, sorted and "grouped by" parent scope,
* beginning with global.
@@ -33,8 +36,33 @@ export default class ScopesScopeGroupsGroupAddMembersController extends Controll
return sorted;
}
/**
* Returns the filters object used for displaying filter tags.
* @type {object}
*/
get filters() {
return {
allFilters: {
scopeIds: this.model.scopes,
},
selectedFilters: {
scopeIds: this.scopeIds,
},
};
}
// =actions
/**
* Sets a query param to the value of selectedItems
* @param {string} paramKey
* @param {[string]} selectedItems
*/
@action
applyFilter(paramKey, selectedItems) {
this[paramKey] = [...selectedItems];
}
/**
* Adds members to the group and saves, replaces with the members index
* route, and notifies the user of success or error.
@@ -57,22 +85,4 @@ export default class ScopesScopeGroupsGroupAddMembersController extends Controll
async cancel() {
await this.router.replaceWith('scopes.scope.groups.group.members');
}
/**
* Calls filterBy action located in the route.
* @param {string} field
* @param {[ScopeModel]} value
*/
@action
callFilterBy(field, value) {
this.send('filterBy', field, value);
}
/**
* Calls clearAllFilters action located in the route.
*/
@action
callClearAllFilters() {
this.send('clearAllFilters');
}
}
@@ -8,6 +8,7 @@ import { service } from '@ember/service';
import { action } from '@ember/object';
import { loading } from 'ember-loading';
import { notifySuccess, notifyError } from 'core/decorators/notify';
import { tracked } from '@glimmer/tracking';
export default class ScopesScopeRolesRoleAddPrincipalsController extends Controller {
// =services
@@ -16,6 +17,9 @@ export default class ScopesScopeRolesRoleAddPrincipalsController extends Control
// =attributes
@tracked scopeIds = [];
queryParams = [{ scopeIds: { type: 'array' } }];
/**
* Returns a flat array of scopes, sorted and "grouped by" parent scope,
* beginning with global.
@@ -33,6 +37,22 @@ export default class ScopesScopeRolesRoleAddPrincipalsController extends Control
return sorted;
}
/**
* Returns the filters object used for displaying filter tags.
* @type {object}
*/
get filters() {
return {
allFilters: {
scopeIds: this.model.scopes,
},
selectedFilters: {
scopeIds: this.scopeIds,
},
};
}
// =actions
/**
@@ -49,6 +69,16 @@ export default class ScopesScopeRolesRoleAddPrincipalsController extends Control
this.router.replaceWith('scopes.scope.roles.role.principals');
}
/**
* Sets a query param to the value of selectedItems
* @param {string} paramKey
* @param {[string]} selectedItems
*/
@action
applyFilter(paramKey, selectedItems) {
this[paramKey] = [...selectedItems];
}
/**
* Redirect to role principals as if nothing ever happened.
*/
@@ -56,22 +86,4 @@ export default class ScopesScopeRolesRoleAddPrincipalsController extends Control
cancel() {
this.router.replaceWith('scopes.scope.roles.role.principals');
}
/**
* Calls filterBy action located in the route.
* @param {string} field
* @param {[ScopeModel]} value
*/
@action
callFilterBy(field, value) {
this.send('filterBy', field, value);
}
/**
* Calls clearAllFilters action located in the route.
*/
@action
callClearAllFilters() {
this.send('clearAllFilters');
}
}
@@ -21,6 +21,56 @@ export default class ScopesScopeWorkersIndexController extends Controller {
// =attributes
@tracked selectedWorker;
@tracked tags = [];
queryParams = [{ tags: { type: 'array' } }];
/**
* Returns all unique tags of the selected worker in base64 encoded format.
* @type {object}
*/
get workerTagOptions() {
const allTags = this.model
.flatMap((worker) => worker.allTags)
.filter(Boolean);
// Filter out duplicate tags
const uniqueTags = allTags.reduce((acc, currentTag) => {
const doesTagExist = acc.some(
(tag) => tag.key === currentTag.key && tag.value === currentTag.value,
);
if (!doesTagExist) {
acc.push(currentTag);
}
return acc;
}, []);
return uniqueTags.map((tag) => {
const encodedTag = window.btoa(JSON.stringify(tag));
return {
id: encodedTag,
name: tag.value,
key: tag.key,
};
});
}
/**
* Returns the filters object used for displaying filter tags.
* @type {object}
*/
get filters() {
return {
allFilters: {
tags: this.workerTagOptions,
},
selectedFilters: {
tags: this.tags,
},
};
}
/**
* If can list (at least): return default welcome message.
@@ -65,16 +115,16 @@ export default class ScopesScopeWorkersIndexController extends Controller {
return `${tag.key} = ${tag.value}`;
}
/**
* Determine equality between two tags based on both key and value.
* @param {object} firstTag
* @param {object} secondTag
*/
isEqual(firstTag, secondTag) {
return firstTag.key === secondTag.key && firstTag.value === secondTag.value;
}
// =actions
/**
* Sets a query param to the value of selectedItems
* @param {string} paramKey
* @param {[string]} selectedItems
*/
@action
applyFilter(paramKey, selectedItems) {
this[paramKey] = [...selectedItems];
}
/**
* Toggle the tags flyout to display or hide the tags of a worker.
@@ -132,24 +182,6 @@ export default class ScopesScopeWorkersIndexController extends Controller {
await this.router.refresh();
}
/**
* Calls filterBy action located in the route.
* @param {string} field
* @param {[object]} value
*/
@action
callFilterBy(field, value) {
this.send('filterBy', field, value);
}
/**
* Calls clearAllFilters action located in the route.
*/
@action
callClearAllFilters() {
this.send('clearAllFilters');
}
/**
* Refreshes worker data.
*/
@@ -5,9 +5,6 @@
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import { action } from '@ember/object';
import { resourceFilter } from 'core/decorators/resource-filter';
export default class ScopesScopeGroupsGroupAddMembersRoute extends Route {
// =services
@@ -16,12 +13,12 @@ export default class ScopesScopeGroupsGroupAddMembersRoute extends Route {
// =attributes
@resourceFilter({
allowed: (route) => route.store.peekAll('scope'),
serialize: ({ id }) => id,
findBySerialized: ({ id }, value) => id === value,
})
scope;
queryParams = {
scopeIds: {
refreshModel: true,
replace: true,
},
};
// =methods
@@ -38,42 +35,25 @@ export default class ScopesScopeGroupsGroupAddMembersRoute extends Route {
* Loads all users and returns them with the group.
* @return {Promise<{group: GroupModel, users: [UserModel], scopes: [ScopeModel] }> }
*/
async model() {
async model({ scopeIds }) {
const group = this.modelFor('scopes.scope.groups.group');
// filter out projects, since the user resource exists only on org and above
const scopes = this.store
.peekAll('scope')
.filter((scope) => !scope.isProject);
const scopeIDs = this.scope?.map((scope) => scope.id);
const query = { filters: { scope_id: [] } };
scopeIDs?.forEach((scopeID) => {
scopeIds?.forEach((scopeID) => {
query.filters.scope_id.push({ equals: scopeID });
});
const users = await this.store.query('user', {
scope_id: 'global',
recursive: true,
query,
});
return { group, users, scopes };
}
// =actions
/**
* Sets the specified resource filter field to the specified value.
* @param {string} field
* @param value
*/
@action
filterBy(field, value) {
this[field] = value;
}
/**
* Clears and filter selections.
*/
@action
clearAllFilters() {
this.scope = [];
}
}
@@ -5,8 +5,6 @@
import Route from '@ember/routing/route';
import { service } from '@ember/service';
import { action } from '@ember/object';
import { resourceFilter } from 'core/decorators/resource-filter';
import {
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_LDAP,
@@ -20,12 +18,12 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
// =attributes
@resourceFilter({
allowed: (route) => route.store.peekAll('scope'),
serialize: ({ id }) => id,
findBySerialized: ({ id }, value) => id === value,
})
scope;
queryParams = {
scopeIds: {
refreshModel: true,
replace: true,
},
};
// =methods
@@ -42,12 +40,12 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
* Returns the current role, all users, and all groups
* @return {{role: RoleModel, users: [UserModel], groups: [GroupModel]}}
*/
async model() {
async model({ scopeIds }) {
const role = this.modelFor('scopes.scope.roles.role');
const scopes = this.store.peekAll('scope');
const scopeIDs = this.scope?.map((scope) => scope.id);
const query = { filters: { scope_id: [] } };
scopeIDs?.forEach((scopeID) => {
scopeIds?.forEach((scopeID) => {
query.filters.scope_id.push({ equals: scopeID });
});
const users = await this.store.query('user', {
@@ -83,24 +81,7 @@ export default class ScopesScopeRolesRoleAddPrincipalsRoute extends Route {
users,
groups,
managedGroups: managedGroups.flat(),
selectedScopes: this.scope,
};
}
/**
* Sets the specified resource filter field to the specified value.
* @param {string} field
* @param value
*/
@action
filterBy(field, value) {
this[field] = value;
}
/**
* Clears and filter selections.
*/
@action
clearAllFilters() {
this.scope = [];
}
}
@@ -4,60 +4,42 @@
*/
import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { resourceFilter } from 'core/decorators/resource-filter';
import sortBy from 'lodash/sortBy';
export default class ScopesScopeWorkersIndexRoute extends Route {
// =attributes
// This resource filter depends on the data from the list route so can't
// live in the same model where the list is loaded as it needs to get loaded
// first. If it's in the same file it might try to grab the model data before
// it's loaded.
@resourceFilter({
allowed: (route) => {
const allTags = route
.modelFor('scopes.scope.workers')
.flatMap((worker) => worker.allTags)
.filter(Boolean);
// Filter out duplicate tags
return allTags.reduce((uniqueTags, currentTag) => {
const isDuplicateTag = uniqueTags.some(
(tag) => tag.key === currentTag.key && tag.value === currentTag.value,
);
if (!isDuplicateTag) {
uniqueTags.push(currentTag);
}
return uniqueTags;
}, []);
queryParams = {
tags: {
refreshModel: true,
replace: true,
},
findBySerialized: ({ key: itemKey, value: itemValue }, { key, value }) =>
itemKey === key && itemValue === value,
refreshRouteOnChange: false,
})
tags;
};
// =methods
model() {
model({ tags }) {
const workers = sortBy(
this.modelFor('scopes.scope.workers'),
'displayName',
);
if (this.tags?.length) {
if (tags?.length) {
// Return workers that have config and/or api tags that have at
// least one intersection with the filter tags
// Decode the tags from base64
const decodedTags = tags.map((tag) => {
const decodedString = window.atob(tag);
return JSON.parse(decodedString);
});
return workers.filter((worker) => {
if (!worker.config_tags && !worker.api_tags) {
return null;
}
const workerTags = worker.allTags;
return this.tags.some((tag) =>
return decodedTags.some((tag) =>
workerTags.some(
(workerTag) =>
tag.key === workerTag.key && tag.value === workerTag.value,
@@ -78,26 +60,6 @@ export default class ScopesScopeWorkersIndexRoute extends Route {
}
}
/**
* Clears filter selections.
*/
@action
clearAllFilters() {
this.tags = [];
this.refresh();
}
/**
* Sets the specified resource filter field to the specified value.
* @param {string} field
* @param value
*/
@action
filterBy(field, value) {
this[field] = value;
this.refresh();
}
setupController(controller) {
const scope = this.modelFor('scopes.scope');
super.setupController(...arguments);
+27 -4
View File
@@ -613,7 +613,6 @@
}
.auth-methods-list-table,
.workers-list-table,
.sessions-list-table {
margin-top: 1rem;
}
@@ -945,9 +944,28 @@
// workers
.workers {
.rose-dropdown-content {
max-height: 300px;
overflow: scroll;
> div {
margin-bottom: 1rem;
}
.tags-list {
display: flex;
.toolbar-refresher {
margin-left: auto;
}
.grouping {
display: flex;
align-items: center;
gap: 0.2rem;
padding: 0.5rem 1rem;
text-transform: uppercase;
}
li:has(.indentation) {
padding-left: 2.25rem;
}
}
}
@@ -1029,3 +1047,8 @@
margin-left: 1.5rem;
}
}
// dropdown checkbox list
.dropdown-checkbox-list {
margin-bottom: 1rem;
}
@@ -29,25 +29,27 @@
name=@model.scope.displayName
}}</Hds::Text::Body>
<Rose::Dropdown
@text={{t 'actions.choose-different-org'}}
@icon='org'
as |dropdown|
>
<dropdown.link @route='scopes.scope.authenticate' @model='global'>
<Hds::Dropdown @listPosition='bottom-left' as |dd|>
<dd.ToggleButton
@text={{t 'actions.choose-different-org'}}
@icon='org'
@color='secondary'
/>
<dd.Interactive
@route='scopes.scope.authenticate'
@model='global'
>
{{t 'titles.global'}}
</dropdown.link>
</dd.Interactive>
{{#each this.sortedScopes as |scope|}}
<dropdown.link
<dd.Interactive
@route='scopes.scope.authenticate'
@model={{scope.id}}
>
{{scope.displayName}}
</dropdown.link>
</dd.Interactive>
{{/each}}
</Rose::Dropdown>
</Hds::Dropdown>
<Hds::Separator />
<Rose::Nav::Tabs as |nav|>
@@ -32,62 +32,16 @@
<page.body>
{{#let
(resource-filter 'scopes.scope.groups.group.add-members' 'scope')
as |filter|
}}
<Rose::Toolbar as |toolbar|>
<toolbar.primary>
<Rose::Form as |form|>
<Rose::Dropdown
@text={{t (concat 'resources.' filter.name '.title')}}
@count={{filter.selectedValue.length}}
@ignoreClickInside={{true}}
as |dropdown|
>
<ul>
<form.checkboxGroup
@name={{filter.name}}
@items={{this.flatSortedScopes}}
@selectedItems={{filter.selectedValue}}
@onChange={{fn this.callFilterBy filter.name}}
as |group|
>
<li
class={{if
group.item.isOrg
'indent-label-1'
(if group.item.isProject 'indent-label-2')
}}
>
<dropdown.item>
<group.checkbox
@label={{group.item.displayName}}
value={{group.item}}
/>
</dropdown.item>
</li>
</form.checkboxGroup>
</ul>
</Rose::Dropdown>
{{#if
(has-resource-filter-selections
'scopes.scope.groups.group.add-members' 'scope'
)
}}
<Hds::Button
@size='small'
@icon='x'
@text={{t 'actions.clear-all-filters'}}
{{on 'click' this.callClearAllFilters}}
/>
{{/if}}
</Rose::Form>
</toolbar.primary>
</Rose::Toolbar>
{{/let}}
<Dropdown
name='scopeIds'
class='dropdown-checkbox-list'
@listPosition='bottom-left'
@toggleText={{t 'resources.scope.title_plural'}}
@itemOptions={{@model.scopes}}
@checkedItems={{this.scopeIds}}
@applyFilter={{fn this.applyFilter 'scopeIds'}}
/>
<FilterTags @filters={{this.filters}} />
<br />
<Form::Group::AddMembers
@@ -32,62 +32,16 @@
<page.body>
{{#let
(resource-filter 'scopes.scope.roles.role.add-principals' 'scope')
as |filter|
}}
<Rose::Toolbar as |toolbar|>
<toolbar.primary>
<Rose::Form as |form|>
<Rose::Dropdown
@text={{t (concat 'resources.' filter.name '.title')}}
@count={{filter.selectedValue.length}}
@ignoreClickInside={{true}}
as |dropdown|
>
<ul>
<form.checkboxGroup
@name={{filter.name}}
@items={{this.flatSortedScopes}}
@selectedItems={{filter.selectedValue}}
@onChange={{fn this.callFilterBy filter.name}}
as |group|
>
<li
class={{if
group.item.isOrg
'indent-label-1'
(if group.item.isProject 'indent-label-2')
}}
>
<dropdown.item>
<group.checkbox
@label={{group.item.displayName}}
value={{group.item}}
/>
</dropdown.item>
</li>
</form.checkboxGroup>
</ul>
</Rose::Dropdown>
{{#if
(has-resource-filter-selections
'scopes.scope.roles.role.add-principals' 'scope'
)
}}
<Hds::Button
@size='small'
@icon='x'
@text={{t 'actions.clear-all-filters'}}
{{on 'click' this.callClearAllFilters}}
/>
{{/if}}
</Rose::Form>
</toolbar.primary>
</Rose::Toolbar>
{{/let}}
<Dropdown
name='scopeIds'
class='dropdown-checkbox-list'
@listPosition='bottom-left'
@toggleText={{t 'resources.scope.title_plural'}}
@itemOptions={{@model.scopes}}
@checkedItems={{this.scopeIds}}
@applyFilter={{fn this.applyFilter 'scopeIds'}}
/>
<FilterTags @filters={{this.filters}} />
<br />
<Form::Role::AddPrincipals
@@ -69,6 +69,7 @@
</S.Generic>
{{/if}}
</Hds::SegmentedGroup>
<FilterTags @filters={{this.filters}} />
{{#if @model.targets}}
@@ -34,67 +34,44 @@
<page.body class='workers'>
{{#if @model}}
<Rose::Toolbar as |toolbar|>
<toolbar.primary>
<Rose::Form as |form|>
{{#let
(resource-filter 'scopes.scope.workers.index' 'tags')
as |filter|
}}
{{#if filter.allowedValues}}
<Rose::Dropdown
@text={{t (concat 'form.' filter.name '.label')}}
@count={{filter.selectedValue.length}}
@ignoreClickInside={{true}}
as |dropdown|
>
{{#each-in
(group-by 'key' filter.allowedValues)
as |key tags|
}}
<dropdown.section @title={{key}} @icon='tag' />
<form.checkboxGroup
@name={{key}}
@items={{tags}}
@selectedItems={{filter.selectedValue}}
@onChange={{fn this.callFilterBy filter.name}}
@itemEqualityFunc={{this.isEqual}}
as |group|
>
<dropdown.item class='indent-label-1'>
<group.checkbox
@label={{group.item.value}}
value={{group.item}}
/>
</dropdown.item>
</form.checkboxGroup>
{{/each-in}}
</Rose::Dropdown>
{{/if}}
{{/let}}
{{#if
(has-resource-filter-selections
'scopes.scope.workers.index' 'tags'
)
}}
<Hds::Button
@size='small'
@icon='x'
@text={{t 'actions.clear-all-filters'}}
{{on 'click' this.callClearAllFilters}}
/>
{{/if}}
</Rose::Form>
</toolbar.primary>
<toolbar.secondary>
<ToolbarRefresher @onClick={{this.refresh}} />
</toolbar.secondary>
</Rose::Toolbar>
<div class='tags-list'>
<Dropdown
name='tags'
@listPosition='bottom-left'
@toggleText={{t 'form.tags.label'}}
@itemOptions={{this.workerTagOptions}}
@checkedItems={{this.tags}}
@applyFilter={{fn this.applyFilter 'tags'}}
@isGrouped={{true}}
as |FD selectItem itemOptions|
>
{{#each-in (group-by 'key' itemOptions) as |key groupItems|}}
<FD.Generic class='grouping'>
<Hds::Icon @name='tag' @isInline={{true}} @color='faint' />
<Hds::Text::Display
@size='100'
@weight='medium'
@color='faint'
>{{key}}</Hds::Text::Display>
</FD.Generic>
{{#each groupItems as |item|}}
<FD.Checkbox
class='indentation'
@value={{item.id}}
checked={{includes item.id this.tags}}
{{on 'change' selectItem}}
>
{{item.name}}
</FD.Checkbox>
{{/each}}
{{/each-in}}
</Dropdown>
<ToolbarRefresher @onClick={{this.refresh}} />
</div>
<FilterTags @filters={{this.filters}} />
<Hds::Table
class='workers-list-table'
@model={{@model}}
@columns={{array
(hash label=(t 'resources.worker.title'))
@@ -401,8 +401,8 @@ module('Acceptance | authentication', function (hooks) {
test('org scopes with no auth methods are not visible in dropdown', async function (assert) {
await visit(authMethodGlobalAuthenticateURL);
await click('.rose-dropdown-trigger');
await click('.hds-dropdown-toggle-button');
assert.dom('.rose-dropdown-content a').exists({ count: 3 });
assert.dom('.hds-dropdown-list-item a').exists({ count: 3 });
});
});
@@ -96,6 +96,7 @@ module('Acceptance | workers | list', function (hooks) {
await click(selectors.WORKER_TAGS_FILTER_DROPDOWN);
await click(selectors.WORKER_TAGS_FILTER_DROPDOWN_FIRST_ITEM);
await click(selectors.WORKER_TAGS_FILTER_APPLY_BUTTON);
assert.dom(commonSelectors.TABLE_ROW).exists({ count: 1 });
});
@@ -36,9 +36,12 @@ export const WORKER_TAGS_FLYOUT_TABLE_ROWS =
export const WORKER_TAGS_FLYOUT_VIEW_MORE_TAGS_BUTTON =
'[data-test-worker-tags-flyout] .view-more-tags a';
export const WORKER_TAGS_FILTER_DROPDOWN = '.workers details summary';
export const WORKER_TAGS_FILTER_DROPDOWN =
'.workers .hds-dropdown-toggle-button';
export const WORKER_TAGS_FILTER_DROPDOWN_FIRST_ITEM =
'.workers details div input:first-child';
'.workers .hds-dropdown-list-item:nth-of-type(2) input';
export const WORKER_TAGS_FILTER_APPLY_BUTTON =
'.workers [data-test-dropdown-apply-button]';
export const TABLE_ROW_WORKER_TAGS_FLYOUT_BUTTON = (workerId) =>
`[data-test-worker-tags-flyout-button="${workerId}"]`;
@@ -31,7 +31,9 @@ module(
globalScope: null,
addMembers: null,
};
const model = {
scopes: [{ id: 'global', type: 'global' }],
};
hooks.beforeEach(async function () {
await authenticateSession({});
store = this.owner.lookup('service:store');
@@ -82,33 +84,19 @@ module(
assert.deepEqual(group.members, [user]);
});
test('callFilterBy action adds expected property values to route', async function (assert) {
const route = this.owner.lookup(
'route:scopes/scope/groups/group/add-members',
);
await visit(urls.addMembers);
const scope = await store.findRecord('scope', instances.scopes.global.id);
test('applyFilter action sets expected values correctly', async function (assert) {
controller.set('model', model);
const selectedItems = ['yes'];
controller.applyFilter('scopeIds', selectedItems);
assert.notOk(route.scope);
controller.callFilterBy('scope', [scope]);
assert.deepEqual(route.scope, [scope]);
assert.deepEqual(controller.scopeIds, selectedItems);
});
test('callClearAllFilters action removes all filter values from route', async function (assert) {
const route = this.owner.lookup(
'route:scopes/scope/groups/group/add-members',
);
await visit(urls.addMembers);
const scope = await store.findRecord('scope', instances.scopes.global.id);
route.scope = [scope];
test('filters returns expected entries', function (assert) {
controller.set('model', model);
assert.deepEqual(route.scope, [scope]);
controller.callClearAllFilters();
assert.deepEqual(route.scope, []);
assert.ok(controller.filters.allFilters);
assert.ok(controller.filters.selectedFilters);
});
},
);
@@ -31,6 +31,9 @@ module(
const urls = {
addPrincipals: null,
};
const model = {
scopes: [{ id: 'global', type: 'global' }],
};
hooks.beforeEach(async function () {
await authenticateSession({});
@@ -98,33 +101,19 @@ module(
]);
});
test('callFilterBy action adds expected property values to route', async function (assert) {
const route = this.owner.lookup(
'route:scopes/scope/roles/role/add-principals',
);
await visit(urls.addPrincipals);
const scope = await store.findRecord('scope', instances.scopes.global.id);
test('applyFilter action sets expected values correctly', async function (assert) {
controller.set('model', model);
const selectedItems = ['yes'];
controller.applyFilter('scopeIds', selectedItems);
assert.notOk(route.scope);
controller.callFilterBy('scope', [scope]);
assert.deepEqual(route.scope, [scope]);
assert.deepEqual(controller.scopeIds, selectedItems);
});
test('callClearAllFilters action removes all filter values from route', async function (assert) {
const route = this.owner.lookup(
'route:scopes/scope/roles/role/add-principals',
);
await visit(urls.addPrincipals);
const scope = await store.findRecord('scope', instances.scopes.global.id);
route.scope = [scope];
test('filters returns expected entries', function (assert) {
controller.set('model', model);
assert.deepEqual(route.scope, [scope]);
controller.callClearAllFilters();
assert.deepEqual(route.scope, []);
assert.ok(controller.filters.allFilters);
assert.ok(controller.filters.selectedFilters);
});
},
);
@@ -32,6 +32,10 @@ module('Unit | Controller | scopes/scope/workers/index', function (hooks) {
workers: null,
};
const model = {
tags: [{ key: 'env', value: 'os', type: 'config' }],
};
hooks.beforeEach(async function () {
await authenticateSession({});
intl = this.owner.lookup('service:intl');
@@ -85,31 +89,20 @@ module('Unit | Controller | scopes/scope/workers/index', function (hooks) {
assert.strictEqual(getWorkerCount(), workerCount - 1);
});
test('callFilterBy action adds expected property values to route', async function (assert) {
const route = this.owner.lookup('route:scopes/scope/workers/index');
await visit(urls.workers);
test('applyFilter action sets expected values correctly', async function (assert) {
controller.set('model', model);
const tag = { key: 'type', value: 'dev', type: 'config' };
// Encode the tag to base64
const encodedTag = window.btoa(JSON.stringify(tag));
controller.applyFilter('tags', [encodedTag]);
assert.notOk(route.tags);
controller.callFilterBy('tags', [tag]);
assert.deepEqual(route.tags, [tag]);
assert.deepEqual(controller.tags, [encodedTag]);
});
test('callClearAllFilters action removes all filter values from route', async function (assert) {
const route = this.owner.lookup('route:scopes/scope/workers/index');
await visit(urls.workers);
const tag = { key: 'type', value: 'dev', type: 'config' };
controller.callFilterBy('tags', [tag]);
assert.deepEqual(route.tags, [
{ key: 'type', value: 'dev', type: 'config' },
]);
controller.callClearAllFilters();
assert.deepEqual(route.tags, []);
test('filters returns expected entries', function (assert) {
controller.set('model', model.tags);
assert.ok(controller.filters.allFilters);
assert.ok(controller.filters.selectedFilters);
});
test('messageDescription returns correct translation with list authorization', async function (assert) {
@@ -5,13 +5,12 @@
import Controller from '@ember/controller';
import { service } from '@ember/service';
import { action } from '@ember/object';
export default class ScopesScopeAuthenticateController extends Controller {
// =services
@service clusterUrl;
@service router;
// =attributes
/**
@@ -25,6 +24,13 @@ export default class ScopesScopeAuthenticateController extends Controller {
];
}
// =actions
@action
selectScope(scope, callback) {
this.router.transitionTo('scopes.scope.authenticate', scope);
callback();
}
/**
* Checks if the current route is the OIDC method authentication route.
* @type {boolean}
+12 -13
View File
@@ -7,22 +7,21 @@
{{#if this.session.isAuthenticated}}
<EmberWormhole @to='header-nav'>
<Rose::Dropdown
@text={{this.scopes.selectedOrg.displayName}}
@icon={{if this.scopes.selectedOrg.isGlobal 'globe' 'org'}}
as |dropdown|
>
{{!-- {{#if this.session.data.authenticated.isGlobal}} --}}
<dropdown.link @route='scopes.scope' @model='global'>
<Hds::Dropdown @enableCollisionDetection={{true}} as |dd|>
<dd.ToggleButton
@text={{this.scopes.selectedOrg.displayName}}
@icon={{if this.scopes.selectedOrg.isGlobal 'globe' 'org'}}
@color='secondary'
/>
<dd.Interactive @route='scopes.scope' @model='global'>
{{t 'titles.global'}}
</dropdown.link>
<dropdown.separator />
{{!-- {{/if}} --}}
</dd.Interactive>
<dd.Separator />
{{#each this.scopes.orgs as |scope|}}
<dropdown.link @route='scopes.scope' @model={{scope.id}}>
<dd.Interactive @route='scopes.scope' @model={{scope.id}}>
{{scope.displayName}}
</dropdown.link>
</dd.Interactive>
{{/each}}
</Rose::Dropdown>
</Hds::Dropdown>
</EmberWormhole>
{{/if}}
@@ -1,22 +0,0 @@
{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: BUSL-1.1
}}
<Rose::Dropdown
@text={{this.scopes.selectedOrg.displayName}}
@icon={{if this.scopes.selectedOrg.isGlobal 'globe' 'org'}}
as |dropdown|
>
{{!-- {{#if this.session.data.authenticated.isGlobal}} --}}
<dropdown.link @route='scopes.scope' @model='global'>
{{t 'titles.global'}}
</dropdown.link>
<dropdown.separator />
{{!-- {{/if}} --}}
{{#each this.scopes.orgs as |scope|}}
<dropdown.link @route='scopes.scope' @model={{scope.id}}>
{{scope.displayName}}
</dropdown.link>
{{/each}}
</Rose::Dropdown>
@@ -17,20 +17,23 @@
}}
>
<Rose::Dropdown
@text={{t 'actions.choose-different-org'}}
@icon='org'
as |dropdown|
>
<dropdown.link @route='scopes.scope.authenticate' @model='global'>
<Hds::Dropdown @listPosition='bottom-left' as |dd|>
<dd.ToggleButton
@text={{t 'actions.choose-different-org'}}
@icon='org'
@color='secondary'
/>
<dd.Interactive {{on 'click' (fn this.selectScope 'global' dd.close)}}>
{{t 'titles.global'}}
</dropdown.link>
</dd.Interactive>
{{#each this.sortedScopes as |scope|}}
<dropdown.link @route='scopes.scope.authenticate' @model={{scope.id}}>
<dd.Interactive
{{on 'click' (fn this.selectScope scope.id dd.close)}}
>
{{scope.displayName}}
</dropdown.link>
</dd.Interactive>
{{/each}}
</Rose::Dropdown>
</Hds::Dropdown>
<Rose::Nav::Tabs as |nav|>
{{#each @model.authMethods as |authMethod|}}
@@ -217,9 +217,9 @@ module('Acceptance | authentication', function (hooks) {
test('org scopes with no auth methods are not visible in dropdown', async function (assert) {
await visit(urls.authenticate.methods.global);
await click('.rose-dropdown-trigger');
await click('.hds-dropdown-toggle-button');
assert.dom('.rose-dropdown-content a').exists({ count: 2 });
assert.dom('.hds-dropdown-list-item button').exists({ count: 2 });
});
test('change cluster url is visible when no auth methods are available', async function (assert) {
@@ -399,7 +399,8 @@ module('Acceptance | projects | sessions | index', function (hooks) {
.isVisible();
// change scope in app header
await click('.rose-header-nav .rose-dropdown a:nth-of-type(3)');
await click('.rose-header-nav .hds-dropdown-toggle-button');
await click('.rose-header-nav .hds-dropdown-list-item:nth-of-type(4) a');
// navigate to back sessions
await click(`[href="${urls.sessions2}"]`);
@@ -467,7 +467,9 @@ module('Acceptance | projects | targets | index', function (hooks) {
.dom(`[data-test-target-project-id="${instances.scopes.project2.id}"]`)
.exists();
await click('.rose-header-nav .rose-dropdown a:nth-of-type(2)');
await click('.rose-header-nav .hds-dropdown-toggle-button');
await click('.rose-header-nav .hds-dropdown-list-item:nth-of-type(3) a');
assert
.dom(`[data-test-target-project-id="${instances.scopes.project.id}"]`)
.exists();
+7 -3
View File
@@ -228,13 +228,17 @@ module('Acceptance | scopes', function (hooks) {
);
await visit(urls.targets);
await click('.rose-header-nav .rose-dropdown a:nth-of-type(2)');
await click('.rose-header-nav .hds-dropdown-toggle-button');
await click('.rose-header-nav .hds-dropdown-list-item:nth-of-type(3) a');
assert.strictEqual(currentURL(), urls.targets);
await click('.rose-header-nav .rose-dropdown a:nth-of-type(3)');
await click('.rose-header-nav .hds-dropdown-list-item:nth-of-type(4) a');
assert.strictEqual(currentURL(), urls.org2Targets);
await click('.rose-header-nav .rose-dropdown a:nth-of-type(1)');
await click('.rose-header-nav .hds-dropdown-list-item:nth-of-type(1) a');
assert.strictEqual(currentURL(), urls.globalTargets);
});