Commit 13ebe8bf authored by Fernando Arias's avatar Fernando Arias

First pass at corpus upload commit

* Store package ID on upload
parent e8f11cc0
mutation uploadComplete($projectPath: ID!, $packageId: Int!) {
uploadComplete(projectPath: $projectPath, packageId: $packageId) @client {
errors
}
}
......@@ -7,5 +7,6 @@ query getCorpuses($projectPath: ID!) {
isUploading
progress
cancelSource
uploadedPackageId
}
}
......@@ -4,6 +4,7 @@ import { publishPackage } from '~/api/packages_api';
import axios from '~/lib/utils/axios_utils';
import getCorpusesQuery from '../queries/get_corpuses.query.graphql';
import updateProgress from '../mutations/update_progress.mutation.graphql';
import uploadComplete from '../mutations/upload_complete.mutation.graphql';
export default {
Query: {
......@@ -22,6 +23,7 @@ export default {
isUploading: false,
progress: 0,
cancelSource: null,
uploadedPackageId: null,
__typename: 'UploadState',
};
},
......@@ -91,19 +93,43 @@ export default {
variables: { projectPath },
});
const data = produce(sourceData, (draftState) => {
const targetData = produce(sourceData, (draftState) => {
const { uploadState } = draftState;
uploadState.isUploading = true;
uploadState.cancelSource = source;
});
cache.writeQuery({ query: getCorpusesQuery, data, variables: { projectPath } });
cache.writeQuery({ query: getCorpusesQuery, targetData, variables: { projectPath } });
publishPackage(
{ projectPath, name, version: 0, fileName: name, files },
{ status: 'hidden', select: 'package_file' },
{ onUploadProgress, cancelToken: source.token },
);
)
.then(({ data }) => {
client.mutate({
mutation: uploadComplete,
variables: { projectPath, packageId: data.package_id },
});
})
.catch((e) => {
/* TODO: Error handling */
});
},
uploadComplete: (_, { projectPath, packageId }, { cache }) => {
const sourceData = cache.readQuery({
query: getCorpusesQuery,
variables: { projectPath },
});
const data = produce(sourceData, (draftState) => {
const { uploadState } = draftState;
uploadState.isUploading = false;
uploadState.cancelSource = null;
uploadState.uploadedPackageId = packageId;
});
cache.writeQuery({ query: getCorpusesQuery, data, variables: { projectPath } });
},
updateProgress: (_, { projectPath, progress }, { cache }) => {
const sourceData = cache.readQuery({
......@@ -115,11 +141,6 @@ export default {
const { uploadState } = draftState;
uploadState.isUploading = true;
uploadState.progress = progress;
if (progress >= 100) {
uploadState.isUploading = false;
uploadState.cancelSource = null;
}
});
cache.writeQuery({ query: getCorpusesQuery, data, variables: { projectPath } });
......
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