Commit aa7e55f2 authored by Dennis Tang's avatar Dennis Tang

refactor dropdown reusable components

parent da3610ff
...@@ -5,10 +5,10 @@ import { mapState, mapGetters, mapActions } from 'vuex'; ...@@ -5,10 +5,10 @@ import { mapState, mapGetters, mapActions } from 'vuex';
import LoadingIcon from '~/vue_shared/components/loading_icon.vue'; import LoadingIcon from '~/vue_shared/components/loading_icon.vue';
import DropdownSearchInput from '~/vue_shared/components/dropdown/dropdown_search_input.vue'; import DropdownSearchInput from '~/vue_shared/components/dropdown/dropdown_search_input.vue';
import DropdownHiddenInput from '~/vue_shared/components/dropdown/dropdown_hidden_input.vue'; import DropdownHiddenInput from '~/vue_shared/components/dropdown/dropdown_hidden_input.vue';
import DropdownButton from '~/vue_shared/components/dropdown/dropdown_button.vue';
import eventHub from '../eventhub'; import eventHub from '../eventhub';
import store from '../stores'; import store from '../stores';
import DropdownButton from './dropdown_button.vue';
export default { export default {
name: 'GkeMachineTypeDropdown', name: 'GkeMachineTypeDropdown',
......
...@@ -5,9 +5,9 @@ import { mapState, mapGetters, mapActions } from 'vuex'; ...@@ -5,9 +5,9 @@ import { mapState, mapGetters, mapActions } from 'vuex';
import LoadingIcon from '~/vue_shared/components/loading_icon.vue'; import LoadingIcon from '~/vue_shared/components/loading_icon.vue';
import DropdownSearchInput from '~/vue_shared/components/dropdown/dropdown_search_input.vue'; import DropdownSearchInput from '~/vue_shared/components/dropdown/dropdown_search_input.vue';
import DropdownHiddenInput from '~/vue_shared/components/dropdown/dropdown_hidden_input.vue'; import DropdownHiddenInput from '~/vue_shared/components/dropdown/dropdown_hidden_input.vue';
import DropdownButton from '~/vue_shared/components/dropdown/dropdown_button.vue';
import store from '../stores'; import store from '../stores';
import DropdownButton from './dropdown_button.vue';
export default { export default {
name: 'GkeProjectIdDropdown', name: 'GkeProjectIdDropdown',
......
...@@ -5,10 +5,10 @@ import { mapState, mapGetters, mapActions } from 'vuex'; ...@@ -5,10 +5,10 @@ import { mapState, mapGetters, mapActions } from 'vuex';
import LoadingIcon from '~/vue_shared/components/loading_icon.vue'; import LoadingIcon from '~/vue_shared/components/loading_icon.vue';
import DropdownSearchInput from '~/vue_shared/components/dropdown/dropdown_search_input.vue'; import DropdownSearchInput from '~/vue_shared/components/dropdown/dropdown_search_input.vue';
import DropdownHiddenInput from '~/vue_shared/components/dropdown/dropdown_hidden_input.vue'; import DropdownHiddenInput from '~/vue_shared/components/dropdown/dropdown_hidden_input.vue';
import DropdownButton from '~/vue_shared/components/dropdown/dropdown_button.vue';
import eventHub from '../eventhub'; import eventHub from '../eventhub';
import store from '../stores'; import store from '../stores';
import DropdownButton from './dropdown_button.vue';
export default { export default {
name: 'GkeZoneDropdown', name: 'GkeZoneDropdown',
......
<script> <script>
import { s__ } from '~/locale'; import { __ } from '~/locale';
import LoadingIcon from '~/vue_shared/components/loading_icon.vue'; import LoadingIcon from '~/vue_shared/components/loading_icon.vue';
export default { export default {
...@@ -19,8 +19,8 @@ export default { ...@@ -19,8 +19,8 @@ export default {
}, },
toggleText: { toggleText: {
type: String, type: String,
required: true, required: false,
default: s__('ClusterIntegration|Select'), default: __('Select'),
}, },
}, },
}; };
...@@ -41,11 +41,15 @@ export default { ...@@ -41,11 +41,15 @@ export default {
<span class="dropdown-toggle-text"> <span class="dropdown-toggle-text">
{{ toggleText }} {{ toggleText }}
</span> </span>
<span
class="dropdown-toggle-icon"
v-show="!isLoading"
>
<i <i
class="fa fa-chevron-down"
aria-hidden="true" aria-hidden="true"
data-hidden="true" data-hidden="true"
v-show="!isLoading"
class="fa fa-chevron-down"
></i> ></i>
</span>
</button> </button>
</template> </template>
...@@ -6,7 +6,7 @@ export default { ...@@ -6,7 +6,7 @@ export default {
required: true, required: true,
}, },
value: { value: {
type: String, type: [Number, String],
required: true, required: true,
}, },
}, },
......
...@@ -30,14 +30,14 @@ export default { ...@@ -30,14 +30,14 @@ export default {
autocomplete="off" autocomplete="off"
/> />
<i <i
aria-hidden="true"
class="fa fa-search dropdown-input-search" class="fa fa-search dropdown-input-search"
aria-hidden="true"
data-hidden="true" data-hidden="true"
> >
</i> </i>
<i <i
aria-hidden="true"
class="fa fa-times dropdown-input-clear js-dropdown-input-clear" class="fa fa-times dropdown-input-clear js-dropdown-input-clear"
aria-hidden="true"
data-hidden="true" data-hidden="true"
role="button" role="button"
> >
......
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
import $ from 'jquery'; import $ from 'jquery';
import { __ } from '~/locale'; import { __ } from '~/locale';
import LabelsSelect from '~/labels_select'; import LabelsSelect from '~/labels_select';
import DropdownHiddenInput from '~/vue_shared/components/dropdown/dropdown_hidden_input.vue';
import LoadingIcon from '../../loading_icon.vue'; import LoadingIcon from '../../loading_icon.vue';
import DropdownTitle from './dropdown_title.vue'; import DropdownTitle from './dropdown_title.vue';
import DropdownValue from './dropdown_value.vue'; import DropdownValue from './dropdown_value.vue';
import DropdownValueCollapsed from './dropdown_value_collapsed.vue'; import DropdownValueCollapsed from './dropdown_value_collapsed.vue';
import DropdownButton from './dropdown_button.vue'; import DropdownButton from './dropdown_button.vue';
import DropdownHiddenInput from './dropdown_hidden_input.vue';
import DropdownHeader from './dropdown_header.vue'; import DropdownHeader from './dropdown_header.vue';
import DropdownSearchInput from './dropdown_search_input.vue'; import DropdownSearchInput from './dropdown_search_input.vue';
import DropdownFooter from './dropdown_footer.vue'; import DropdownFooter from './dropdown_footer.vue';
...@@ -140,7 +140,7 @@ export default { ...@@ -140,7 +140,7 @@ export default {
v-for="label in context.labels" v-for="label in context.labels"
:key="label.id" :key="label.id"
:name="hiddenInputName" :name="hiddenInputName"
:label="label" :value="label.id"
/> />
<div <div
class="dropdown" class="dropdown"
......
<script>
export default {
props: {
name: {
type: String,
required: true,
},
label: {
type: Object,
required: true,
},
},
};
</script>
<template>
<input
type="hidden"
:name="name"
:value="label.id"
/>
</template>
import Vue from 'vue';
import dropdownHiddenInputComponent from '~/vue_shared/components/sidebar/labels_select/dropdown_hidden_input.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { mockLabels } from './mock_data';
const createComponent = (name = 'label_id[]', label = mockLabels[0]) => {
const Component = Vue.extend(dropdownHiddenInputComponent);
return mountComponent(Component, {
name,
label,
});
};
describe('DropdownHiddenInputComponent', () => {
let vm;
beforeEach(() => {
vm = createComponent();
});
afterEach(() => {
vm.$destroy();
});
describe('template', () => {
it('renders input element of type `hidden`', () => {
expect(vm.$el.nodeName).toBe('INPUT');
expect(vm.$el.getAttribute('type')).toBe('hidden');
expect(vm.$el.getAttribute('name')).toBe(vm.name);
expect(vm.$el.getAttribute('value')).toBe(`${vm.label.id}`);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment