Skip to content

Commit

Permalink
Update review mode (#604)
Browse files Browse the repository at this point in the history
* Fix review mode toggle not accepting initial value

* Update review mode (always show all scans)

* Change pyppeteer test
  • Loading branch information
annehaley authored Sep 29, 2022
1 parent f00fea7 commit 36ef5b2
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 86 deletions.
17 changes: 1 addition & 16 deletions miqa/core/tests/pyppeteer/test_save_decisions.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,9 @@ async def test_save_decisions_tier_1(
).click()
await page.waitFor(1_000)

# Go back up a scan and confirm the previous decision marked all artifacts as present
await (await page.waitForXPath('//i[contains(@class, "fa-caret-up")]')).click()
saved_artifacts = await page.xpath(
'//div[contains(., "No comment")]/following-sibling::div/'
'span/span[contains(@class,"v-chip__content")]'
)
assert len(saved_artifacts) == len(artifact_chips)

# Submit another decision on the third scan
# This time marking all artifacts as absent and the scan as Usable
await page.goBack()
artifact_chips = await page.xpath('//span[contains(@class,"v-chip__content")]')
for chip in artifact_chips:
# clicking twice marks the artifact as absent
Expand All @@ -92,14 +85,6 @@ async def test_save_decisions_tier_1(
).click()
await page.waitFor(1_000)

# Go back up a scan and confirm the previous decision marked all artifacts as absent
await (await page.waitForXPath('//i[contains(@class, "fa-caret-up")]')).click()
saved_artifacts = await page.xpath(
'//div[contains(., "I disagree")]/following-sibling::div/'
'span/span[contains(@class,"v-chip__content")]'
)
assert len(saved_artifacts) == 0

# Go back to the project page
await (await page.waitForXPath('//a[contains(., "Projects")]')).click()
await (
Expand Down
41 changes: 17 additions & 24 deletions web_client/src/components/ExperimentsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from 'vuex';
import UserAvatar from '@/components/UserAvatar.vue';
import djangoRest from '@/django';
import { includeScan } from '@/store';
import { API_URL, decisionOptions } from '../constants';
export default {
Expand Down Expand Up @@ -72,6 +73,7 @@ export default {
...mapActions([
'loadProject',
]),
includeScan,
scansForExperiment(expId) {
const expScanIds = this.experimentScans[expId];
return expScanIds.filter(
Expand Down Expand Up @@ -179,41 +181,30 @@ export default {

<template>
<v-card class="flex-card">
<v-subheader
v-if="!minimal"
<div
class="d-flex"
style="justify-content: space-between"
style="justify-content: space-between; align-items: baseline"
>
Experiments
<div
class="d-flex mode-toggle"
<v-subheader
v-if="!minimal"
style="display: inline"
>
Experiments
</v-subheader>
<v-subheader
class="mode-toggle"
>
<span>All scans</span>
<v-switch
:value="reviewMode"
inset
:input-value="true"
dense
style="display: inline-block; max-height: 40px; max-width: 60px;"
class="px-3 ma-0"
@change="switchReviewMode"
/>
<span>Scans for my review</span>
</div>
</v-subheader>
<v-subheader
v-if="minimal"
class="d-flex mode-toggle"
>
<span>All scans</span>
<v-switch
:value="reviewMode"
dense
style="display: inline-block; max-height: 40px; max-width: 60px;"
class="px-3 ma-0"
@change="switchReviewMode"
/>
<span>Scans for my review</span>
</v-subheader>
</v-subheader>
</div>
<div class="scans-view">
<div v-if="orderedExperiments && orderedExperiments.length">
<ul class="experiment">
Expand Down Expand Up @@ -255,6 +246,7 @@ export default {
<v-btn
v-bind="attrs"
:to="getURLForFirstFrameInScan(scan.id)"
:disabled="!includeScan(scan.id)"
class="ml-0 px-1 scan-name"
href
text
Expand Down Expand Up @@ -466,6 +458,7 @@ ul.scans {
}
.mode-toggle {
align-items: baseline;
display: inline-block;
}
.add-scans {
min-width: 150px;
Expand Down
84 changes: 38 additions & 46 deletions web_client/src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function startReaderWorkerPool() {
});
}

function queueLoadScan(scan, loadNext = false) {
function queueLoadScan(scan, loadNext = 0) {
// load all frames in target scan
if (!loadedData.includes(scan.id)) {
store.state.scanFrames[scan.id].forEach(
Expand All @@ -217,10 +217,7 @@ function queueLoadScan(scan, loadNext = false) {
loadedData.push(scan.id);
}

// semi-recursive; we only recurse on the first call
// to queue up the next scan as well
// to prefetch further ahead, modify the recursion
if (loadNext) {
if (loadNext > 0) {
const scansInSameExperiment = store.state.experimentScans[scan.experiment];
let nextScan;
if (scan.id === scansInSameExperiment[scansInSameExperiment.length - 1]) {
Expand All @@ -229,17 +226,21 @@ function queueLoadScan(scan, loadNext = false) {
const nextExperimentId = experimentIds[experimentIds.indexOf(scan.experiment) + 1];
const nextExperimentScans = store.state.experimentScans[nextExperimentId];
if (nextExperimentScans && nextExperimentScans.length > 0) {
nextScan = store.state.allScans[
nextScan = store.state.scans[
nextExperimentScans[0]
];
}
} else {
// load next scan in same experiment
nextScan = store.state.allScans[scansInSameExperiment[
scansInSameExperiment.indexOf(scan.id) + 1
]];
let offset = 1;
while (!nextScan || !includeScan(nextScan.id)) {
// load next scan in same experiment
nextScan = store.state.scans[scansInSameExperiment[
scansInSameExperiment.indexOf(scan.id) + offset
]];
offset += 1;
}
}
if (nextScan) queueLoadScan(nextScan);
if (nextScan) queueLoadScan(nextScan, loadNext - 1);
startReaderWorkerPool();
}
}
Expand Down Expand Up @@ -278,17 +279,32 @@ function expandScanRange(frameId, dataRange) {
}
}

export function includeScan(scanId) {
if (store.state.reviewMode) {
const myRole = store.state.currentTaskOverview?.my_project_role;
const scanState = store.state.currentTaskOverview?.scan_states[scanId];
switch (scanState) {
case 'unreviewed':
return true;
case 'complete':
return false;
default:
return myRole === 'tier_2_reviewer';
}
}
return true;
}

const initState = {
MIQAConfig: {},
me: null,
allUsers: [],
reviewMode: false,
reviewMode: true,
globalSettings: undefined as ProjectSettings,
currentProject: undefined as Project | null,
currentTaskOverview: null as ProjectTaskOverview | null,
currentProjectPermissions: {},
projects: [] as Project[],
allScans: {},
experimentIds: [],
experiments: {},
experimentScans: {},
Expand Down Expand Up @@ -349,14 +365,11 @@ const {
const project = state.projects.filter((x) => x.id === experiment.project)[0];
const experimentScansList = state.experimentScans[experiment.id];
const scanFramesList = state.scanFrames[scan.id];
let upTo = currentFrame.firstFrameInPreviousScan;
let downTo = currentFrame.firstFrameInNextScan;
if (upTo && !Object.keys(state.scans).includes(state.frames[upTo].scan)) {
upTo = null;
}
if (downTo && !Object.keys(state.scans).includes(state.frames[downTo].scan)) {
downTo = null;
}

const scanOrder = Object.values(state.experimentScans).flat().filter(includeScan);
const currIndexInOrder = scanOrder.indexOf(scan.id);
const upTo = scanOrder[currIndexInOrder - 1];
const downTo = scanOrder[currIndexInOrder + 1];
return {
projectId: project.id,
projectName: project.name,
Expand All @@ -374,8 +387,8 @@ const {
framePositionString: `(${scanFramesList.indexOf(currentFrame.id) + 1}/${scanFramesList.length})`,
backTo: currentFrame.previousFrame,
forwardTo: currentFrame.nextFrame,
upTo,
downTo,
upTo: state.scanFrames[upTo] ? state.scanFrames[upTo][0] : undefined,
downTo: state.scanFrames[downTo] ? state.scanFrames[downTo][0] : undefined,
currentFrame,
currentAutoEvaluation: currentFrame.frame_evaluation,
};
Expand Down Expand Up @@ -453,7 +466,6 @@ const {
// Replace with a new object to trigger a Vuex update
state.scans = { ...state.scans };
state.scans[scanId] = scan;
state.allScans = Object.assign(state.allScans, state.scans);
},
setRenderOrientation(state, anatomy) {
state.renderOrientation = anatomy;
Expand Down Expand Up @@ -482,7 +494,7 @@ const {
}
if (state.currentProject && taskOverview.project_id === state.currentProject.id) {
state.currentTaskOverview = taskOverview;
Object.values(store.state.allScans).forEach((scan: Scan) => {
Object.values(store.state.scans).forEach((scan: Scan) => {
if (taskOverview.scan_states[scan.id] && taskOverview.scan_states[scan.id] !== 'unreviewed') {
store.dispatch.reloadScan(scan.id);
}
Expand Down Expand Up @@ -573,26 +585,6 @@ const {
},
switchReviewMode(state, mode) {
state.reviewMode = mode || false;
if (mode) {
const myRole = state.currentTaskOverview.my_project_role;
state.scans = Object.fromEntries(
Object.entries(state.allScans).filter(
([scanId]) => {
const scanState = state.currentTaskOverview.scan_states[scanId];
switch (scanState) {
case 'unreviewed':
return true;
case 'complete':
return false;
default:
return myRole === 'tier_2_reviewer';
}
},
),
);
} else {
state.scans = state.allScans;
}
},
},
actions: {
Expand Down Expand Up @@ -767,7 +759,7 @@ const {

if (newScan !== oldScan && newScan) {
queueLoadScan(
newScan, true,
newScan, 3,
);
}

Expand Down

0 comments on commit 36ef5b2

Please sign in to comment.