Skip to content

Commit

Permalink
Fix issue with next subject not loading reductions. Moved caesar redu…
Browse files Browse the repository at this point in the history
…ctions check out of Workflow Store and into SubjectStore.
  • Loading branch information
kieftrav committed Jan 9, 2024
1 parent 852291a commit 8c35319
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ InteractionLayer.propTypes = {
value: PropTypes.array
}).isRequired,
disabled: PropTypes.bool,
/** Index of the Frame. Initially inherits from parent component or overwritten with SubjectViewerStore */
frame: PropTypes.number,
height: PropTypes.number.isRequired,
marks: PropTypes.array,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ InteractionLayerContainer.propTypes = {
activeTool: PropTypes.object,
disabled: PropTypes.bool,
duration: PropTypes.number,
/** Index of the Frame. Initially inherits from parent component or overwritten with SubjectViewerStore */
frame: PropTypes.number,
height: PropTypes.number.isRequired,
interactionTaskAnnotations: PropTypes.array,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function SingleImageViewer({
rotate = 0,
scale = 1,
svgMaxHeight = null,
subject,
subject,
title = {},
viewBox,
width,
Expand Down Expand Up @@ -84,7 +84,7 @@ subject,
}

SingleImageViewer.propTypes = {
/** Index of the Frame */
/** Index of the Frame. Initially inherits from parent component or overwritten with SubjectViewerStore */
frame: PropTypes.number,
/** Passed from container */
enableInteractionLayer: PropTypes.bool,
Expand Down
14 changes: 10 additions & 4 deletions packages/lib-classifier/src/hooks/useFreehandLineReductions.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ export default function useFreehandLineReductions() {
workflowSteps: {
active: step,
findTasksByType
},
subjects: {
active: activeSubject,
reductionsLoadedForSubject,
setReductionsLoadedForSubject,
}
} = useStores()

// We only want to create and load the marks per workflow-step
// Switching SubjectViewers destroys the reduction model so we need to store loaded state in the workflow as well
// We only want to create and load the marks per subject
// Switching SubjectViewers destroys the local reduction model so we need to store loaded state in the SubjectStore
// We also need to know that the marks have been found, used, and added to the tool (marksUsed variable)

let reductionsLoaded = workflow.reductionsLoadedForStep(step.stepKey);
let reductionsLoaded = reductionsLoadedForSubject(activeSubject.id);
const { loaded, caesarReductions } = useCaesarReductions(workflow.caesarReducer)


if (loaded && getType(caesarReductions).name === 'FreehandLineReductions') {
if (reductionsLoaded) return;

Expand All @@ -43,7 +49,7 @@ export default function useFreehandLineReductions() {
})

if (marksUsed) {
workflow.setReductionsLoadedForStep(step.stepKey)
setReductionsLoadedForSubject(activeSubject.id)
caesarReductions.setIsUsed()
}
}
Expand Down
11 changes: 11 additions & 0 deletions packages/lib-classifier/src/store/SubjectStore/SubjectStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const SubjectStore = types
.model('SubjectStore', {
active: types.safeReference(SubjectType),
available: types.optional(AvailableSubjects, () => AvailableSubjects.create({})),
caesarReductionsLoadedForSubject: types.array(types.string),
queue: types.array(types.safeReference(SubjectType)),
resources: types.map(SubjectType),
type: types.optional(types.string, 'subjects')
Expand Down Expand Up @@ -70,6 +71,10 @@ const SubjectStore = types
const { workflows } = getRoot(self)
const workflow = tryReference(() => workflows?.active)
return workflow?.prioritized
},

reductionsLoadedForSubject(activeSubjectId) {
return self.caesarReductionsLoadedForSubject.indexOf(activeSubjectId) !== -1;
}
}))

Expand Down Expand Up @@ -358,6 +363,10 @@ const SubjectStore = types
self.onReset = callback
}

function setReductionsLoadedForSubject (activeSubjectId) {
self.caesarReductionsLoadedForSubject.push(activeSubjectId);
}

function setResources(subjects = []) {
if (subjects.length > 0) {
try {
Expand All @@ -373,6 +382,7 @@ const SubjectStore = types
}
}
}

/** Shift the subject queue by one subject, so that the active subject is always the first subject. */
function shift() {
const subject = tryReference(() => self.active)
Expand Down Expand Up @@ -403,6 +413,7 @@ const SubjectStore = types
reset,
setActiveSubject,
setOnReset,
setReductionsLoadedForSubject,
setResources,
shift
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const WorkflowStep = types.refinement(
const Workflow = types
.model('Workflow', {
active: types.optional(types.boolean, false),
caesarReductionsLoadedForStep: types.array(types.string),
configuration: WorkflowConfiguration,
display_name: types.string,
first_task: types.optional(types.string, ''),
Expand Down Expand Up @@ -90,10 +89,6 @@ const Workflow = types
})

return anyFreehandLineTool
},

reductionsLoadedForStep(stepKey) {
return self.caesarReductionsLoadedForStep.indexOf(stepKey) !== -1;
}
}))

Expand All @@ -111,12 +106,7 @@ const Workflow = types
}

return {
selectSubjectSet: flow(selectSubjectSet),

setReductionsLoadedForStep (stepKey) {
self.caesarReductionsLoadedForStep.push(stepKey);
console.log('push the damn key', self.caesarReductionsLoadedForStep);
}
selectSubjectSet: flow(selectSubjectSet)
}
})

Expand Down

0 comments on commit 8c35319

Please sign in to comment.