summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/explorer/utils.js
blob: a48da51caae13d78715f1352d3ae2afa7b754b20 (plain)
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
import { joinPaths } from '~/lib/utils/url_utility';

export const pathGenerator = (imageDetails, ending = '?format=json') => {
  // this method is a temporary workaround, to be removed with graphql implementation
  // https://gitlab.com/gitlab-org/gitlab/-/issues/276432

  const splitPath = imageDetails.path.split('/').reverse();
  const splitName = imageDetails.name ? imageDetails.name.split('/').reverse() : [];
  const basePath = splitPath
    .reduce((acc, curr, index) => {
      if (splitPath[index] !== splitName[index]) {
        acc.unshift(curr);
      }
      return acc;
    }, [])
    .join('/');

  return joinPaths(
    window.gon.relative_url_root,
    `/${basePath}`,
    '/registry/repository/',
    `${imageDetails.id}`,
    `tags${ending}`,
  );
};