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

Fix select issues #11869

Merged
merged 5 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
7 changes: 5 additions & 2 deletions shell/components/auth/AllowedPrincipals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import ArrayList from '@shell/components/form/ArrayList';
import Principal from '@shell/components/auth/Principal';
import SelectPrincipal from '@shell/components/auth/SelectPrincipal';
import { _EDIT } from '@shell/config/query-params';
import { addObject } from '@shell/utils/array';

export default {
components: {
Expand Down Expand Up @@ -56,7 +55,11 @@ export default {

methods: {
addPrincipal(id) {
addObject(this.authConfig.allowedPrincipalIds, id);
const currentIds = this.authConfig.allowedPrincipalIds;
// add new id and remove duplicates
const updatedIds = [...new Set([...currentIds, id])];
Copy link
Contributor

Choose a reason for hiding this comment

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

I like it, It's elegant. Does Set preserve order?

We do use lodash though so I think we want to use https://lodash.com/docs/3.10.1#uniq. Notice they also have the unique() alias in case you'd want to use that.

Copy link
Member Author

Choose a reason for hiding this comment

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

@codyrancher yes Set preserves order, but as you pointed out, I should've used lodash one, thanks!


this.authConfig.allowedPrincipalIds = updatedIds;
},
}
};
Expand Down
2 changes: 1 addition & 1 deletion shell/components/auth/SelectPrincipal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export default {
:filterable="false"
class="select-principal"
:class="{'retain-selection': retainSelection}"
@input="add"
@update:value="add"
@search="onSearch"
@on-open="resetTooltipContent()"
@on-close="setTooltipContent()"
Expand Down
3 changes: 3 additions & 0 deletions shell/components/form/LabeledSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { LABEL_SELECT_NOT_OPTION_KINDS } from '@shell/types/components/labeledSe
export default {
name: 'LabeledSelect',

inheritAttrs: false,

components: { LabeledTooltip },
mixins: [
CompactInput,
Expand Down Expand Up @@ -245,6 +247,7 @@ export default {

<template>
<div
v-bind="$attrs"
ref="select"
class="labeled-select"
:class="{
Expand Down
Loading