Commit 22078f8a authored by Enrique Alcantara's avatar Enrique Alcantara

Migrate isSupportedContent to Apollo

Use VueApollo to handle the isSupportedContent
business logic
parent bac995be
extend type Query { extend type Query {
isSupportedContent: Boolean! isSupportedContent: Boolean!
projectId: String! project: String!
returnUrl: String returnUrl: String
sourcePath: String! sourcePath: String!
username: String! username: String!
......
...@@ -6,7 +6,14 @@ import createRouter from './router'; ...@@ -6,7 +6,14 @@ import createRouter from './router';
import createApolloProvider from './graphql'; import createApolloProvider from './graphql';
const initStaticSiteEditor = el => { const initStaticSiteEditor = el => {
const { isSupportedContent, projectId, path: sourcePath, baseUrl } = el.dataset; const {
isSupportedContent,
projectId,
path: sourcePath,
baseUrl,
namespace,
project,
} = el.dataset;
const { current_username: username } = window.gon; const { current_username: username } = window.gon;
const returnUrl = el.dataset.returnUrl || null; const returnUrl = el.dataset.returnUrl || null;
...@@ -22,7 +29,7 @@ const initStaticSiteEditor = el => { ...@@ -22,7 +29,7 @@ const initStaticSiteEditor = el => {
const router = createRouter(baseUrl); const router = createRouter(baseUrl);
const apolloProvider = createApolloProvider({ const apolloProvider = createApolloProvider({
isSupportedContent: parseBoolean(isSupportedContent), isSupportedContent: parseBoolean(isSupportedContent),
projectId, project: `${namespace}/${project}`,
returnUrl, returnUrl,
sourcePath, sourcePath,
username, username,
......
...@@ -11,6 +11,8 @@ import PublishToolbar from '../components/publish_toolbar.vue'; ...@@ -11,6 +11,8 @@ import PublishToolbar from '../components/publish_toolbar.vue';
import InvalidContentMessage from '../components/invalid_content_message.vue'; import InvalidContentMessage from '../components/invalid_content_message.vue';
import SubmitChangesError from '../components/submit_changes_error.vue'; import SubmitChangesError from '../components/submit_changes_error.vue';
import appDataQuery from '../graphql/queries/app_data.query.graphql';
export default { export default {
components: { components: {
RichContentEditor, RichContentEditor,
...@@ -23,13 +25,17 @@ export default { ...@@ -23,13 +25,17 @@ export default {
SubmitChangesError, SubmitChangesError,
}, },
mixins: [glFeatureFlagsMixin()], mixins: [glFeatureFlagsMixin()],
apollo: {
isSupportedContent: {
query: appDataQuery,
},
},
computed: { computed: {
...mapState([ ...mapState([
'content', 'content',
'isLoadingContent', 'isLoadingContent',
'isSavingChanges', 'isSavingChanges',
'isContentLoaded', 'isContentLoaded',
'isSupportedContent',
'returnUrl', 'returnUrl',
'title', 'title',
'submitChangesError', 'submitChangesError',
......
...@@ -6,7 +6,6 @@ const createState = (initialState = {}) => ({ ...@@ -6,7 +6,6 @@ const createState = (initialState = {}) => ({
isLoadingContent: false, isLoadingContent: false,
isSavingChanges: false, isSavingChanges: false,
isSupportedContent: false,
isContentLoaded: false, isContentLoaded: false,
......
...@@ -40,7 +40,6 @@ describe('static_site_editor/pages/home', () => { ...@@ -40,7 +40,6 @@ describe('static_site_editor/pages/home', () => {
store = new Vuex.Store({ store = new Vuex.Store({
state: createState({ state: createState({
isSupportedContent: true,
...initialState, ...initialState,
}), }),
getters: { getters: {
...@@ -67,13 +66,16 @@ describe('static_site_editor/pages/home', () => { ...@@ -67,13 +66,16 @@ describe('static_site_editor/pages/home', () => {
}); });
}; };
const buildWrapper = () => { const buildWrapper = (data = { isSupportedContent: true }) => {
wrapper = shallowMount(Home, { wrapper = shallowMount(Home, {
localVue, localVue,
store, store,
provide: { provide: {
glFeatures: { richContentEditor: true }, glFeatures: { richContentEditor: true },
}, },
data() {
return data;
},
}); });
}; };
...@@ -194,8 +196,7 @@ describe('static_site_editor/pages/home', () => { ...@@ -194,8 +196,7 @@ describe('static_site_editor/pages/home', () => {
}); });
it('displays invalid content message when content is not supported', () => { it('displays invalid content message when content is not supported', () => {
buildStore({ initialState: { isSupportedContent: false } }); buildWrapper({ isSupportedContent: false });
buildWrapper();
expect(findInvalidContentMessage().exists()).toBe(true); expect(findInvalidContentMessage().exists()).toBe(true);
}); });
......
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