2021-11-05 14:12:21 -04:00
|
|
|
import Vue from 'vue';
|
2021-11-24 19:10:49 -05:00
|
|
|
import { __ } from '~/locale';
|
|
|
|
import App from './components/screens/app.vue';
|
|
|
|
import ServiceAccountsForm from './components/screens/service_accounts_form.vue';
|
|
|
|
import ErrorNoGcpProjects from './components/errors/no_gcp_projects.vue';
|
|
|
|
import ErrorGcpError from './components/errors/gcp_error.vue';
|
2021-11-05 14:12:21 -04:00
|
|
|
|
|
|
|
const elementRenderer = (element, props = {}) => (createElement) =>
|
|
|
|
createElement(element, { props });
|
|
|
|
|
2021-11-24 19:10:49 -05:00
|
|
|
const rootComponentMap = [
|
|
|
|
{
|
|
|
|
root: '#js-google-cloud-error-no-gcp-projects',
|
|
|
|
component: ErrorNoGcpProjects,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
root: '#js-google-cloud-error-gcp-error',
|
|
|
|
component: ErrorGcpError,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
root: '#js-google-cloud-service-accounts',
|
|
|
|
component: ServiceAccountsForm,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
root: '#js-google-cloud',
|
|
|
|
component: App,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-11-05 14:12:21 -04:00
|
|
|
export default () => {
|
2021-11-24 19:10:49 -05:00
|
|
|
for (let i = 0; i < rootComponentMap.length; i += 1) {
|
|
|
|
const { root, component } = rootComponentMap[i];
|
|
|
|
const element = document.querySelector(root);
|
|
|
|
if (element) {
|
|
|
|
const props = JSON.parse(element.getAttribute('data'));
|
|
|
|
return new Vue({ el: root, render: elementRenderer(component, props) });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new Error(__('Unknown root'));
|
2021-11-05 14:12:21 -04:00
|
|
|
};
|