From e222d5b90934a224b8793f95ff88587c039e9ffd Mon Sep 17 00:00:00 2001 From: Dharini Jeeva Date: Thu, 15 May 2025 11:05:05 -0700 Subject: [PATCH] chore: Migrate rose dropdown to HDS (#2826) --- e2e-tests/desktop/tests/scope.spec.js | 9 +- ui/admin/app/components/header-nav/index.hbs | 47 +++++----- .../scopes/scope/groups/group/add-members.js | 48 ++++++---- .../scopes/scope/roles/role/add-principals.js | 48 ++++++---- .../controllers/scopes/scope/workers/index.js | 86 +++++++++++------ .../scopes/scope/groups/group/add-members.js | 44 +++------ .../scopes/scope/roles/role/add-principals.js | 39 ++------ .../app/routes/scopes/scope/workers/index.js | 70 ++++---------- ui/admin/app/styles/app.scss | 31 ++++++- .../templates/scopes/scope/authenticate.hbs | 26 +++--- .../scopes/scope/groups/group/add-members.hbs | 66 ++----------- .../scope/roles/role/add-principals.hbs | 66 ++----------- .../templates/scopes/scope/targets/index.hbs | 1 + .../templates/scopes/scope/workers/index.hbs | 93 +++++++------------ .../tests/acceptance/authentication-test.js | 4 +- .../tests/acceptance/workers/list-test.js | 1 + .../tests/acceptance/workers/selectors.js | 7 +- .../scope/groups/group/add-members-test.js | 36 +++---- .../scope/roles/role/add-principals-test.js | 35 +++---- .../scopes/scope/workers/index-test.js | 35 +++---- .../controllers/scopes/scope/authenticate.js | 10 +- ui/desktop/app/templates/scopes/scope.hbs | 25 +++-- .../templates/scopes/scope/-header-nav.hbs | 22 ----- .../templates/scopes/scope/authenticate.hbs | 23 +++-- .../tests/acceptance/authentication-test.js | 4 +- .../projects/sessions/index-test.js | 3 +- .../acceptance/projects/targets/index-test.js | 4 +- ui/desktop/tests/acceptance/scopes-test.js | 10 +- 28 files changed, 375 insertions(+), 518 deletions(-) delete mode 100644 ui/desktop/app/templates/scopes/scope/-header-nav.hbs diff --git a/e2e-tests/desktop/tests/scope.spec.js b/e2e-tests/desktop/tests/scope.spec.js index 93779cf3f..969e3abd9 100644 --- a/e2e-tests/desktop/tests/scope.spec.js +++ b/e2e-tests/desktop/tests/scope.spec.js @@ -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(); diff --git a/ui/admin/app/components/header-nav/index.hbs b/ui/admin/app/components/header-nav/index.hbs index ed3d99b67..26dd9babf 100644 --- a/ui/admin/app/components/header-nav/index.hbs +++ b/ui/admin/app/components/header-nav/index.hbs @@ -3,38 +3,39 @@ SPDX-License-Identifier: BUSL-1.1 }} - + + {{#if this.session.data.authenticated.isGlobal}} - + {{t 'titles.global'}} - - + {{/if}} {{#each this.scope.orgsList as |org|}} - + {{org.displayName}} - + {{/each}} - + {{#if this.scope.project}} - + + {{#each this.scope.projectsList as |project|}} - + {{project.displayName}} - + {{/each}} - + {{/if}} \ No newline at end of file diff --git a/ui/admin/app/controllers/scopes/scope/groups/group/add-members.js b/ui/admin/app/controllers/scopes/scope/groups/group/add-members.js index f1e3519c4..e492d5eff 100644 --- a/ui/admin/app/controllers/scopes/scope/groups/group/add-members.js +++ b/ui/admin/app/controllers/scopes/scope/groups/group/add-members.js @@ -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'); - } } diff --git a/ui/admin/app/controllers/scopes/scope/roles/role/add-principals.js b/ui/admin/app/controllers/scopes/scope/roles/role/add-principals.js index 982c506fd..85c0b3ac9 100644 --- a/ui/admin/app/controllers/scopes/scope/roles/role/add-principals.js +++ b/ui/admin/app/controllers/scopes/scope/roles/role/add-principals.js @@ -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'); - } } diff --git a/ui/admin/app/controllers/scopes/scope/workers/index.js b/ui/admin/app/controllers/scopes/scope/workers/index.js index 0540082f6..4a58bc297 100644 --- a/ui/admin/app/controllers/scopes/scope/workers/index.js +++ b/ui/admin/app/controllers/scopes/scope/workers/index.js @@ -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. */ diff --git a/ui/admin/app/routes/scopes/scope/groups/group/add-members.js b/ui/admin/app/routes/scopes/scope/groups/group/add-members.js index 228d3b9d7..60f65752f 100644 --- a/ui/admin/app/routes/scopes/scope/groups/group/add-members.js +++ b/ui/admin/app/routes/scopes/scope/groups/group/add-members.js @@ -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 = []; - } } diff --git a/ui/admin/app/routes/scopes/scope/roles/role/add-principals.js b/ui/admin/app/routes/scopes/scope/roles/role/add-principals.js index 5442ea20f..9f62a0cb0 100644 --- a/ui/admin/app/routes/scopes/scope/roles/role/add-principals.js +++ b/ui/admin/app/routes/scopes/scope/roles/role/add-principals.js @@ -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 = []; - } } diff --git a/ui/admin/app/routes/scopes/scope/workers/index.js b/ui/admin/app/routes/scopes/scope/workers/index.js index 3a253cf5f..67ec3fddc 100644 --- a/ui/admin/app/routes/scopes/scope/workers/index.js +++ b/ui/admin/app/routes/scopes/scope/workers/index.js @@ -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); diff --git a/ui/admin/app/styles/app.scss b/ui/admin/app/styles/app.scss index 9ee0f5fe3..e69ed09f4 100644 --- a/ui/admin/app/styles/app.scss +++ b/ui/admin/app/styles/app.scss @@ -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; +} diff --git a/ui/admin/app/templates/scopes/scope/authenticate.hbs b/ui/admin/app/templates/scopes/scope/authenticate.hbs index 27ef3f5df..482d5519e 100644 --- a/ui/admin/app/templates/scopes/scope/authenticate.hbs +++ b/ui/admin/app/templates/scopes/scope/authenticate.hbs @@ -29,25 +29,27 @@ name=@model.scope.displayName }} - - + + + {{t 'titles.global'}} - - + {{#each this.sortedScopes as |scope|}} - {{scope.displayName}} - - + {{/each}} - + diff --git a/ui/admin/app/templates/scopes/scope/groups/group/add-members.hbs b/ui/admin/app/templates/scopes/scope/groups/group/add-members.hbs index 5806a3626..0c5c42498 100644 --- a/ui/admin/app/templates/scopes/scope/groups/group/add-members.hbs +++ b/ui/admin/app/templates/scopes/scope/groups/group/add-members.hbs @@ -32,62 +32,16 @@ - {{#let - (resource-filter 'scopes.scope.groups.group.add-members' 'scope') - as |filter| - }} - - - - -
    - -
  • - - - -
  • -
    -
-
- - {{#if - (has-resource-filter-selections - 'scopes.scope.groups.group.add-members' 'scope' - ) - }} - - {{/if}} -
-
-
- {{/let}} - + +
- {{#let - (resource-filter 'scopes.scope.roles.role.add-principals' 'scope') - as |filter| - }} - - - - -
    - -
  • - - - -
  • -
    -
-
- - {{#if - (has-resource-filter-selections - 'scopes.scope.roles.role.add-principals' 'scope' - ) - }} - - {{/if}} -
-
-
- {{/let}} - + +
{{/if}} + {{#if @model.targets}} diff --git a/ui/admin/app/templates/scopes/scope/workers/index.hbs b/ui/admin/app/templates/scopes/scope/workers/index.hbs index 02d6a57e2..9539eddbc 100644 --- a/ui/admin/app/templates/scopes/scope/workers/index.hbs +++ b/ui/admin/app/templates/scopes/scope/workers/index.hbs @@ -34,67 +34,44 @@ {{#if @model}} - - - - {{#let - (resource-filter 'scopes.scope.workers.index' 'tags') - as |filter| - }} - {{#if filter.allowedValues}} - - {{#each-in - (group-by 'key' filter.allowedValues) - as |key tags| - }} - - - - - - - {{/each-in}} - - {{/if}} - {{/let}} - {{#if - (has-resource-filter-selections - 'scopes.scope.workers.index' 'tags' - ) - }} - - {{/if}} - - - - - - - +
+ + {{#each-in (group-by 'key' itemOptions) as |key groupItems|}} + + + {{key}} + + {{#each groupItems as |item|}} + + {{item.name}} + + {{/each}} + {{/each-in}} + + +
+ `[data-test-worker-tags-flyout-button="${workerId}"]`; diff --git a/ui/admin/tests/unit/controllers/scopes/scope/groups/group/add-members-test.js b/ui/admin/tests/unit/controllers/scopes/scope/groups/group/add-members-test.js index 0784b5ec4..f19225749 100644 --- a/ui/admin/tests/unit/controllers/scopes/scope/groups/group/add-members-test.js +++ b/ui/admin/tests/unit/controllers/scopes/scope/groups/group/add-members-test.js @@ -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); }); }, ); diff --git a/ui/admin/tests/unit/controllers/scopes/scope/roles/role/add-principals-test.js b/ui/admin/tests/unit/controllers/scopes/scope/roles/role/add-principals-test.js index 2e7c23619..f17cb23bf 100644 --- a/ui/admin/tests/unit/controllers/scopes/scope/roles/role/add-principals-test.js +++ b/ui/admin/tests/unit/controllers/scopes/scope/roles/role/add-principals-test.js @@ -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); }); }, ); diff --git a/ui/admin/tests/unit/controllers/scopes/scope/workers/index-test.js b/ui/admin/tests/unit/controllers/scopes/scope/workers/index-test.js index 8c445a160..958e57e4c 100644 --- a/ui/admin/tests/unit/controllers/scopes/scope/workers/index-test.js +++ b/ui/admin/tests/unit/controllers/scopes/scope/workers/index-test.js @@ -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) { diff --git a/ui/desktop/app/controllers/scopes/scope/authenticate.js b/ui/desktop/app/controllers/scopes/scope/authenticate.js index 9f437e7ac..db8caf354 100644 --- a/ui/desktop/app/controllers/scopes/scope/authenticate.js +++ b/ui/desktop/app/controllers/scopes/scope/authenticate.js @@ -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} diff --git a/ui/desktop/app/templates/scopes/scope.hbs b/ui/desktop/app/templates/scopes/scope.hbs index 378a038ce..b2a570455 100644 --- a/ui/desktop/app/templates/scopes/scope.hbs +++ b/ui/desktop/app/templates/scopes/scope.hbs @@ -7,22 +7,21 @@ {{#if this.session.isAuthenticated}} - - {{!-- {{#if this.session.data.authenticated.isGlobal}} --}} - + + + {{t 'titles.global'}} - - - {{!-- {{/if}} --}} + + {{#each this.scopes.orgs as |scope|}} - + {{scope.displayName}} - + {{/each}} - + {{/if}} \ No newline at end of file diff --git a/ui/desktop/app/templates/scopes/scope/-header-nav.hbs b/ui/desktop/app/templates/scopes/scope/-header-nav.hbs deleted file mode 100644 index 92cbbcfc5..000000000 --- a/ui/desktop/app/templates/scopes/scope/-header-nav.hbs +++ /dev/null @@ -1,22 +0,0 @@ -{{! - Copyright (c) HashiCorp, Inc. - SPDX-License-Identifier: BUSL-1.1 -}} - - - {{!-- {{#if this.session.data.authenticated.isGlobal}} --}} - - {{t 'titles.global'}} - - - {{!-- {{/if}} --}} - {{#each this.scopes.orgs as |scope|}} - - {{scope.displayName}} - - {{/each}} - \ No newline at end of file diff --git a/ui/desktop/app/templates/scopes/scope/authenticate.hbs b/ui/desktop/app/templates/scopes/scope/authenticate.hbs index c3b017c4d..53273be88 100644 --- a/ui/desktop/app/templates/scopes/scope/authenticate.hbs +++ b/ui/desktop/app/templates/scopes/scope/authenticate.hbs @@ -17,20 +17,23 @@ }} > - - + + + {{t 'titles.global'}} - + {{#each this.sortedScopes as |scope|}} - + {{scope.displayName}} - + {{/each}} - + {{#each @model.authMethods as |authMethod|}} diff --git a/ui/desktop/tests/acceptance/authentication-test.js b/ui/desktop/tests/acceptance/authentication-test.js index 3f175756a..f9f453e6b 100644 --- a/ui/desktop/tests/acceptance/authentication-test.js +++ b/ui/desktop/tests/acceptance/authentication-test.js @@ -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) { diff --git a/ui/desktop/tests/acceptance/projects/sessions/index-test.js b/ui/desktop/tests/acceptance/projects/sessions/index-test.js index 91bc008d6..4d9bb439c 100644 --- a/ui/desktop/tests/acceptance/projects/sessions/index-test.js +++ b/ui/desktop/tests/acceptance/projects/sessions/index-test.js @@ -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}"]`); diff --git a/ui/desktop/tests/acceptance/projects/targets/index-test.js b/ui/desktop/tests/acceptance/projects/targets/index-test.js index ac9f006ba..6c4ca1f6a 100644 --- a/ui/desktop/tests/acceptance/projects/targets/index-test.js +++ b/ui/desktop/tests/acceptance/projects/targets/index-test.js @@ -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(); diff --git a/ui/desktop/tests/acceptance/scopes-test.js b/ui/desktop/tests/acceptance/scopes-test.js index 0b7b67f42..caef320fd 100644 --- a/ui/desktop/tests/acceptance/scopes-test.js +++ b/ui/desktop/tests/acceptance/scopes-test.js @@ -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); });