-
Notifications
You must be signed in to change notification settings - Fork 33
Grant actions card #3246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cameronperera
wants to merge
25
commits into
llb/grants-builder
Choose a base branch
from
grant-actions-card
base: llb/grants-builder
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Grant actions card #3246
Changes from 20 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
36bf61b
chore: 🤖 Add initial page layout for code editor + sidebar (#3180)
lisbet-alvarez 7343f99
Replace `Rose::CodeEditor` with `Hds::CodeEditor` (#2679)
zamoore 4beaa6d
feat: 🎸 Create string formats component (#3191)
lisbet-alvarez 28fa5fd
feat: 🎸 add grant schema to mirage (#3196)
cameronperera 89ec9df
feat: 🎸 add export options flyout (#3198)
lisbet-alvarez 3df2e64
feat: 🎸 Add autocompletion to code editor (#3207)
ZedLi aafa312
feat: 🎸 create grant actions component
cameronperera 54478ab
feat: 🎸 add description to actions
cameronperera 806a723
feat: 🎸 update default logic to not show all actions
cameronperera 581c37a
feat: 🎸 show invalid id and type message
cameronperera e92af6d
test: 💍 create const for test selectors
cameronperera 85eb53b
feat: 🎸 trigger action suggestion when cursor moves
cameronperera 6507e86
refactor: 💡 add createGrantLineHelpers func
cameronperera f1cbb62
refactor: 💡 small refactors
cameronperera 237f03c
feat: 🎸 Add CSP nonce to code editors (#3230)
bgajjala8 e6ef513
refactor: 💡 small refactor
cameronperera 5a9211e
test: 💍 add more tests
cameronperera f3ee680
Merge branch 'llb/grants-builder' into grant-actions-card
cameronperera e14c553
Merge branch 'llb/grants-builder' into grant-actions-card
cameronperera 934e767
refactor: 💡 fix merge conflicts issues
cameronperera 591f262
refactor: 💡 updates from PR feedback
cameronperera 41f2eaa
Merge branch 'llb/grants-builder' into grant-actions-card
cameronperera 437b771
refactor: 💡 updates for completions and linting
cameronperera 9708243
test: 💍 fix test issue with translations
cameronperera 2b4f182
test: 💍 fix test issue that was already fixed once
cameronperera File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
cameronperera marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| {{! | ||
| Copyright IBM Corp. 2021, 2026 | ||
| SPDX-License-Identifier: BUSL-1.1 | ||
| }} | ||
|
|
||
| {{#if this.actionRows.length}} | ||
| <Hds::Table | ||
| @model={{this.actionRows}} | ||
| @columns={{array | ||
| (hash label=(t 'titles.action')) | ||
| (hash label=(t 'form.description.label')) | ||
| }} | ||
| @valign='middle' | ||
| data-test-grant-actions-table | ||
| > | ||
| <:body as |B|> | ||
| <B.Tr> | ||
| <B.Td>{{B.data.name}}</B.Td> | ||
| <B.Td>{{B.data.description}}</B.Td> | ||
| </B.Tr> | ||
| </:body> | ||
| </Hds::Table> | ||
| {{else if this.showInvalidIdAndType}} | ||
| <Hds::Alert @type='compact' as |A|> | ||
| <A.Description data-test-grant-actions-invalid-id-or-type> | ||
| {{t 'resources.role.edit-grants.actions.invalid-id-or-type'}} | ||
| </A.Description> | ||
| </Hds::Alert> | ||
| {{else if this.showNoResourceTypeDetected}} | ||
| <Hds::Alert @type='compact' as |A|> | ||
| <A.Description data-test-grant-actions-no-type-detected> | ||
| {{t 'resources.role.edit-grants.actions.no-type-detected'}} | ||
| </A.Description> | ||
| </Hds::Alert> | ||
| {{else}} | ||
| <Hds::Alert @type='compact' as |A|> | ||
| <A.Description data-test-grant-actions-empty-state> | ||
| {{t 'resources.role.edit-grants.no-suggestions'}} | ||
| </A.Description> | ||
| </Hds::Alert> | ||
| {{/if}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| /** | ||
| * Copyright IBM Corp. 2021, 2026 | ||
| * SPDX-License-Identifier: BUSL-1.1 | ||
| */ | ||
|
|
||
| import Component from '@glimmer/component'; | ||
| import { service } from '@ember/service'; | ||
|
|
||
| import { | ||
| createGrantLineHelpers, | ||
| getCompatibleResourceTypeForIds, | ||
| normalizeGrantsSchema, | ||
| parseGrantLine, | ||
| } from 'admin/utils/grant-completions'; | ||
|
|
||
| const ACTIONS_WITH_RESOURCE_TYPE = new Set([ | ||
|
cameronperera marked this conversation as resolved.
Outdated
|
||
| 'create', | ||
| 'list', | ||
| 'read', | ||
| 'update', | ||
| 'delete', | ||
| 'read:self', | ||
| 'delete:self', | ||
| 'cancel', | ||
| 'cancel:self', | ||
| ]); | ||
|
|
||
| export default class GrantActionsIndex extends Component { | ||
| @service intl; | ||
|
|
||
| #normalizedSchema = normalizeGrantsSchema(this.args.grantsSchema ?? {}); | ||
|
|
||
| #grantLineHelpers = createGrantLineHelpers(this.args.grantsSchema ?? {}); | ||
|
|
||
| get parsedGrantLine() { | ||
| return parseGrantLine(this.args.grantString); | ||
|
cameronperera marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| get hasSpecificIds() { | ||
| return ( | ||
| this.parsedGrantLine.idsValue && | ||
| !this.parsedGrantLine.idsValue.includes('*') | ||
| ); | ||
| } | ||
|
|
||
| get hasExplicitType() { | ||
| return ( | ||
| this.parsedGrantLine.typeValue && this.parsedGrantLine.typeValue !== '*' | ||
| ); | ||
| } | ||
|
|
||
| get hasTemplateIds() { | ||
| if (!this.hasSpecificIds) { | ||
| return false; | ||
| } | ||
|
|
||
| return this.parsedGrantLine.idsValue | ||
| .split(',') | ||
| .filter(Boolean) | ||
| .some((id) => id.startsWith('{{') && id.endsWith('}}')); | ||
| } | ||
|
|
||
| get compatibleIdsResourceType() { | ||
| if (!this.hasSpecificIds || this.hasTemplateIds) { | ||
|
cameronperera marked this conversation as resolved.
Outdated
|
||
| return null; | ||
| } | ||
|
|
||
| return getCompatibleResourceTypeForIds( | ||
| this.#normalizedSchema, | ||
| this.parsedGrantLine.idsValue, | ||
| ); | ||
| } | ||
|
|
||
| get hasInvalidType() { | ||
| return ( | ||
| this.hasExplicitType && | ||
| !this.#normalizedSchema.resourcesByType[this.parsedGrantLine.typeValue] | ||
| ); | ||
| } | ||
|
|
||
| get hasInvalidIds() { | ||
| return ( | ||
| this.hasSpecificIds && | ||
|
cameronperera marked this conversation as resolved.
Outdated
|
||
| !this.hasTemplateIds && | ||
| !this.compatibleIdsResourceType | ||
| ); | ||
| } | ||
|
|
||
| get hasInvalidPinnedIdTypeCombination() { | ||
| if ( | ||
| !this.hasSpecificIds || | ||
| !this.hasExplicitType || | ||
| this.hasInvalidIds || | ||
| this.hasInvalidType | ||
| ) { | ||
| return false; | ||
| } | ||
|
|
||
| const childTypes = | ||
| this.#normalizedSchema.childResourceTypesByParentType[ | ||
| this.compatibleIdsResourceType | ||
| ] ?? []; | ||
|
|
||
| return !childTypes.includes(this.parsedGrantLine.typeValue); | ||
| } | ||
|
|
||
| get actions() { | ||
| if (!this.parsedGrantLine.idsValue && !this.parsedGrantLine.typeValue) { | ||
| return []; | ||
| } | ||
|
|
||
| return this.#grantLineHelpers | ||
| .getSuggestedActions(this.args.grantString) | ||
| .filter((action) => action !== '*') | ||
| .sort((left, right) => left.localeCompare(right)); | ||
| } | ||
|
|
||
| get descriptionResourceType() { | ||
| if (this.parsedGrantLine.typeValue === '*') { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| this.parsedGrantLine.typeValue || | ||
| this.#grantLineHelpers.getDetectedResourceType(this.args.grantString) | ||
|
cameronperera marked this conversation as resolved.
Outdated
|
||
| ); | ||
| } | ||
|
|
||
| get actionRows() { | ||
| return this.actions.map((action) => ({ | ||
| name: action, | ||
| description: this.getActionDescription(action), | ||
| })); | ||
| } | ||
|
|
||
| get showNoResourceTypeDetected() { | ||
| return ( | ||
| !this.showInvalidIdAndType && | ||
| !this.actions.length && | ||
| !this.#grantLineHelpers.getDetectedResourceType(this.args.grantString) | ||
| ); | ||
| } | ||
|
|
||
| get showInvalidIdAndType() { | ||
| return ( | ||
| !this.actions.length && | ||
| (this.hasInvalidType || | ||
| this.hasInvalidIds || | ||
| this.hasInvalidPinnedIdTypeCombination) | ||
| ); | ||
| } | ||
|
|
||
| getActionDescription(action) { | ||
| const translationKey = `resources.role.edit-grants.actions.${action}`; | ||
|
|
||
| if (!this.intl.exists(translationKey)) { | ||
| return action; | ||
| } | ||
|
|
||
| if (ACTIONS_WITH_RESOURCE_TYPE.has(action)) { | ||
| if (!this.descriptionResourceType) { | ||
| return action; | ||
| } | ||
|
|
||
| return this.intl.t(translationKey, { | ||
| resourceType: this.descriptionResourceType, | ||
| }); | ||
| } | ||
|
|
||
| return this.intl.t(translationKey); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.