refactor: 💡 Update string formats to use select + add options (#3256)

* refactor: 💡 Update string formats to use select + add options

* refactor: 💡 PR feedback

* test: 💍 fix tests

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-18983
This commit is contained in:
Lisbet Alvarez authored and Zhihe Li committed 2026-05-14 15:21:29 -04:00
1 parent e5657a8d4c
commit 990146fa34
5 files changed
+170 -97

No files matched your search

+16 -5
View File
@@ -720,22 +720,33 @@ role:
title: Grant Editor
description: Add each new grant string on a different line
string-formats:
title: String format
title_plural: String formats
syntax: Syntax
syntax-format: Syntax format
more-info: More info
resource-type:
label: Singular resource type
help: Applies actions to a specific resource type
help: Applies collection actions to a specific resource type in a single grant.
resource:
label: Specific resource(s)
help: Applies actions to one or more individual resources
help: Applies ID actions to one or more individual resources in a single grant.
pinned-id:
label: Pinned ID
help: '"Pins" actions to a non-top-level type within a specific resource ID. Only available for certain resource types. '
link: More info
help: '"Pins" actions to a non-top-level type within a specific ID in a single grant.'
output-fields:
label: Output fields
help: Defines which fields from a request are returned to the user.
account-template:
label: Account template
help: Substitutes the account ID from the token used to perform the request.
user-template:
label: User template
help: Substitutes the user ID from the token used to perform the request.
insert-actions: insert actions
insert-resource-types: insert resource types
insert-id: insert id
insert-resource-ids: insert resource ids
insert-output-fields: insert output fields
export:
format: Format
formatted-export-aria-label: Formatted export
@@ -3,61 +3,45 @@
SPDX-License-Identifier: BUSL-1.1
}}
<Hds::Form::Radio::Group
@name='string-formats'
{{on 'change' (set-from-event this 'selectedFormatType')}}
as |G|
<Hds::Form::SuperSelect::Single::Field
name='string-formats'
@onChange={{this.changeSelectedFormatType}}
@selected={{this.selectedFormatType}}
@options={{this.stringFormatTypesList}}
as |F|
>
<G.RadioField
@value={{this.stringFormatTypes.resourceType}}
checked={{eq this.selectedFormatType this.stringFormatTypes.resourceType}}
as |F|
>
<F.Label>{{t
'resources.role.edit-grants.string-formats.resource-type.label'
}}</F.Label>
<F.HelperText>{{t
'resources.role.edit-grants.string-formats.resource-type.help'
}}</F.HelperText>
</G.RadioField>
<G.RadioField
@value={{this.stringFormatTypes.resource}}
checked={{eq this.selectedFormatType this.stringFormatTypes.resource}}
as |F|
>
<F.Label>{{t
'resources.role.edit-grants.string-formats.resource.label'
}}</F.Label>
<F.HelperText>{{t
'resources.role.edit-grants.string-formats.resource.help'
}}</F.HelperText>
</G.RadioField>
<G.RadioField
@value={{this.stringFormatTypes.pinnedId}}
checked={{eq this.selectedFormatType this.stringFormatTypes.pinnedId}}
as |F|
>
<F.Label>{{t
'resources.role.edit-grants.string-formats.pinned-id.label'
}}</F.Label>
<F.HelperText>
{{t 'resources.role.edit-grants.string-formats.pinned-id.help'}}
<Hds::Link::Inline
@color='secondary'
@href={{doc-url 'role.grant-string-format.pinned-id'}}
>
{{t 'resources.role.edit-grants.string-formats.pinned-id.link'}}
</Hds::Link::Inline>
</F.HelperText>
</G.RadioField>
</Hds::Form::Radio::Group>
<F.Label>{{t
'resources.role.edit-grants.string-formats.syntax-format'
}}</F.Label>
<F.Options>
{{#let F.options as |formatType|}}
<Hds::Text::Body @tag='p' @weight='semibold'>{{t
(concat
'resources.role.edit-grants.string-formats.' formatType '.label'
)
}}</Hds::Text::Body>
<Hds::Text::Body @tag='p' @color='faint' @size='100'>{{t
(concat
'resources.role.edit-grants.string-formats.' formatType '.help'
)
}}</Hds::Text::Body>
{{/let}}
</F.Options>
</Hds::Form::SuperSelect::Single::Field>
<Hds::Form::Textarea::Field
name='string-format'
readonly
@value={{this.stringFormat}}
@value={{this.stringFormat.text}}
@height='3.5rem'
as |F|
>
<F.Label>{{t 'resources.role.edit-grants.string-formats.title'}}</F.Label>
</Hds::Form::Textarea::Field>
<F.Label>{{t 'resources.role.edit-grants.string-formats.syntax'}}</F.Label>
</Hds::Form::Textarea::Field>
<Hds::Link::Standalone
@icon='docs-link'
@iconPosition='trailing'
@text={{t 'resources.role.edit-grants.string-formats.more-info'}}
@href={{doc-url this.stringFormat.link}}
/>
@@ -6,6 +6,7 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { service } from '@ember/service';
import { action } from '@ember/object';
export default class GrantStringFormatsIndex extends Component {
// =services
@@ -18,15 +19,38 @@ export default class GrantStringFormatsIndex extends Component {
resourceType: 'resource-type',
resource: 'resource',
pinnedId: 'pinned-id',
outputFields: 'output-fields',
accountTemplate: 'account-template',
userTemplate: 'user-template',
};
stringFormatTypesList = Object.values(this.stringFormatTypes);
stringFormats = {
[this.stringFormatTypes.resourceType]:
`type=<${this.intl.t('resources.role.edit-grants.string-formats.insert-resource-types')}>;actions=<${this.intl.t('resources.role.edit-grants.string-formats.insert-actions')}>`,
[this.stringFormatTypes.resource]:
`ids=<${this.intl.t('resources.role.edit-grants.string-formats.insert-resource-ids')}>;actions=<${this.intl.t('resources.role.edit-grants.string-formats.insert-actions')}>`,
[this.stringFormatTypes.pinnedId]:
`ids=<${this.intl.t('resources.role.edit-grants.string-formats.insert-id')}>;type=<${this.intl.t('resources.role.edit-grants.string-formats.insert-resource-types')}>;actions=<${this.intl.t('resources.role.edit-grants.string-formats.insert-actions')}>`,
[this.stringFormatTypes.resourceType]: {
text: `type=<${this.intl.t('resources.role.edit-grants.string-formats.insert-resource-types')}>;actions=<${this.intl.t('resources.role.edit-grants.string-formats.insert-actions')}>`,
link: 'role.grant-string-format.resource-type',
},
[this.stringFormatTypes.resource]: {
text: `ids=<${this.intl.t('resources.role.edit-grants.string-formats.insert-resource-ids')}>;actions=<${this.intl.t('resources.role.edit-grants.string-formats.insert-actions')}>`,
link: 'role.grant-string-format.resource',
},
[this.stringFormatTypes.pinnedId]: {
text: `ids=<${this.intl.t('resources.role.edit-grants.string-formats.insert-id')}>;type=<${this.intl.t('resources.role.edit-grants.string-formats.insert-resource-types')}>;actions=<${this.intl.t('resources.role.edit-grants.string-formats.insert-actions')}>`,
link: 'role.grant-string-format.pinned-id',
},
[this.stringFormatTypes.outputFields]: {
text: `output_fields=<${this.intl.t('resources.role.edit-grants.string-formats.insert-output-fields')}>`,
link: 'role.grant-string-format.output-fields',
},
[this.stringFormatTypes.accountTemplate]: {
text: 'ids={{.Account.Id}}',
link: 'role.grant-string-format.account-template',
},
[this.stringFormatTypes.userTemplate]: {
text: 'ids={{.User.Id}}',
link: 'role.grant-string-format.user-template',
},
};
@tracked selectedFormatType = this.stringFormatTypes.resourceType;
@@ -38,4 +62,11 @@ export default class GrantStringFormatsIndex extends Component {
get stringFormat() {
return this.stringFormats[this.selectedFormatType];
}
// =actions
@action
changeSelectedFormatType(type) {
this.selectedFormatType = type;
}
}
+10
View File
@@ -97,8 +97,18 @@ module.exports = function (environment) {
'role.add-principals':
'/tutorials/oss-administration/oss-manage-roles#create-a-role',
'role.add-grant-scopes': '/docs/commands/roles/add-grant-scopes',
'role.grant-string-format.resource-type':
'/docs/rbac/permission-grant-formats#type-only',
'role.grant-string-format.resource':
'/docs/rbac/permission-grant-formats#id-only',
'role.grant-string-format.pinned-id':
'/docs/rbac/permission-grant-formats#pinned-id',
'role.grant-string-format.output-fields':
'/docs/rbac/assignable-permissions#output-fields',
'role.grant-string-format.account-template':
'/docs/rbac/permission-grant-formats#account-id',
'role.grant-string-format.user-template':
'/docs/rbac/permission-grant-formats#user-id',
session: '/docs/concepts/domain-model/sessions',
target: '/docs/concepts/domain-model/targets',
'target.new': '/docs/common-workflows/manage-targets',
@@ -15,48 +15,85 @@ module(
setupRenderingTest(hooks);
setupIntl(hooks, 'en-us');
const RESOURCE_TYPE_OPTION = '[value="resource-type"]';
const RESOURCE_OPTION = '[value="resource"]';
const PINNED_ID_OPTION = '[value="pinned-id"]';
const STRING_FORMATS_SELECT = '[name="string-formats"]';
const RESOURCE_TYPE_OPTION = '[data-option-index="0"]';
const RESOURCE_OPTION = '[data-option-index="1"]';
const PINNED_ID_OPTION = '[data-option-index="2"]';
const OUTPUT_FIELDS_OPTION = '[data-option-index="3"]';
const ACCOUNT_TEMPLATE_OPTION = '[data-option-index="4"]';
const USER_TEMPLATE_OPTION = '[data-option-index="5"]';
const STRING_FORMAT_FIELD = '[name="string-format"]';
const MORE_INFO_LINK = '.hds-link-standalone';
test('it renders string format with resource type by default', async function (assert) {
await render(hbs`<GrantStringFormats />`);
const options = {
resourceType: RESOURCE_TYPE_OPTION,
resource: RESOURCE_OPTION,
pinnedId: PINNED_ID_OPTION,
outputFields: OUTPUT_FIELDS_OPTION,
accountTemplate: ACCOUNT_TEMPLATE_OPTION,
userTemplate: USER_TEMPLATE_OPTION,
};
assert.dom(RESOURCE_TYPE_OPTION).isChecked();
assert.dom(RESOURCE_OPTION).isNotChecked();
assert.dom(PINNED_ID_OPTION).isNotChecked();
assert
.dom(STRING_FORMAT_FIELD)
.hasValue('type=<insert resource types>;actions=<insert actions>');
});
test.each(
'it renders the expected string format for each option',
[
{
selectedOption: 'resourceType',
expectedValue:
'type=<insert resource types>;actions=<insert actions>',
},
{
optionToClick: RESOURCE_OPTION,
selectedOption: 'resource',
expectedValue: 'ids=<insert resource ids>;actions=<insert actions>',
},
{
optionToClick: PINNED_ID_OPTION,
selectedOption: 'pinnedId',
expectedValue:
'ids=<insert id>;type=<insert resource types>;actions=<insert actions>',
},
{
optionToClick: OUTPUT_FIELDS_OPTION,
selectedOption: 'outputFields',
expectedValue: 'output_fields=<insert output fields>',
},
{
optionToClick: ACCOUNT_TEMPLATE_OPTION,
selectedOption: 'accountTemplate',
expectedValue: 'ids={{.Account.Id}}',
},
{
optionToClick: USER_TEMPLATE_OPTION,
selectedOption: 'userTemplate',
expectedValue: 'ids={{.User.Id}}',
},
],
async function (
assert,
{ optionToClick, selectedOption, expectedValue },
) {
await render(hbs`<GrantStringFormats />`);
test('it renders string format when type is changed to specific resource', async function (assert) {
await render(hbs`<GrantStringFormats />`);
await click(STRING_FORMATS_SELECT);
await click(RESOURCE_OPTION);
if (optionToClick) {
await click(optionToClick);
await click(STRING_FORMATS_SELECT);
}
assert.dom(RESOURCE_OPTION).isChecked();
assert.dom(RESOURCE_TYPE_OPTION).isNotChecked();
assert.dom(PINNED_ID_OPTION).isNotChecked();
assert
.dom(STRING_FORMAT_FIELD)
.hasValue('ids=<insert resource ids>;actions=<insert actions>');
});
for (const [optionName, selector] of Object.entries(options)) {
assert
.dom(selector)
.hasAria(
'selected',
optionName === selectedOption ? 'true' : 'false',
);
}
test('it renders string format when type is changed to pinned id', async function (assert) {
await render(hbs`<GrantStringFormats />`);
await click(PINNED_ID_OPTION);
assert.dom(PINNED_ID_OPTION).isChecked();
assert.dom(RESOURCE_TYPE_OPTION).isNotChecked();
assert.dom(RESOURCE_OPTION).isNotChecked();
assert
.dom(STRING_FORMAT_FIELD)
.hasValue(
'ids=<insert id>;type=<insert resource types>;actions=<insert actions>',
);
});
assert.dom(STRING_FORMAT_FIELD).hasValue(expectedValue);
assert.dom(MORE_INFO_LINK).isVisible();
},
);
},
);