From 6f9cc1de2e7fddcc9dc12658d008beb4d3ad9ee5 Mon Sep 17 00:00:00 2001 From: Will Granger Date: Tue, 2 Jun 2020 16:26:42 -0500 Subject: [PATCH 1/3] Hacky Solution --- src/config.js | 3 +++ src/screens/Editor/Editor.js | 2 +- src/store/SubjectStore.js | 21 ++++++++++++++++++++- src/store/TranscriptionsStore.js | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/config.js b/src/config.js index fd514d34..ae93a1bc 100644 --- a/src/config.js +++ b/src/config.js @@ -8,6 +8,9 @@ if (!env.match(/^(production|staging|development|test)$/)) { throw new Error(`Error: Invalid Environment - ${env}`); } +export const ASM_COLLABORATIVE_ID = '5339' +export const ASM_INDIVIDUAL_ID = '5329' + const baseConfig = { development: { caesar: 'https://caesar-staging.zooniverse.org/graphql', diff --git a/src/screens/Editor/Editor.js b/src/screens/Editor/Editor.js index 27fdca17..131f54de 100644 --- a/src/screens/Editor/Editor.js +++ b/src/screens/Editor/Editor.js @@ -30,8 +30,8 @@ function Editor ({ match, testTime }) { let accessTime = new Date() const setResources = async () => { - await store.subjects.fetchSubject(match.params.subject) await store.getResources(match.params) + await store.subjects.fetchSubject(match.params.subject) if (!store.transcriptions.lockedByCurrentUser) { store.modal.toggleModal(MODALS.LOCKED) } diff --git a/src/store/SubjectStore.js b/src/store/SubjectStore.js index 4f83eb2f..fc22f4a0 100644 --- a/src/store/SubjectStore.js +++ b/src/store/SubjectStore.js @@ -1,6 +1,7 @@ -import { flow, types } from 'mobx-state-tree' +import { flow, getRoot, types } from 'mobx-state-tree' import apiClient from 'panoptes-client/lib/api-client.js' import ASYNC_STATES from 'helpers/asyncStates' +import { ASM_INDIVIDUAL_ID, ASM_COLLABORATIVE_ID } from 'config' const Subject = types .model('Subject', { @@ -14,7 +15,25 @@ const SubjectStore = types.model('SubjectStore', { current: types.optional(Subject, {}), error: types.optional(types.string, ''), }).actions(self => ({ + originalSubjectCheck: flow (function * originalSubjectCheck (id) { + const workflows = getRoot(self).workflows + + if (workflows.current.id === ASM_INDIVIDUAL_ID) { + const { current } = getRoot(self).transcriptions + const { client } = getRoot(self) + + const response = yield client.get(`/transcriptions?filter[workflow_id_eq]=${ASM_COLLABORATIVE_ID}&filter[internal_id_eq]=${current.internal_id}`) + const resources = JSON.parse(response.body) + if (resources.data.length) { + id = resources.data[0].id + } + } + return id + }), + fetchSubject: flow (function * fetchSubject (id) { + id = yield self.originalSubjectCheck(id) + self.asyncState = ASYNC_STATES.LOADING try { const [subject] = yield apiClient.type('subjects').get({ id }) diff --git a/src/store/TranscriptionsStore.js b/src/store/TranscriptionsStore.js index 040ca0be..57dfedf4 100644 --- a/src/store/TranscriptionsStore.js +++ b/src/store/TranscriptionsStore.js @@ -573,7 +573,7 @@ const TranscriptionsStore = types.model('TranscriptionsStore', { get lockedByCurrentUser () { const login = getRoot(self).auth.user && getRoot(self).auth.user.login; if (login && self.current) { - return self.current.locked_by && self.current.locked_by === login + return self.current && self.current.locked_by && self.current.locked_by === login } return false }, From 00348f7c810e9e96a133b0fc71689676c2ed53a1 Mon Sep 17 00:00:00 2001 From: Will Granger Date: Wed, 3 Jun 2020 09:37:18 -0500 Subject: [PATCH 2/3] Fetch Original Subject Extracts --- src/store/SubjectStore.js | 1 + src/store/TranscriptionsStore.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/store/SubjectStore.js b/src/store/SubjectStore.js index fc22f4a0..8cfa4c53 100644 --- a/src/store/SubjectStore.js +++ b/src/store/SubjectStore.js @@ -32,6 +32,7 @@ const SubjectStore = types.model('SubjectStore', { }), fetchSubject: flow (function * fetchSubject (id) { + // This is temporary while we test id = yield self.originalSubjectCheck(id) self.asyncState = ASYNC_STATES.LOADING diff --git a/src/store/TranscriptionsStore.js b/src/store/TranscriptionsStore.js index 57dfedf4..59827c9e 100644 --- a/src/store/TranscriptionsStore.js +++ b/src/store/TranscriptionsStore.js @@ -12,7 +12,7 @@ import { getPage, getSlopeLabel, isolateGroups } from 'helpers/slopeHelpers' import getError, { TranscriptionError } from 'helpers/getError' import MODALS from 'helpers/modals' import STATUS from 'helpers/status' - +import { ASM_INDIVIDUAL_ID, ASM_COLLABORATIVE_ID } from 'config' import Reduction from './Reduction' let Frame = types.array(Reduction) @@ -205,11 +205,17 @@ const TranscriptionsStore = types.model('TranscriptionsStore', { } const fetchExtracts = flow(function * fetchExtracts(id) { - const workflowId = getRoot(self).workflows.current.id + let workflowId = getRoot(self).workflows.current.id // TODO: The extractor key below will need to change eventually. This is just // to test the code with ASM staging data. In the future, this will change to // 'alice' once current extractors have been backfilled with duplicate extractors // with the correct 'alice' key. + + // This is temporary while we test + if (workflowId === ASM_INDIVIDUAL_ID) { + workflowId = ASM_COLLABORATIVE_ID + } + const query = `{ workflow(id: ${workflowId}) { extracts(subjectId: ${id}, extractorKey: "alice") { @@ -217,6 +223,7 @@ const TranscriptionsStore = types.model('TranscriptionsStore', { } } }` + let validExtracts = [] yield request(config.caesar, query).then((data) => { const filteredExtracts = data.workflow.extracts.filter(extract => Object.entries(extract.data).length > 0) @@ -432,6 +439,10 @@ const TranscriptionsStore = types.model('TranscriptionsStore', { self.current = id self.asyncState = ASYNC_STATES.READY }) + + // This is temporary while we test + id = yield getRoot(self).subjects.originalSubjectCheck(id) + yield self.fetchExtracts(id) self.getSlopeKeys(false) } catch (error) { From 37f4fefb58ae85be41589e3b6c3033bd30e6b04d Mon Sep 17 00:00:00 2001 From: Will Granger Date: Wed, 3 Jun 2020 14:34:05 -0500 Subject: [PATCH 3/3] Conditionally check current workflow --- src/store/SubjectStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/SubjectStore.js b/src/store/SubjectStore.js index 8cfa4c53..251fba1e 100644 --- a/src/store/SubjectStore.js +++ b/src/store/SubjectStore.js @@ -18,7 +18,7 @@ const SubjectStore = types.model('SubjectStore', { originalSubjectCheck: flow (function * originalSubjectCheck (id) { const workflows = getRoot(self).workflows - if (workflows.current.id === ASM_INDIVIDUAL_ID) { + if (workflows.current && workflows.current.id === ASM_INDIVIDUAL_ID) { const { current } = getRoot(self).transcriptions const { client } = getRoot(self)