Files
threshold-ui/ui/admin/app/templates/scopes/scope/auth-methods/index.hbs
T
ded8bdadd1 Icu 12592 add filtering pagination support for auth methods (#2209)
* feat: 🎸 add filtering & pagination to auth methods

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12592

---------

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2024-04-12 14:55:34 -04:00

213 lines
7.0 KiB
Handlebars

{{!
Copyright (c) HashiCorp, Inc.
SPDX-License-Identifier: MPL-2.0
}}
<Rose::Layout::Page as |page|>
<page.header>
<h2>
{{t 'resources.auth-method.title_plural'}}
<DocLink @doc='auth-method' @iconSize='large' />
</h2>
<p>{{t 'resources.auth-method.description'}}</p>
</page.header>
<page.breadcrumbs>
<Breadcrumbs::Container />
</page.breadcrumbs>
<page.actions>
{{#if (can 'create model' this.scopeModel collection='auth-methods')}}
<Hds::Dropdown data-test-new-dropdown as |dd|>
<dd.ToggleButton @text={{t 'titles.new'}} @color='secondary' />
<dd.Interactive
@text={{t 'resources.auth-method.types.password'}}
@route='scopes.scope.auth-methods.new'
@query={{hash type='password'}}
/>
<dd.Interactive
@text={{t 'resources.auth-method.types.oidc'}}
@route='scopes.scope.auth-methods.new'
@query={{hash type='oidc'}}
/>
{{#if (feature-flag 'ldap-auth-methods')}}
<dd.Interactive
@text={{t 'resources.auth-method.types.ldap'}}
@route='scopes.scope.auth-methods.new'
@query={{hash type='ldap'}}
/>
{{/if}}
</Hds::Dropdown>
{{/if}}
</page.actions>
<page.body class='search-filtering'>
{{#if @model.authMethodsExist}}
{{#unless this.hasPrimaryAuthMethod}}
<Hds::Alert
class='auth-methods-list-alert'
@type='inline'
@color='warning'
as |A|
>
<A.Title>
{{t 'resources.auth-method.messages.no-primary-auth-method.title'}}
</A.Title>
<A.Description>
{{t
'resources.auth-method.messages.no-primary-auth-method.description'
}}
</A.Description>
</Hds::Alert>
{{/unless}}
<Hds::SegmentedGroup as |S|>
<S.TextInput
@value={{this.search}}
@type='search'
placeholder={{t 'actions.search'}}
aria-label={{t 'actions.search'}}
{{on 'input' this.handleSearchInput}}
/>
<S.Generic>
<Dropdown
name='type'
@toggleText={{t 'form.type.label'}}
@itemOptions={{this.authMethodTypeOptions}}
@checkedItems={{this.types}}
@applyFilter={{fn this.applyFilter 'types'}}
/>
</S.Generic>
<S.Generic>
<Dropdown
name='primary'
@toggleText={{t 'resources.auth-method.titles.primary'}}
@itemOptions={{this.primaryOptions}}
@checkedItems={{this.primary}}
@applyFilter={{fn this.applyFilter 'primary'}}
/>
</S.Generic>
</Hds::SegmentedGroup>
<FilterTags @filters={{this.filters}} />
{{#if @model.authMethods}}
<Hds::Table
class='auth-methods-list-table'
@model={{@model.authMethods}}
@columns={{array
(hash label=(t 'form.name.label'))
(hash label=(t 'form.type.label'))
(hash label=(t 'form.id.label'))
(hash label='')
(hash label=(t 'titles.actions'))
}}
@density='short'
@valign='middle'
>
<:body as |B|>
<B.Tr data-test-auth-methods-table-row={{B.data.id}}>
<B.Td>
{{#if (can 'read auth-method' B.data)}}
<LinkTo
@route='scopes.scope.auth-methods.auth-method'
@model={{B.data.id}}
>
{{B.data.displayName}}
</LinkTo>
{{else}}
{{B.data.displayName}}
{{/if}}
<p>{{B.data.description}}</p>
</B.Td>
<B.Td>
<Hds::Badge
@text={{t
(concat 'resources.auth-method.types.' B.data.type)
}}
/>
</B.Td>
<B.Td>
<Hds::Copy::Snippet
@textToCopy={{B.data.id}}
@color='secondary'
/>
</B.Td>
<B.Td>
{{#if B.data.isPrimary}}
<Hds::Badge @text={{t 'states.primary'}} @color='success' />
{{/if}}
</B.Td>
<B.Td>
{{#if (can 'makePrimary auth-method' B.data)}}
<Hds::Dropdown as |dd|>
<dd.ToggleIcon
@icon='more-horizontal'
@text={{t 'actions.manage'}}
@hasChevron={{false}}
/>
{{#unless B.data.isPrimary}}
<dd.Interactive
@text={{t 'resources.auth-method.actions.make-primary'}}
data-test-make-primary-action
{{on 'click' (route-action 'makePrimary' B.data)}}
/>
{{/unless}}
{{#if B.data.isPrimary}}
<dd.Interactive
@text={{t
'resources.auth-method.actions.remove-as-primary'
}}
{{on 'click' (route-action 'removeAsPrimary' B.data)}}
/>
{{/if}}
</Hds::Dropdown>
{{/if}}
</B.Td>
</B.Tr>
</:body>
</Hds::Table>
<Rose::Pagination
@totalItems={{@model.totalItems}}
@currentPage={{this.page}}
@currentPageSize={{this.pageSize}}
/>
{{else}}
<Hds::ApplicationState data-test-no-auth-method-results as |A|>
<A.Header @title={{t 'titles.no-results-found'}} />
<A.Body
@text={{t
(if
this.search
'descriptions.no-search-results'
'descriptions.no-filter-results'
)
query=this.search
resource=(t 'resources.auth-method.title_plural')
}}
/>
</Hds::ApplicationState>
{{/if}}
{{else}}
<Hds::ApplicationState as |A|>
<A.Header @title={{t 'resources.auth-method.messages.welcome.title'}} />
<A.Body
{{! can list (at least): show default welcome message}}
{{! can create (only): show create-but-not-list welcome message}}
{{! can neither list nor create: show neither-list-nor-create welcome message}}
@text={{t
(if
(can 'list model' this.scopeModel collection='auth-methods')
'resources.auth-method.description'
(if
(can 'create model' this.scopeModel collection='auth-methods')
'descriptions.create-but-not-list'
'descriptions.neither-list-nor-create'
)
)
resource=(t 'resources.auth-method.title_plural')
}}
/>
</Hds::ApplicationState>
{{/if}}
</page.body>
</Rose::Layout::Page>