Commit 86506bbc authored by Florie Guibert's avatar Florie Guibert

Merge getIdFromGraphQLId utils

parent afd257ba
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { GlModal, GlAlert } from '@gitlab/ui'; import { GlModal, GlAlert } from '@gitlab/ui';
import { mapGetters, mapActions, mapState } from 'vuex'; import { mapGetters, mapActions, mapState } from 'vuex';
import { TYPE_USER, TYPE_ITERATION, TYPE_MILESTONE } from '~/graphql_shared/constants'; import { TYPE_USER, TYPE_ITERATION, TYPE_MILESTONE } from '~/graphql_shared/constants';
import { convertToGraphQLId, getZeroBasedIdFromGraphQLId } from '~/graphql_shared/utils'; import { convertToGraphQLId, getIdFromGraphQLId } from '~/graphql_shared/utils';
import { getParameterByName, visitUrl } from '~/lib/utils/url_utility'; import { getParameterByName, visitUrl } from '~/lib/utils/url_utility';
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import { fullLabelId } from '../boards_util'; import { fullLabelId } from '../boards_util';
...@@ -169,11 +169,11 @@ export default { ...@@ -169,11 +169,11 @@ export default {
: null, : null,
// Temporarily converting to milestone ID due to https://gitlab.com/gitlab-org/gitlab/-/issues/344779 // Temporarily converting to milestone ID due to https://gitlab.com/gitlab-org/gitlab/-/issues/344779
milestoneId: this.board.milestone?.id milestoneId: this.board.milestone?.id
? convertToGraphQLId(TYPE_MILESTONE, getZeroBasedIdFromGraphQLId(this.board.milestone.id)) ? convertToGraphQLId(TYPE_MILESTONE, getIdFromGraphQLId(this.board.milestone.id))
: null, : null,
// Temporarily converting to iteration ID due to https://gitlab.com/gitlab-org/gitlab/-/issues/344779 // Temporarily converting to iteration ID due to https://gitlab.com/gitlab-org/gitlab/-/issues/344779
iterationId: this.board.iteration?.id iterationId: this.board.iteration?.id
? convertToGraphQLId(TYPE_ITERATION, getZeroBasedIdFromGraphQLId(this.board.iteration.id)) ? convertToGraphQLId(TYPE_ITERATION, getIdFromGraphQLId(this.board.iteration.id))
: null, : null,
}; };
}, },
......
...@@ -25,9 +25,7 @@ const parseGid = (gid) => parseInt(`${gid}`.replace(/gid:\/\/gitlab\/.*\//g, '') ...@@ -25,9 +25,7 @@ const parseGid = (gid) => parseInt(`${gid}`.replace(/gid:\/\/gitlab\/.*\//g, '')
* @param {String} gid GraphQL global ID * @param {String} gid GraphQL global ID
* @returns {Number} * @returns {Number}
*/ */
export const getIdFromGraphQLId = (gid = '') => parseGid(gid) || null; export const getIdFromGraphQLId = (gid = '') => {
export const getZeroBasedIdFromGraphQLId = (gid = '') => {
const parsedGid = parseGid(gid); const parsedGid = parseGid(gid);
return Number.isInteger(parsedGid) ? parsedGid : null; return Number.isInteger(parsedGid) ? parsedGid : null;
}; };
......
import { import {
isGid, isGid,
getIdFromGraphQLId, getIdFromGraphQLId,
getZeroBasedIdFromGraphQLId,
convertToGraphQLId, convertToGraphQLId,
convertToGraphQLIds, convertToGraphQLIds,
convertFromGraphQLIds, convertFromGraphQLIds,
...@@ -54,7 +53,7 @@ describe('getIdFromGraphQLId', () => { ...@@ -54,7 +53,7 @@ describe('getIdFromGraphQLId', () => {
}, },
{ {
input: 'gid://gitlab/Environments/0', input: 'gid://gitlab/Environments/0',
output: null, output: 0,
}, },
{ {
input: 'gid://gitlab/Environments/123', input: 'gid://gitlab/Environments/123',
...@@ -71,55 +70,6 @@ describe('getIdFromGraphQLId', () => { ...@@ -71,55 +70,6 @@ describe('getIdFromGraphQLId', () => {
}); });
}); });
describe('getZeroBasedIdFromGraphQLId', () => {
[
{
input: '',
output: null,
},
{
input: null,
output: null,
},
{
input: 2,
output: 2,
},
{
input: 'gid://',
output: null,
},
{
input: 'gid://gitlab/',
output: null,
},
{
input: 'gid://gitlab/Environments',
output: null,
},
{
input: 'gid://gitlab/Environments/',
output: null,
},
{
input: 'gid://gitlab/Environments/0',
output: 0,
},
{
input: 'gid://gitlab/Environments/123',
output: 123,
},
{
input: 'gid://gitlab/DesignManagement::Version/2',
output: 2,
},
].forEach(({ input, output }) => {
it(`getZeroBasedIdFromGraphQLId returns ${output} when passed ${input}`, () => {
expect(getZeroBasedIdFromGraphQLId(input)).toBe(output);
});
});
});
describe('convertToGraphQLId', () => { describe('convertToGraphQLId', () => {
it('combines $type and $id into $result', () => { it('combines $type and $id into $result', () => {
expect(convertToGraphQLId(mockType, mockId)).toBe(mockGid); expect(convertToGraphQLId(mockType, mockId)).toBe(mockGid);
......
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