Skip to content
Snippets Groups Projects
Commit fe46eb1b authored by Nathan Friend's avatar Nathan Friend Committed by Nicolò Mezzopera
Browse files

Update releases page to use state instead of props

This commit updates the releases page to store static data as Vuex state
instead of passing thee data to the Vue app as props.
parent c5915a7f
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -25,31 +25,16 @@ export default {
GlLink,
GlButton,
},
props: {
projectId: {
type: String,
required: true,
},
projectPath: {
type: String,
required: true,
},
documentationPath: {
type: String,
required: true,
},
illustrationPath: {
type: String,
required: true,
},
newReleasePath: {
type: String,
required: false,
default: '',
},
},
computed: {
...mapState('list', ['isLoading', 'releases', 'hasError', 'pageInfo']),
...mapState('list', [
'documentationPath',
'illustrationPath',
'newReleasePath',
'isLoading',
'releases',
'hasError',
'pageInfo',
]),
shouldRenderEmptyState() {
return !this.releases.length && !this.hasError && !this.isLoading;
},
Loading
Loading
@@ -65,15 +50,13 @@ export default {
created() {
this.fetchReleases({
page: getParameterByName('page'),
projectId: this.projectId,
projectPath: this.projectPath,
});
},
methods: {
...mapActions('list', ['fetchReleases']),
onChangePage(page) {
historyPushState(buildUrlWithCurrentLocation(`?page=${page}`));
this.fetchReleases({ page, projectId: this.projectId });
this.fetchReleases({ page });
},
},
};
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@ export default {
name: 'ReleasesPaginationGraphql',
components: { GlKeysetPagination },
computed: {
...mapState('list', ['projectPath', 'graphQlPageInfo']),
...mapState('list', ['graphQlPageInfo']),
showPagination() {
return this.graphQlPageInfo.hasPreviousPage || this.graphQlPageInfo.hasNextPage;
},
Loading
Loading
@@ -16,11 +16,11 @@ export default {
...mapActions('list', ['fetchReleasesGraphQl']),
onPrev(before) {
historyPushState(buildUrlWithCurrentLocation(`?before=${before}`));
this.fetchReleasesGraphQl({ projectPath: this.projectPath, before });
this.fetchReleasesGraphQl({ before });
},
onNext(after) {
historyPushState(buildUrlWithCurrentLocation(`?after=${after}`));
this.fetchReleasesGraphQl({ projectPath: this.projectPath, after });
this.fetchReleasesGraphQl({ after });
},
},
};
Loading
Loading
Loading
Loading
@@ -7,13 +7,13 @@ export default {
name: 'ReleasesPaginationRest',
components: { TablePagination },
computed: {
...mapState('list', ['projectId', 'pageInfo']),
...mapState('list', ['pageInfo']),
},
methods: {
...mapActions('list', ['fetchReleasesRest']),
onChangePage(page) {
historyPushState(buildUrlWithCurrentLocation(`?page=${page}`));
this.fetchReleasesRest({ page, projectId: this.projectId });
this.fetchReleasesRest({ page });
},
},
};
Loading
Loading
Loading
Loading
@@ -21,9 +21,6 @@ export default () => {
graphqlMilestoneStats: Boolean(gon.features?.graphqlMilestoneStats),
},
}),
render: h =>
h(ReleaseListApp, {
props: el.dataset,
}),
render: h => h(ReleaseListApp),
});
};
Loading
Loading
@@ -23,7 +23,7 @@ export const requestReleases = ({ commit }) => commit(types.REQUEST_RELEASES);
*
* @param {String} projectId
*/
export const fetchReleases = ({ dispatch, rootState }, { page = '1', projectId, projectPath }) => {
export const fetchReleases = ({ dispatch, rootState, state }, { page = '1' }) => {
dispatch('requestReleases');
 
if (
Loading
Loading
@@ -35,7 +35,7 @@ export const fetchReleases = ({ dispatch, rootState }, { page = '1', projectId,
.query({
query: allReleasesQuery,
variables: {
fullPath: projectPath,
fullPath: state.projectPath,
},
})
.then(response => {
Loading
Loading
@@ -44,7 +44,7 @@ export const fetchReleases = ({ dispatch, rootState }, { page = '1', projectId,
.catch(() => dispatch('receiveReleasesError'));
} else {
api
.releases(projectId, { page })
.releases(state.projectId, { page })
.then(response => dispatch('receiveReleasesSuccess', response))
.catch(() => dispatch('receiveReleasesError'));
}
Loading
Loading
Loading
Loading
@@ -27,15 +27,18 @@ describe('Releases App ', () => {
tagName: `${index}.00`,
}));
 
const defaultProps = {
const defaultInitialState = {
projectId: 'gitlab-ce',
projectPath: 'gitlab-org/gitlab-ce',
documentationPath: 'help/releases',
illustrationPath: 'illustration/path',
};
 
const createComponent = (propsData = defaultProps) => {
const listModule = createListModule({});
const createComponent = (stateUpdates = {}) => {
const listModule = createListModule({
...defaultInitialState,
...stateUpdates,
});
 
fetchReleaseSpy = jest.spyOn(listModule.actions, 'fetchReleases');
 
Loading
Loading
@@ -51,7 +54,6 @@ describe('Releases App ', () => {
wrapper = shallowMount(ReleasesApp, {
store,
localVue,
propsData,
});
};
 
Loading
Loading
@@ -68,13 +70,9 @@ describe('Releases App ', () => {
createComponent();
});
 
it('calls fetchRelease with the page, project ID, and project path', () => {
it('calls fetchRelease with the page parameter', () => {
expect(fetchReleaseSpy).toHaveBeenCalledTimes(1);
expect(fetchReleaseSpy).toHaveBeenCalledWith(expect.anything(), {
page: null,
projectId: defaultProps.projectId,
projectPath: defaultProps.projectPath,
});
expect(fetchReleaseSpy).toHaveBeenCalledWith(expect.anything(), { page: null });
});
});
 
Loading
Loading
@@ -156,7 +154,7 @@ describe('Releases App ', () => {
const newReleasePath = 'path/to/new/release';
 
beforeEach(() => {
createComponent({ ...defaultProps, newReleasePath });
createComponent({ ...defaultInitialState, newReleasePath });
});
 
it('renders the "New release" button', () => {
Loading
Loading
Loading
Loading
@@ -143,7 +143,7 @@ describe('~/releases/components/releases_pagination_graphql.vue', () => {
 
it('calls fetchReleasesGraphQl with the correct after cursor', () => {
expect(listModule.actions.fetchReleasesGraphQl.mock.calls).toEqual([
[expect.anything(), { projectPath, after: cursors.endCursor }],
[expect.anything(), { after: cursors.endCursor }],
]);
});
 
Loading
Loading
@@ -161,7 +161,7 @@ describe('~/releases/components/releases_pagination_graphql.vue', () => {
 
it('calls fetchReleasesGraphQl with the correct before cursor', () => {
expect(listModule.actions.fetchReleasesGraphQl.mock.calls).toEqual([
[expect.anything(), { projectPath, before: cursors.startCursor }],
[expect.anything(), { before: cursors.startCursor }],
]);
});
 
Loading
Loading
Loading
Loading
@@ -59,7 +59,7 @@ describe('~/releases/components/releases_pagination_rest.vue', () => {
 
it('calls fetchReleasesRest with the correct page', () => {
expect(listModule.actions.fetchReleasesRest.mock.calls).toEqual([
[expect.anything(), { projectId, page: newPage }],
[expect.anything(), { page: newPage }],
]);
});
 
Loading
Loading
Loading
Loading
@@ -23,11 +23,16 @@ describe('Releases State actions', () => {
let pageInfo;
let releases;
let graphqlReleasesResponse;
let projectPath;
const projectPath = 'root/test-project';
const projectId = 19;
 
beforeEach(() => {
mockedState = {
...createState({}),
...createState({
projectId,
projectPath,
}),
featureFlags: {
graphqlReleaseData: true,
graphqlReleasesPage: true,
Loading
Loading
@@ -38,7 +43,6 @@ describe('Releases State actions', () => {
pageInfo = parseIntPagination(pageInfoHeadersWithoutPagination);
releases = convertObjectPropsToCamelCase(originalReleases, { deep: true });
graphqlReleasesResponse = cloneDeep(originalGraphqlReleasesResponse);
projectPath = 'root/test-project';
});
 
describe('requestReleases', () => {
Loading
Loading
@@ -51,7 +55,7 @@ describe('Releases State actions', () => {
describe('success', () => {
it('dispatches requestReleases and receiveReleasesSuccess', done => {
jest.spyOn(gqClient, 'query').mockImplementation(({ query, variables }) => {
expect(query).toEqual(allReleasesQuery);
expect(query).toBe(allReleasesQuery);
expect(variables).toEqual({
fullPath: projectPath,
});
Loading
Loading
@@ -60,7 +64,7 @@ describe('Releases State actions', () => {
 
testAction(
fetchReleases,
{ projectPath },
{},
mockedState,
[],
[
Loading
Loading
@@ -83,7 +87,7 @@ describe('Releases State actions', () => {
 
testAction(
fetchReleases,
{ projectPath },
{},
mockedState,
[],
[
Loading
Loading
@@ -107,14 +111,14 @@ describe('Releases State actions', () => {
describe('success', () => {
it('dispatches requestReleases and receiveReleasesSuccess', done => {
jest.spyOn(api, 'releases').mockImplementation((id, options) => {
expect(id).toEqual(1);
expect(options.page).toEqual('1');
expect(id).toBe(projectId);
expect(options.page).toBe('1');
return Promise.resolve({ data: releases, headers: pageInfoHeadersWithoutPagination });
});
 
testAction(
fetchReleases,
{ projectId: 1 },
{},
mockedState,
[],
[
Loading
Loading
@@ -132,13 +136,13 @@ describe('Releases State actions', () => {
 
it('dispatches requestReleases and receiveReleasesSuccess on page two', done => {
jest.spyOn(api, 'releases').mockImplementation((_, options) => {
expect(options.page).toEqual('2');
expect(options.page).toBe('2');
return Promise.resolve({ data: releases, headers: pageInfoHeadersWithoutPagination });
});
 
testAction(
fetchReleases,
{ page: '2', projectId: 1 },
{ page: '2' },
mockedState,
[],
[
Loading
Loading
@@ -161,7 +165,7 @@ describe('Releases State actions', () => {
 
testAction(
fetchReleases,
{ projectId: null },
{},
mockedState,
[],
[
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment