Skip to content

Commit 96a36ff

Browse files
authored
Merge pull request #17355 from rak-phillip/task/labeled-select-composable
Migrate components off the LabeledFormElement mixin
2 parents c20230b + 17aa0dd commit 96a36ff

14 files changed

Lines changed: 435 additions & 445 deletions

File tree

shell/chart/__tests__/S3.test.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { nextTick } from 'vue';
33
import { mount } from '@vue/test-utils';
44

55
import S3 from '@shell/chart/rancher-backup/S3';
6-
import Vuex from 'vuex';
6+
import { createStore } from 'vuex';
77

88
describe('rancher-backup: S3', () => {
99
const mockStore = {
@@ -16,8 +16,15 @@ describe('rancher-backup: S3', () => {
1616
}
1717
};
1818
const wrapper = mount(S3, {
19-
plugins: [Vuex],
20-
global: { mocks: { $store: mockStore, $fetchState: { pending: false } } }
19+
global: { mocks: { $store: mockStore, $fetchState: { pending: false } } },
20+
provide: {
21+
store: createStore({
22+
getters: {
23+
'cluster/paginationEnabled': () => () => false,
24+
currentStore: () => 'cluster'
25+
}
26+
})
27+
},
2128
});
2229

2330
it('should emit invalid when form is not filled', () => {

shell/components/form/InputWithSelect.vue

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
<script>
2-
import labeledFormElement from '@shell/mixins/labeled-form-element';
32
import { LabeledInput } from '@components/Form/LabeledInput';
43
import LabeledSelect from '@shell/components/form/LabeledSelect';
54
import Select from '@shell/components/form/Select';
5+
import { computed } from 'vue';
6+
import { _VIEW, _EDIT } from '@shell/config/query-params';
7+
68
export default {
7-
name: 'InputWithSelect',
9+
name: 'InputWithSelect',
10+
11+
inheritAttrs: false,
12+
813
emits: ['update:value'],
914
components: {
1015
LabeledInput,
1116
LabeledSelect,
1217
Select,
1318
},
14-
mixins: [labeledFormElement],
15-
props: {
19+
props: {
1620
disabled: {
1721
type: Boolean,
1822
default: false,
@@ -84,23 +88,27 @@ export default {
8488
selectRules: {
8589
default: () => [],
8690
type: Array,
91+
},
92+
mode: {
93+
type: String,
94+
default: _EDIT,
8795
}
8896
8997
},
9098
99+
setup(props) {
100+
const isView = computed(() => props.mode === _VIEW);
101+
102+
return { isView };
103+
},
104+
91105
data() {
92106
return {
93107
selected: this.selectValue || this.options[0].value,
94108
string: this.textValue,
95109
};
96110
},
97111
98-
computed: {
99-
canPaginate() {
100-
return false;
101-
}
102-
},
103-
104112
methods: {
105113
focus() {
106114
const comp = this.$refs.text;

shell/components/form/LabeledSelect.vue

Lines changed: 82 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
<script>
22
import CompactInput from '@shell/mixins/compact-input';
3-
import LabeledFormElement from '@shell/mixins/labeled-form-element';
43
import { get } from '@shell/utils/object';
54
import { LabeledTooltip } from '@components/LabeledTooltip';
65
import VueSelectOverrides from '@shell/mixins/vue-select-overrides';
76
import { calculatePosition } from '@shell/utils/select';
87
import { generateRandomAlphaString } from '@shell/utils/string';
9-
import LabeledSelectPagination from '@shell/components/form/labeled-select-utils/labeled-select-pagination';
8+
import { useLabeledSelectPagination, labeledSelectPaginationProps } from '@shell/components/form/labeled-select-utils/useLabeledSelectPagination';
109
import { LABEL_SELECT_NOT_OPTION_KINDS } from '@shell/types/components/labeledSelect';
1110
import { mapGetters } from 'vuex';
1211
import { _VIEW } from '@shell/config/query-params';
1312
import { useClickOutside } from '@shell/composables/useClickOutside';
13+
import { useLabeledFormElement, labeledFormElementProps } from '@shell/composables/useLabeledFormElement';
14+
import { useLabeledSelect } from '@shell/composables/useLabeledSelect';
1415
import { ref } from 'vue';
1516
1617
export default {
@@ -21,14 +22,18 @@ export default {
2122
components: { LabeledTooltip },
2223
mixins: [
2324
CompactInput,
24-
LabeledFormElement,
2525
VueSelectOverrides,
26-
LabeledSelectPagination
2726
],
2827
29-
emits: ['on-open', 'on-close', 'selecting', 'deselecting', 'search', 'update:validation', 'update:value'],
28+
emits: ['on-open', 'on-close', 'on-focus', 'on-blur', 'selecting', 'deselecting', 'search', 'update:validation', 'update:value'],
3029
3130
props: {
31+
...labeledFormElementProps,
32+
...labeledSelectPaginationProps,
33+
value: {
34+
default: null,
35+
type: [String, Object, Number, Array, Boolean]
36+
},
3237
appendToBody: {
3338
default: true,
3439
type: Boolean,
@@ -37,14 +42,6 @@ export default {
3742
default: false,
3843
type: Boolean
3944
},
40-
disabled: {
41-
default: false,
42-
type: Boolean
43-
},
44-
required: {
45-
default: false,
46-
type: Boolean
47-
},
4845
hoverTooltip: {
4946
default: true,
5047
type: Boolean
@@ -99,14 +96,18 @@ export default {
9996
default: null,
10097
type: [String, Object]
10198
},
102-
value: {
103-
default: null,
104-
type: [String, Object, Number, Array, Boolean]
105-
},
10699
options: {
107100
type: Array,
108101
default: () => ([])
109102
},
103+
searchable: {
104+
default: false,
105+
type: Boolean
106+
},
107+
filterable: {
108+
default: true,
109+
type: Boolean
110+
},
110111
closeOnSelect: {
111112
type: Boolean,
112113
default: true
@@ -117,15 +118,75 @@ export default {
117118
}
118119
},
119120
120-
setup() {
121+
setup(props, { emit }) {
121122
const select = ref(null);
122123
const isOpen = ref(false);
123124
124125
useClickOutside(select, () => {
125126
isOpen.value = false;
126127
});
127128
128-
return { isOpen, select };
129+
const {
130+
raised,
131+
focused,
132+
blurred,
133+
empty,
134+
isView,
135+
onFocusLabeled,
136+
onBlurLabeled,
137+
isDisabled,
138+
validationMessage,
139+
requiredField
140+
} = useLabeledFormElement(props, emit);
141+
142+
const {
143+
canPaginate,
144+
canLoadMore,
145+
optionCounts,
146+
_options,
147+
pages,
148+
totalResults,
149+
paginating,
150+
loadMore,
151+
setPaginationFilter,
152+
} = useLabeledSelectPagination(props);
153+
154+
const {
155+
isSearchable,
156+
isFilterable,
157+
resizeHandler: resizeHandlerFn
158+
} = useLabeledSelect(props, canPaginate);
159+
160+
const resizeHandler = () => {
161+
resizeHandlerFn(select);
162+
};
163+
164+
return {
165+
isOpen,
166+
select,
167+
raised,
168+
focused,
169+
blurred,
170+
empty,
171+
isView,
172+
onFocusLabeled,
173+
onBlurLabeled,
174+
isDisabled,
175+
validationMessage,
176+
requiredField,
177+
isSearchable,
178+
isFilterable,
179+
resizeHandler,
180+
canPaginate,
181+
canLoadMore,
182+
optionCounts,
183+
_options,
184+
pages,
185+
totalResults,
186+
paginating,
187+
loadMore,
188+
setPaginationFilter,
189+
};
129190
},
130191
131192
data() {
@@ -148,11 +209,6 @@ export default {
148209
return this.canPaginate ? !!this._options.find((o) => o.kind === 'group' && !!o.icon) : false;
149210
},
150211
151-
_options() {
152-
// If we're paginated show the page as provided by `paginate`. See label-select-pagination mixin
153-
return this.canPaginate ? this.page : this.options;
154-
},
155-
156212
filteredAttrs() {
157213
const {
158214
class: _class,
@@ -207,11 +263,13 @@ export default {
207263
},
208264
209265
onFocus() {
266+
this.$emit('on-focus');
210267
this.selectedVisibility = 'hidden';
211268
this.onFocusLabeled();
212269
},
213270
214271
onBlur() {
272+
this.$emit('on-blur');
215273
this.selectedVisibility = 'visible';
216274
this.onBlurLabeled();
217275
},

0 commit comments

Comments
 (0)