BigW Consortium Gitlab

Commit 81d769ec by Dennis Tang

refactor component mounts into reusable function

parent 36eaa408
...@@ -6,8 +6,8 @@ import GkeZoneDropdown from './components/gke_zone_dropdown.vue'; ...@@ -6,8 +6,8 @@ import GkeZoneDropdown from './components/gke_zone_dropdown.vue';
import GkeMachineTypeDropdown from './components/gke_machine_type_dropdown.vue'; import GkeMachineTypeDropdown from './components/gke_machine_type_dropdown.vue';
import * as CONSTANTS from './constants'; import * as CONSTANTS from './constants';
const mountGkeProjectIdDropdown = () => { const mountComponent = (entryPoint, component, componentName, extraProps = {}) => {
const el = document.querySelector('.js-gcp-project-id-dropdown-entry-point'); const el = document.querySelector(entryPoint);
const hiddenInput = el.querySelector('input'); const hiddenInput = el.querySelector('input');
if (!el) return false; if (!el) return false;
...@@ -15,62 +15,39 @@ const mountGkeProjectIdDropdown = () => { ...@@ -15,62 +15,39 @@ const mountGkeProjectIdDropdown = () => {
return new Vue({ return new Vue({
el, el,
components: { components: {
GkeProjectIdDropdown, [componentName]: component,
}, },
render: createElement => render: createElement =>
createElement('gke-project-id-dropdown', { createElement(componentName, {
props: { props: {
docsUrl: el.dataset.docsurl,
fieldName: hiddenInput.getAttribute('name'), fieldName: hiddenInput.getAttribute('name'),
fieldId: hiddenInput.getAttribute('id'), fieldId: hiddenInput.getAttribute('id'),
defaultValue: hiddenInput.value, defaultValue: hiddenInput.value,
...extraProps,
}, },
}), }),
}); });
}; };
const mountGkeZoneDropdown = () => { const mountGkeProjectIdDropdown = () => {
const el = document.querySelector('.js-gcp-zone-dropdown-entry-point'); const entryPoint = '.js-gcp-project-id-dropdown-entry-point';
const hiddenInput = el.querySelector('input'); const el = document.querySelector(entryPoint);
if (!el) return false;
return new Vue({ mountComponent(entryPoint, GkeProjectIdDropdown, 'gke-project-id-dropdown', {
el, docsUrl: el.dataset.docsurl,
components: {
GkeZoneDropdown,
},
render: createElement =>
createElement('gke-zone-dropdown', {
props: {
fieldName: hiddenInput.getAttribute('name'),
fieldId: hiddenInput.getAttribute('id'),
defaultValue: hiddenInput.value,
},
}),
}); });
}; };
const mountGkeMachineTypeDropdown = () => { const mountGkeZoneDropdown = () => {
const el = document.querySelector('.js-gcp-machine-type-dropdown-entry-point'); mountComponent('.js-gcp-zone-dropdown-entry-point', GkeZoneDropdown, 'gke-zone-dropdown');
const hiddenInput = el.querySelector('input'); };
if (!el) return false;
return new Vue({ const mountGkeMachineTypeDropdown = () => {
el, mountComponent(
components: { '.js-gcp-machine-type-dropdown-entry-point',
GkeMachineTypeDropdown, GkeMachineTypeDropdown,
}, 'gke-machine-type-dropdown',
render: createElement => );
createElement('gke-machine-type-dropdown', {
props: {
fieldName: hiddenInput.getAttribute('name'),
fieldId: hiddenInput.getAttribute('id'),
defaultValue: hiddenInput.value,
},
}),
});
}; };
const gkeDropdownErrorHandler = () => { const gkeDropdownErrorHandler = () => {
......
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