export default function setupVueRepositoryList()

in app/assets/javascripts/repository/index.js [35:307]


export default function setupVueRepositoryList() {
  const el = document.getElementById('js-tree-list');
  const { dataset } = el;
  const {
    projectPath,
    projectShortPath,
    ref,
    escapedRef,
    fullName,
    resourceId,
    userId,
    explainCodeAvailable,
    targetBranch,
  } = dataset;
  const router = createRouter(projectPath, escapedRef, fullName);
  initFileTreeBrowser(router);

  apolloProvider.clients.defaultClient.cache.writeQuery({
    query: commitsQuery,
    data: {
      commits: [],
    },
  });

  apolloProvider.clients.defaultClient.cache.writeQuery({
    query: projectPathQuery,
    data: {
      projectPath,
    },
  });

  apolloProvider.clients.defaultClient.cache.writeQuery({
    query: projectShortPathQuery,
    data: {
      projectShortPath,
    },
  });

  apolloProvider.clients.defaultClient.cache.writeQuery({
    query: refsQuery,
    data: {
      ref,
      escapedRef,
    },
  });

  const initForkInfo = () => {
    const forkEl = document.getElementById('js-fork-info');
    if (!forkEl) {
      return null;
    }
    const {
      selectedBranch,
      sourceName,
      sourcePath,
      sourceDefaultBranch,
      createMrPath,
      viewMrPath,
      canSyncBranch,
      aheadComparePath,
      behindComparePath,
    } = forkEl.dataset;
    return new Vue({
      el: forkEl,
      apolloProvider,
      render(h) {
        return h(ForkInfo, {
          props: {
            canSyncBranch: parseBoolean(canSyncBranch),
            projectPath,
            selectedBranch,
            sourceName,
            sourcePath,
            sourceDefaultBranch,
            aheadComparePath,
            behindComparePath,
            createMrPath,
            viewMrPath,
          },
        });
      },
    });
  };

  const lastCommitEl = document.getElementById('js-last-commit');

  const initLastCommitApp = () =>
    new Vue({
      el: lastCommitEl,
      router,
      apolloProvider,
      render(h) {
        const historyUrl = generateHistoryUrl(
          lastCommitEl.dataset.historyLink,
          this.$route.params.path,
          this.$route.meta.refType || this.$route.query.ref_type,
        );
        return h(LastCommit, {
          props: {
            currentPath: this.$route.params.path,
            refType: this.$route.meta.refType || this.$route.query.ref_type,
            historyUrl: historyUrl.href,
          },
        });
      },
    });

  const initBlobControlsApp = () =>
    new Vue({
      el: document.getElementById('js-blob-controls'),
      router,
      apolloProvider,
      render(h) {
        return h(BlobControls, {
          props: {
            projectPath,
            refType: this.$route.meta.refType || this.$route.query.ref_type,
          },
        });
      },
    });

  const initRefSwitcher = () => {
    const refSwitcherEl = document.getElementById('js-tree-ref-switcher');

    if (!refSwitcherEl) return false;

    const { projectId, projectRootPath, refType } = refSwitcherEl.dataset;

    return new Vue({
      el: refSwitcherEl,
      render(createElement) {
        return createElement(RefSelector, {
          props: {
            projectId,
            value: refType ? joinPaths('refs', refType, ref) : ref,
            useSymbolicRefNames: true,
            queryParams: { sort: 'updated_desc' },
          },
          on: {
            input(selectedRef) {
              visitUrl(generateRefDestinationPath(projectRootPath, ref, selectedRef));
            },
          },
        });
      },
    });
  };

  const initCodeDropdown = () => {
    const codeDropdownEl = document.getElementById('js-code-dropdown');

    if (!codeDropdownEl) return false;

    const {
      sshUrl,
      httpUrl,
      kerberosUrl,
      xcodeUrl,
      directoryDownloadLinks,
      newWorkspacePath,
      projectId,
    } = codeDropdownEl.dataset;

    const CodeDropdownComponent =
      gon.features.directoryCodeDropdownUpdates && gon.features.blobRepositoryVueHeaderApp
        ? CompactCodeDropdown
        : CodeDropdown;

    return new Vue({
      el: codeDropdownEl,
      router,
      apolloProvider,
      render(createElement) {
        return createElement(CodeDropdownComponent, {
          props: {
            sshUrl,
            httpUrl,
            kerberosUrl,
            xcodeUrl,
            currentPath: this.$route.params.path,
            directoryDownloadLinks: JSON.parse(directoryDownloadLinks),
            projectId,
            projectPath,
            newWorkspacePath,
          },
        });
      },
    });
  };

  initHeaderApp({ router });
  initCodeDropdown();
  initLastCommitApp();
  initBlobControlsApp();
  initRefSwitcher();
  initForkInfo();

  const breadcrumbEl = document.getElementById('js-repo-breadcrumb');

  if (breadcrumbEl) {
    const {
      canCollaborate,
      canEditTree,
      canPushCode,
      canPushToBranch,
      selectedBranch,
      newBranchPath,
      newTagPath,
      newBlobPath,
      forkNewBlobPath,
      forkNewDirectoryPath,
      forkUploadBlobPath,
      uploadPath,
      newDirPath,
    } = breadcrumbEl.dataset;

    router.afterEach(({ params: { path } }) => {
      updateFormAction('.js-create-dir-form', newDirPath, path);
    });

    // eslint-disable-next-line no-new
    new Vue({
      el: breadcrumbEl,
      router,
      apolloProvider,
      render(h) {
        return h(Breadcrumbs, {
          props: {
            currentPath: this.$route.params.path,
            refType: this.$route.query.ref_type,
            canCollaborate: parseBoolean(canCollaborate),
            canPushToBranch: parseBoolean(canPushToBranch),
            canEditTree: parseBoolean(canEditTree),
            canPushCode: parseBoolean(canPushCode),
            originalBranch: ref,
            selectedBranch,
            newBranchPath,
            newTagPath,
            newBlobPath,
            forkNewBlobPath,
            forkNewDirectoryPath,
            forkUploadBlobPath,
            uploadPath,
            newDirPath,
          },
        });
      },
    });
  }

  initWebIdeLink({ el: document.getElementById('js-tree-web-ide-link'), router });

  // eslint-disable-next-line no-new
  new Vue({
    el,
    store: createStore(),
    router,
    apolloProvider,
    provide: {
      resourceId,
      userId,
      targetBranch,
      explainCodeAvailable: parseBoolean(explainCodeAvailable),
      highlightWorker: new HighlightWorker(),
    },
    render(h) {
      return h(App);
    },
  });

  return { router, data: dataset, apolloProvider, projectPath };
}