Grant actions card (#3246)
* chore: 🤖 Add initial page layout for code editor + sidebar (#3180) * chore: 🤖 Add initial page layout for code editor + sidebar * test: 💍 add missing a11y ignores for exisitng color issue ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-18460 * Replace `Rose::CodeEditor` with `Hds::CodeEditor` (#2679) * chore: 🤖 replace Rose::CodeEditor with Hds::CodeEditor - Remove CodeEditor 5 dependency * chore: 🤖 Replace CodeMirror5 dep remove CodeMirror5 and replace existing editors with HDS::CodeEditor * chore: 🤖 deleting old codeeditor styles * feat: 🎸 changing code editor changing code editor ✅ Closes: 0 * removed unused export * pr cleanup * updating tests for new code editor * responding to PR feedback * added whitespace * fixing linting violations * chore: 🤖 self-review PR self-review PR in the course of switching to new HDS code editor * fix: 🐛 fix linting bug * fix: 🐛 unneeded dependency remove jslint dependency as this is handled in the new code editor from HDS * fix: 🐛 Fixing import bug Fix import bug caused by importing scss modules that no longer exist * Fix and refactor code editor acceptance test * Fix and refactor code editor acceptance test * chore: 🤖 remove codemirror dependency * refactor: 💡 fix merge conflict issues * test: 💍 update e2e test selectors * test: 💍 fix target spec click event * refactor: 💡 clean up test selectors for code editor * refactor: 💡 clean up storage bucket test selectors * chore: 🤖 remove code mirror modifiers --------- Co-authored-by: calcaide <ccorvo@hashicorp.com> Co-authored-by: cameronperera <cameron.perera@hashicorp.com> * feat: 🎸 Create string formats component (#3191) * feat: 🎸 Create string formats component * Add missing copyright headers * fix: 🐛 change to readonly ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-18458 * feat: 🎸 add grant schema to mirage (#3196) * feat: 🎸 add grant schema to mirage * refactor: 💡 update grant schema mirage data * refactor: 💡 fix route name in mirage * feat: 🎸 add export options flyout (#3198) * feat: 🎸 add export options flyout * fix: 🐛 update id to be ids * test: 💍 add a11y ignores * test: 💍 fix tests for grant string format ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-18524 * feat: 🎸 Add autocompletion to code editor (#3207) * feat: 🎸 create grant actions component * feat: 🎸 add description to actions * feat: 🎸 update default logic to not show all actions * feat: 🎸 show invalid id and type message * test: 💍 create const for test selectors * feat: 🎸 trigger action suggestion when cursor moves * refactor: 💡 add createGrantLineHelpers func * refactor: 💡 small refactors * feat: 🎸 Add CSP nonce to code editors (#3230) Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * refactor: 💡 small refactor * test: 💍 add more tests * refactor: 💡 fix merge conflicts issues * refactor: 💡 updates from PR feedback * refactor: 💡 updates for completions and linting * test: 💍 fix test issue with translations * test: 💍 fix test issue that was already fixed once * refactor: 💡 address PR feedback --------- Co-authored-by: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Co-authored-by: Zack Moore <zack.moore@hashicorp.com> Co-authored-by: calcaide <ccorvo@hashicorp.com> Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> Co-authored-by: Bharath Gajjala <120367134+bgajjala8@users.noreply.github.com>
This commit is contained in:
1 parent
1a8c895ea9
commit
08b8b03fed
12 files changed
+880
-29
No files matched your search
@@ -21,7 +21,6 @@
|
||||
@hasFullScreenButton={{true}}
|
||||
@ariaLabel={{t 'form.secret-editor.label'}}
|
||||
@value={{this.grantStringsText}}
|
||||
@onInput={{this.onInput}}
|
||||
@onSetup={{this.onSetup}}
|
||||
@customExtensions={{this.customExtensions}}
|
||||
@cspNonce={{(csp-nonce)}}
|
||||
@@ -68,6 +67,17 @@
|
||||
<GrantStringFormats />
|
||||
</:content>
|
||||
</A.Item>
|
||||
<A.Item @isOpen={{true}} @isStatic={{true}} data-test-grant-actions>
|
||||
<:toggle>{{t 'titles.actions'}}</:toggle>
|
||||
<:content>
|
||||
<div class='grant-actions-scroll-container'>
|
||||
<GrantActions
|
||||
@grantsSchema={{@grantsSchema}}
|
||||
@grantString={{this.currentLineText}}
|
||||
/>
|
||||
</div>
|
||||
</:content>
|
||||
</A.Item>
|
||||
</Hds::Accordion>
|
||||
</Hds::Layout::Grid>
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
autocompletion,
|
||||
completionKeymap,
|
||||
keymap,
|
||||
EditorView,
|
||||
linter,
|
||||
lintGutter,
|
||||
lintKeymap,
|
||||
@@ -172,6 +173,15 @@ export default class FormRoleEditGrantsComponent extends Component {
|
||||
// Trigger autocompletion when the user completes a grant field (which we labeled as keywords)
|
||||
activateOnCompletion: (completion) => completion.type === 'keyword',
|
||||
}),
|
||||
EditorView.updateListener.of((update) => {
|
||||
if (update.docChanged || update.selectionSet) {
|
||||
const line = update.state.doc.lineAt(update.state.selection.main.head);
|
||||
this.currentLineText = line.text;
|
||||
if (update.docChanged) {
|
||||
this.grantStringsText = update.state.doc.toString();
|
||||
}
|
||||
}
|
||||
}),
|
||||
linter(this.linterSource),
|
||||
lintGutter(),
|
||||
keymap.of([...completionKeymap, ...lintKeymap]),
|
||||
@@ -233,14 +243,6 @@ export default class FormRoleEditGrantsComponent extends Component {
|
||||
this.#editorView = view;
|
||||
}
|
||||
|
||||
@action
|
||||
onInput(value, view) {
|
||||
this.grantStringsText = value;
|
||||
|
||||
const line = view.state.doc.lineAt(view.state.selection.main.head);
|
||||
this.currentLineText = line.text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the export options flyout open and closed.
|
||||
*/
|
||||
|
||||
@@ -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.completion-info.no-suggestions'}}
|
||||
</A.Description>
|
||||
</Hds::Alert>
|
||||
{{/if}}
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Copyright IBM Corp. 2021, 2026
|
||||
* SPDX-License-Identifier: BUSL-1.1
|
||||
*/
|
||||
|
||||
import Component from '@glimmer/component';
|
||||
import { cached } from '@glimmer/tracking';
|
||||
import { service } from '@ember/service';
|
||||
|
||||
import { analyzeGrantString } from 'admin/utils/grant-completions';
|
||||
|
||||
export default class GrantActionsIndex extends Component {
|
||||
@service intl;
|
||||
|
||||
@cached
|
||||
get grantAnalysis() {
|
||||
return analyzeGrantString(
|
||||
this.args.grantsSchema ?? {},
|
||||
this.args.grantString,
|
||||
);
|
||||
}
|
||||
|
||||
get actionRows() {
|
||||
return this.grantAnalysis.actions.map((action) => ({
|
||||
name: action,
|
||||
description: this.getActionDescription(action),
|
||||
}));
|
||||
}
|
||||
|
||||
get showNoResourceTypeDetected() {
|
||||
const { actions, detectedResourceType } = this.grantAnalysis;
|
||||
return (
|
||||
!this.showInvalidIdAndType && !actions.length && !detectedResourceType
|
||||
);
|
||||
}
|
||||
|
||||
get showInvalidIdAndType() {
|
||||
const {
|
||||
actions,
|
||||
hasInvalidType,
|
||||
hasInvalidIds,
|
||||
hasInvalidPinnedIdTypeCombination,
|
||||
} = this.grantAnalysis;
|
||||
return (
|
||||
!actions.length &&
|
||||
(hasInvalidType || hasInvalidIds || hasInvalidPinnedIdTypeCombination)
|
||||
);
|
||||
}
|
||||
|
||||
getActionDescription(action) {
|
||||
const { detectedResourceType } = this.grantAnalysis;
|
||||
const specificKey = `resources.role.edit-grants.actions.${action}`;
|
||||
const genericKey = `resources.role.edit-grants.actions.generic.${action}`;
|
||||
|
||||
if (detectedResourceType && this.intl.exists(specificKey)) {
|
||||
return this.intl.t(specificKey, { resourceType: detectedResourceType });
|
||||
}
|
||||
|
||||
if (this.intl.exists(genericKey)) {
|
||||
return this.intl.t(genericKey);
|
||||
}
|
||||
|
||||
if (this.intl.exists(specificKey)) {
|
||||
return this.intl.t(specificKey);
|
||||
}
|
||||
|
||||
return action;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user