Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Do Not Merge] Temporary Fix to Pull Original Subjects for ASM #167

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/screens/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
22 changes: 21 additions & 1 deletion src/store/SubjectStore.js
Original file line number Diff line number Diff line change
@@ -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', {
Expand All @@ -14,7 +15,26 @@ 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 && 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) {
// This is temporary while we test
id = yield self.originalSubjectCheck(id)

self.asyncState = ASYNC_STATES.LOADING
try {
const [subject] = yield apiClient.type('subjects').get({ id })
Expand Down
17 changes: 14 additions & 3 deletions src/store/TranscriptionsStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -205,18 +205,25 @@ 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") {
data, userId, classificationAt
}
}
}`

let validExtracts = []
yield request(config.caesar, query).then((data) => {
const filteredExtracts = data.workflow.extracts.filter(extract => Object.entries(extract.data).length > 0)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -573,7 +584,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
},
Expand Down