Commit 7f93b431 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch '345089-corpus-row-delete' into 'master'

Implement corpus delete logic

See merge request gitlab-org/gitlab!77847
parents aae5cfac 70266874
...@@ -4,6 +4,7 @@ import CorpusTable from 'ee/security_configuration/corpus_management/components/ ...@@ -4,6 +4,7 @@ import CorpusTable from 'ee/security_configuration/corpus_management/components/
import CorpusUpload from 'ee/security_configuration/corpus_management/components/corpus_upload.vue'; import CorpusUpload from 'ee/security_configuration/corpus_management/components/corpus_upload.vue';
import { s__, __ } from '~/locale'; import { s__, __ } from '~/locale';
import getCorpusesQuery from '../graphql/queries/get_corpuses.query.graphql'; import getCorpusesQuery from '../graphql/queries/get_corpuses.query.graphql';
import deleteCorpusMutation from '../graphql/mutations/delete_corpus.mutation.graphql';
export default { export default {
components: { components: {
...@@ -79,6 +80,20 @@ export default { ...@@ -79,6 +80,20 @@ export default {
}; };
this.$apollo.queries.states.refetch(); this.$apollo.queries.states.refetch();
}, },
onDelete(id) {
return this.$apollo
.mutate({
mutation: deleteCorpusMutation,
variables: {
input: {
id,
},
},
})
.then(() => {
this.$apollo.queries.states.refetch();
});
},
nextPage() { nextPage() {
this.pagination = { this.pagination = {
firstPageSize: this.$options.pageSize, firstPageSize: this.$options.pageSize,
...@@ -113,7 +128,7 @@ export default { ...@@ -113,7 +128,7 @@ export default {
<gl-loading-icon v-if="isLoading" size="lg" class="gl-py-13" /> <gl-loading-icon v-if="isLoading" size="lg" class="gl-py-13" />
<template v-else> <template v-else>
<corpus-table :corpuses="corpuses" /> <corpus-table :corpuses="corpuses" @delete="onDelete" />
</template> </template>
<div v-if="hasPagination" class="gl-display-flex gl-justify-content-center gl-mt-5"> <div v-if="hasPagination" class="gl-display-flex gl-justify-content-center gl-mt-5">
......
...@@ -6,7 +6,6 @@ import Target from 'ee/security_configuration/corpus_management/components/colum ...@@ -6,7 +6,6 @@ import Target from 'ee/security_configuration/corpus_management/components/colum
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import UserDate from '~/vue_shared/components/user_date.vue'; import UserDate from '~/vue_shared/components/user_date.vue';
import { ISO_SHORT_FORMAT } from '~/vue_shared/constants'; import { ISO_SHORT_FORMAT } from '~/vue_shared/constants';
import deleteCorpusMutation from '../graphql/mutations/delete_corpus.mutation.graphql';
const thClass = 'gl-bg-transparent! gl-border-gray-100! gl-border-b-solid! gl-border-b-1!'; const thClass = 'gl-bg-transparent! gl-border-gray-100! gl-border-b-solid! gl-border-b-1!';
...@@ -56,11 +55,8 @@ export default { ...@@ -56,11 +55,8 @@ export default {
emptyTable: s__('CorpusManagement|Currently, there are no uploaded or generated corpuses.'), emptyTable: s__('CorpusManagement|Currently, there are no uploaded or generated corpuses.'),
}, },
methods: { methods: {
onDelete({ name }) { onDelete({ package: { id } }) {
this.$apollo.mutate({ this.$emit('delete', id);
mutation: deleteCorpusMutation,
variables: { name, projectPath: this.projectFullPath },
});
}, },
target(corpus) { target(corpus) {
return corpus.package.pipelines.nodes[0]?.ref; return corpus.package.pipelines.nodes[0]?.ref;
......
mutation deleteCorpus($projectPath: ID!, $name: String!) { mutation deleteCorpus($input: DestroyPackageInput!) {
deleteCorpus(projectPath: $projectPath, name: $name) @client { destroyPackage(input: $input) {
errors errors
} }
} }
...@@ -44,9 +44,6 @@ export default { ...@@ -44,9 +44,6 @@ export default {
}, },
}); });
}, },
deleteCorpus: () => {
// NO-OP
},
uploadCorpus: (_, { projectPath, name, files }, { cache, client }) => { uploadCorpus: (_, { projectPath, name, files }, { cache, client }) => {
const onUploadProgress = (e) => { const onUploadProgress = (e) => {
client.mutate({ client.mutate({
......
...@@ -8,11 +8,12 @@ import CorpusManagement from 'ee/security_configuration/corpus_management/compon ...@@ -8,11 +8,12 @@ import CorpusManagement from 'ee/security_configuration/corpus_management/compon
import CorpusTable from 'ee/security_configuration/corpus_management/components/corpus_table.vue'; import CorpusTable from 'ee/security_configuration/corpus_management/components/corpus_table.vue';
import CorpusUpload from 'ee/security_configuration/corpus_management/components/corpus_upload.vue'; import CorpusUpload from 'ee/security_configuration/corpus_management/components/corpus_upload.vue';
import getCorpusesQuery from 'ee/security_configuration/corpus_management/graphql/queries/get_corpuses.query.graphql'; import getCorpusesQuery from 'ee/security_configuration/corpus_management/graphql/queries/get_corpuses.query.graphql';
import deleteCorpusMutation from 'ee/security_configuration/corpus_management/graphql/mutations/delete_corpus.mutation.graphql';
import createMockApollo from 'helpers/mock_apollo_helper'; import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import { getCorpusesQueryResponse } from './mock_data'; import { getCorpusesQueryResponse, deleteCorpusMutationResponse } from './mock_data';
const TEST_PROJECT_FULL_PATH = '/namespace/project'; const TEST_PROJECT_FULL_PATH = '/namespace/project';
const TEST_CORPUS_HELP_PATH = '/docs/corpus-management'; const TEST_CORPUS_HELP_PATH = '/docs/corpus-management';
...@@ -22,10 +23,14 @@ describe('EE - CorpusManagement', () => { ...@@ -22,10 +23,14 @@ describe('EE - CorpusManagement', () => {
const createMockApolloProvider = ({ const createMockApolloProvider = ({
getCorpusesQueryRequestHandler = jest.fn().mockResolvedValue(getCorpusesQueryResponse), getCorpusesQueryRequestHandler = jest.fn().mockResolvedValue(getCorpusesQueryResponse),
deleteCorpusMutationHandler = jest.fn().mockResolvedValue(deleteCorpusMutationResponse),
} = {}) => { } = {}) => {
Vue.use(VueApollo); Vue.use(VueApollo);
const requestHandlers = [[getCorpusesQuery, getCorpusesQueryRequestHandler]]; const requestHandlers = [
[getCorpusesQuery, getCorpusesQueryRequestHandler],
[deleteCorpusMutation, deleteCorpusMutationHandler],
];
const mockResolvers = { const mockResolvers = {
Query: { Query: {
...@@ -178,6 +183,44 @@ describe('EE - CorpusManagement', () => { ...@@ -178,6 +183,44 @@ describe('EE - CorpusManagement', () => {
}); });
}); });
}); });
describe('corpus deletion', () => {
it('deletes the corpus', async () => {
const mutationVars = { input: { id: 1 } };
const getCorpusesQueryRequestHandler = jest
.fn()
.mockResolvedValue(getCorpusesQueryResponse);
const deleteCorpusMutationHandler = jest
.fn()
.mockResolvedValue(deleteCorpusMutationResponse);
createComponent({
apolloProvider: createMockApolloProvider({
getCorpusesQueryRequestHandler,
deleteCorpusMutationHandler,
}),
});
await waitForPromises();
expect(getCorpusesQueryRequestHandler).toHaveBeenCalledTimes(1);
const corpusTable = wrapper.findComponent(CorpusTable);
corpusTable.vm.$emit('delete', mutationVars.input.id);
await waitForPromises();
expect(deleteCorpusMutationHandler).toHaveBeenCalledWith(mutationVars);
expect(getCorpusesQueryRequestHandler).toHaveBeenCalledTimes(2);
expect(getCorpusesQueryRequestHandler).toHaveBeenNthCalledWith(2, {
afterCursor: '',
beforeCursor: '',
firstPageSize: 10,
lastPageSize: null,
projectPath: '/namespace/project',
});
});
});
}); });
describe('when loading', () => { describe('when loading', () => {
......
...@@ -5,6 +5,12 @@ import { corpuses } from './mock_data'; ...@@ -5,6 +5,12 @@ import { corpuses } from './mock_data';
const TEST_PROJECT_FULL_PATH = '/namespace/project'; const TEST_PROJECT_FULL_PATH = '/namespace/project';
const CORPUS = {
package: {
id: 1,
},
};
describe('Corpus table', () => { describe('Corpus table', () => {
let wrapper; let wrapper;
...@@ -13,18 +19,11 @@ describe('Corpus table', () => { ...@@ -13,18 +19,11 @@ describe('Corpus table', () => {
corpuses, corpuses,
}; };
const defaultMocks = {
$apollo: {
mutate: jest.fn().mockResolvedValue(),
},
};
wrapper = mount(CorpusTable, { wrapper = mount(CorpusTable, {
propsData: defaultProps, propsData: defaultProps,
provide: { provide: {
projectFullPath: TEST_PROJECT_FULL_PATH, projectFullPath: TEST_PROJECT_FULL_PATH,
}, },
mocks: defaultMocks,
...options, ...options,
}); });
}; };
...@@ -49,16 +48,11 @@ describe('Corpus table', () => { ...@@ -49,16 +48,11 @@ describe('Corpus table', () => {
expect(columnHeaders.element).toMatchSnapshot(); expect(columnHeaders.element).toMatchSnapshot();
}); });
it('triggers the corpus deletion mutation', () => { it('emits the delete event', () => {
const {
$apollo: { mutate },
} = wrapper.vm;
const actionComponent = wrapper.findComponent(Actions); const actionComponent = wrapper.findComponent(Actions);
actionComponent.vm.$emit('delete', CORPUS);
expect(mutate).not.toHaveBeenCalled(); expect(wrapper.emitted('delete')).toBeTruthy();
actionComponent.vm.$emit('delete', 'corpus-name'); expect(wrapper.emitted('delete')[0][0]).toEqual(CORPUS.package.id);
expect(mutate).toHaveBeenCalledTimes(1);
}); });
describe('with no corpuses', () => { describe('with no corpuses', () => {
......
...@@ -113,3 +113,11 @@ export const getCorpusesQueryResponse = { ...@@ -113,3 +113,11 @@ export const getCorpusesQueryResponse = {
}, },
}, },
}; };
export const deleteCorpusMutationResponse = {
data: {
destroyPackage: {
errors: {},
},
},
};
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