Commit 2122f5b6 authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera Committed by David O'Regan

Connect Infrastructure Registry list to api correctly

parent 20dd0503
......@@ -93,3 +93,5 @@ export const LIST_TITLE_TEXT = s__('PackageRegistry|Package Registry');
export const LIST_INTRO_TEXT = s__(
'PackageRegistry|Publish and share packages for a variety of common package managers. %{docLinkStart}More information%{docLinkEnd}',
);
export const TERRAFORM_SEARCH_TYPE = Object.freeze({ value: { data: 'terraform_module' } });
......@@ -8,6 +8,7 @@ import {
DEFAULT_PAGE,
DEFAULT_PAGE_SIZE,
MISSING_DELETE_PATH_ERROR,
TERRAFORM_SEARCH_TYPE,
} from '../constants';
import { getNewPaginationPage } from '../utils';
import * as types from './mutation_types';
......@@ -27,8 +28,9 @@ export const requestPackagesList = ({ dispatch, state }, params = {}) => {
const { page = DEFAULT_PAGE, per_page = DEFAULT_PAGE_SIZE } = params;
const { sort, orderBy } = state.sorting;
const type = state.filter.find((f) => f.type === 'type');
const type = state.config.forceTerraform
? TERRAFORM_SEARCH_TYPE
: state.filter.find((f) => f.type === 'type');
const name = state.filter.find((f) => f.type === 'filtered-search-term');
const packageFilters = { package_type: type?.value?.data, package_name: name?.value?.data };
......
......@@ -4,9 +4,8 @@ import * as types from './mutation_types';
export default {
[types.SET_INITIAL_STATE](state, config) {
const { comingSoonJson, ...rest } = config;
state.config = {
...rest,
...config,
isGroupPage: config.pageType === GROUP_PAGE_TYPE,
};
},
......
......@@ -9,7 +9,7 @@ Vue.use(Translate);
export default () => {
const el = document.getElementById('js-vue-packages-list');
const store = createStore();
store.dispatch('setInitialState', el.dataset);
store.dispatch('setInitialState', { ...el.dataset, forceTerraform: true });
return new Vue({
el,
......
......@@ -121,6 +121,32 @@ describe('Actions Package list store', () => {
},
);
});
it('should force the terraform_module type when forceTerraform is true', (done) => {
testAction(
actions.requestPackagesList,
undefined,
{ config: { isGroupPage: false, resourceId: 1, forceTerraform: true }, sorting, filter },
[],
[
{ type: 'setLoading', payload: true },
{ type: 'receivePackagesListSuccess', payload: { data: 'foo', headers } },
{ type: 'setLoading', payload: false },
],
() => {
expect(Api.projectPackages).toHaveBeenCalledWith(1, {
params: {
page: 1,
per_page: 20,
sort: sorting.sort,
order_by: sorting.orderBy,
package_type: 'terraform_module',
},
});
done();
},
);
});
});
describe('receivePackagesListSuccess', () => {
......
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