Skip to content
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

UI: LDAP Hierarchical roles #28824

Merged
merged 17 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix overview page search select
  • Loading branch information
hellobontempo committed Nov 2, 2024
commit 0679b42768afa3db7d8ea7dcadf07ab6ac9c3426
9 changes: 4 additions & 5 deletions ui/lib/core/addon/components/search-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,13 @@ export default class SearchSelect extends Component {
}

shouldShowCreate(id, searchResults) {
if (searchResults && searchResults.length && searchResults[0].groupName) {
if (this.args.disallowNewItems) return false;

if (searchResults?.length && searchResults[0].groupName) {
return !searchResults.some((group) => group.options.find((opt) => opt.id === id));
}
const existingOption =
this.dropdownOptions && this.dropdownOptions.find((opt) => opt.id === id || opt.name === id);
if (this.args.disallowNewItems && !existingOption) {
return false;
}
this.dropdownOptions && this.dropdownOptions.some((opt) => opt.id === id || opt.name === id);
return !existingOption;
}

Expand Down
10 changes: 8 additions & 2 deletions ui/lib/ldap/addon/components/page/overview.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,25 @@
class="is-flex-half"
/>
<div>
<OverviewCard @cardTitle="Generate credentials" @subText="Quickly generate credentials by typing the role name.">
<OverviewCard
@cardTitle="Generate credentials"
@subText="Quickly generate credentials by typing the role name. Only the engine's top-level roles are listed here."
>
<:content>
<div class="has-top-margin-m is-flex">
<SearchSelect
class="is-flex-1"
@ariaLabel="Role"
@placeholder="Select a role"
@disallowNewItems={{true}}
@options={{@roles}}
@options={{this.roleOptions}}
@selectLimit="1"
@fallbackComponent="input-search"
@onChange={{this.selectRole}}
@renderInPlace={{true}}
@passObject={{true}}
@objectKeys={{array "id" "name" "type"}}
@shouldRenderName={{true}}
/>
<div>
<Hds::Button
Expand Down
25 changes: 22 additions & 3 deletions ui/lib/ldap/addon/components/page/overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,34 @@ interface Args {
breadcrumbs: Array<Breadcrumb>;
}

interface Option {
id: string;
name: string;
type: string;
}

export default class LdapLibrariesPageComponent extends Component<Args> {
@service('app-router') declare readonly router: RouterService;

@tracked selectedRole: LdapRoleModel | undefined;

get roleOptions() {
const options = this.args.roles
// hierarchical roles are not selectable
.filter((r: LdapRoleModel) => !r.name.endsWith('/'))
// *hack alert* - type is set as id so it renders beside name in search select
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// this is to avoid more changes to search select and is okay because we are only selecting one item
.map((r: LdapRoleModel) => ({ id: r.type, name: r.name, type: r.type }));
return options;
}

@action
selectRole([roleName]: Array<string>) {
const model = this.args.roles.find((role) => role.name === roleName);
this.selectedRole = model;
async selectRole([option]: Array<Option>) {
if (option) {
const { name, type } = option;
const model = this.args.roles.find((role) => role.name === name && role.type === type);
this.selectedRole = model;
}
}

@action
Expand Down