All files / app/assets/javascripts/import_entities/import_projects index.js

0% Statements 0/16
0% Branches 0/5
0% Functions 0/6
0% Lines 0/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86                                                                                                                                                                           
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import { parseBoolean } from '~/lib/utils/common_utils';
import Translate from '~/vue_shared/translate';
import createDefaultClient from '~/lib/graphql';
import ImportProjectsTable from './components/import_projects_table.vue';
 
import createStore from './store';
 
Vue.use(Translate);
Vue.use(VueApollo);
 
export function initStoreFromElement(element) {
  const {
    ciCdOnly,
    canSelectNamespace,
    provider,
 
    reposPath,
    jobsPath,
    importPath,
    cancelPath,
    defaultTargetNamespace,
  } = element.dataset;
 
  return createStore({
    initialState: {
      defaultTargetNamespace,
      ciCdOnly: parseBoolean(ciCdOnly),
      canSelectNamespace: parseBoolean(canSelectNamespace),
      provider,
    },
    endpoints: {
      reposPath,
      jobsPath,
      importPath,
      cancelPath,
    },
  });
}
 
export function initPropsFromElement(element) {
  return {
    providerTitle: element.dataset.providerTitle,
    filterable: parseBoolean(element.dataset.filterable),
    paginatable: parseBoolean(element.dataset.paginatable),
    optionalStages: JSON.parse(element.dataset.optionalStages),
    cancelable: Boolean(element.dataset.cancelPath),
  };
}
 
const defaultClient = createDefaultClient();
 
const apolloProvider = new VueApollo({
  defaultClient,
});
 
export default function mountImportProjectsTable({
  mountElement,
  Component = ImportProjectsTable,
  extraProps = () => ({}),
  extraProvide = () => ({}),
}) {
  if (!mountElement) return undefined;
 
  const store = initStoreFromElement(mountElement);
  const props = initPropsFromElement(mountElement);
  const { detailsPath } = mountElement.dataset;
 
  return new Vue({
    el: mountElement,
    name: 'ImportProjectsRoot',
    store,
    apolloProvider,
    provide: {
      detailsPath,
      ...extraProvide(mountElement.dataset),
    },
    render(createElement) {
      // We are using attrs instead of props so root-level component with inheritAttrs
      // will be able to pass them down
      return createElement(Component, { attrs: { ...props, ...extraProps(mountElement.dataset) } });
    },
  });
}