Commit d042baea authored by Enrique Alcántara's avatar Enrique Alcántara

Merge branch '218531-add-mounts-data-to-apollo-cache' into 'master'

Add mounts data to apollo cache

See merge request gitlab-org/gitlab!45995
parents d7cd8547 09796297
...@@ -37,6 +37,10 @@ export default { ...@@ -37,6 +37,10 @@ export default {
required: false, required: false,
default: '', default: '',
}, },
mounts: {
type: Array,
required: true,
},
imageRoot: { imageRoot: {
type: String, type: String,
required: false, required: false,
......
...@@ -25,11 +25,15 @@ const createApolloProvider = appData => { ...@@ -25,11 +25,15 @@ const createApolloProvider = appData => {
}, },
); );
// eslint-disable-next-line @gitlab/require-i18n-strings
const mounts = appData.mounts.map(mount => ({ __typename: 'Mount', ...mount }));
defaultClient.cache.writeData({ defaultClient.cache.writeData({
data: { data: {
appData: { appData: {
__typename: 'AppData', __typename: 'AppData',
...appData, ...appData,
mounts,
}, },
}, },
}); });
......
...@@ -6,5 +6,9 @@ query appData { ...@@ -6,5 +6,9 @@ query appData {
sourcePath sourcePath
username username
returnUrl returnUrl
mounts {
source
target
}
} }
} }
...@@ -14,6 +14,11 @@ type SavedContentMeta { ...@@ -14,6 +14,11 @@ type SavedContentMeta {
branch: SavedContentField! branch: SavedContentField!
} }
type Mount {
source: String!
target: String
}
type AppData { type AppData {
isSupportedContent: Boolean! isSupportedContent: Boolean!
hasSubmittedChanges: Boolean! hasSubmittedChanges: Boolean!
...@@ -21,6 +26,7 @@ type AppData { ...@@ -21,6 +26,7 @@ type AppData {
returnUrl: String returnUrl: String
sourcePath: String! sourcePath: String!
username: String! username: String!
mounts: [Mount]!
} }
input HasSubmittedChangesInput { input HasSubmittedChangesInput {
......
...@@ -20,9 +20,6 @@ const initStaticSiteEditor = el => { ...@@ -20,9 +20,6 @@ const initStaticSiteEditor = el => {
imageUploadPath, imageUploadPath,
mounts, mounts,
} = el.dataset; } = el.dataset;
// NOTE that the object in 'mounts' is a JSON string from the data attribute, so it must be parsed into an object.
// eslint-disable-next-line no-unused-vars
const mountsObject = JSON.parse(mounts);
const { current_username: username } = window.gon; const { current_username: username } = window.gon;
const returnUrl = el.dataset.returnUrl || null; const returnUrl = el.dataset.returnUrl || null;
const router = createRouter(baseUrl); const router = createRouter(baseUrl);
...@@ -30,6 +27,7 @@ const initStaticSiteEditor = el => { ...@@ -30,6 +27,7 @@ const initStaticSiteEditor = el => {
isSupportedContent: parseBoolean(isSupportedContent), isSupportedContent: parseBoolean(isSupportedContent),
hasSubmittedChanges: false, hasSubmittedChanges: false,
project: `${namespace}/${project}`, project: `${namespace}/${project}`,
mounts: JSON.parse(mounts), // NOTE that the object in 'mounts' is a JSON string from the data attribute, so it must be parsed into an object.
returnUrl, returnUrl,
sourcePath, sourcePath,
username, username,
......
...@@ -138,6 +138,7 @@ export default { ...@@ -138,6 +138,7 @@ export default {
:content="sourceContent.content" :content="sourceContent.content"
:saving-changes="isSavingChanges" :saving-changes="isSavingChanges"
:return-url="appData.returnUrl" :return-url="appData.returnUrl"
:mounts="appData.mounts"
@submit="onPrepareSubmit" @submit="onPrepareSubmit"
/> />
<edit-meta-modal <edit-meta-modal
......
...@@ -15,6 +15,7 @@ import { ...@@ -15,6 +15,7 @@ import {
sourceContentHeaderObjYAML as headerSettings, sourceContentHeaderObjYAML as headerSettings,
sourceContentBody as body, sourceContentBody as body,
returnUrl, returnUrl,
mounts,
} from '../mock_data'; } from '../mock_data';
jest.mock('~/static_site_editor/services/formatter', () => jest.fn(str => `${str} format-pass`)); jest.mock('~/static_site_editor/services/formatter', () => jest.fn(str => `${str} format-pass`));
...@@ -31,6 +32,7 @@ describe('~/static_site_editor/components/edit_area.vue', () => { ...@@ -31,6 +32,7 @@ describe('~/static_site_editor/components/edit_area.vue', () => {
title, title,
content, content,
returnUrl, returnUrl,
mounts,
savingChanges, savingChanges,
...propsData, ...propsData,
}, },
......
...@@ -67,3 +67,10 @@ export const images = new Map([ ...@@ -67,3 +67,10 @@ export const images = new Map([
['path/to/image1.png', 'image1-content'], ['path/to/image1.png', 'image1-content'],
['path/to/image2.png', 'image2-content'], ['path/to/image2.png', 'image2-content'],
]); ]);
export const mounts = [
{
source: 'some/source/',
target: '',
},
];
...@@ -23,6 +23,7 @@ import { ...@@ -23,6 +23,7 @@ import {
submitChangesError, submitChangesError,
trackingCategory, trackingCategory,
images, images,
mounts,
} from '../mock_data'; } from '../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -41,6 +42,7 @@ describe('static_site_editor/pages/home', () => { ...@@ -41,6 +42,7 @@ describe('static_site_editor/pages/home', () => {
project, project,
username, username,
sourcePath, sourcePath,
mounts,
}; };
const hasSubmittedChangesMutationPayload = { const hasSubmittedChangesMutationPayload = {
data: { data: {
...@@ -119,6 +121,7 @@ describe('static_site_editor/pages/home', () => { ...@@ -119,6 +121,7 @@ describe('static_site_editor/pages/home', () => {
it('provides source content, returnUrl, and isSavingChanges to the edit area', () => { it('provides source content, returnUrl, and isSavingChanges to the edit area', () => {
expect(findEditArea().props()).toMatchObject({ expect(findEditArea().props()).toMatchObject({
title, title,
mounts,
content, content,
returnUrl, returnUrl,
savingChanges: false, savingChanges: false,
......
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