Skip to content

Fixing up logic around selecting/deselecting nested labels #13

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

Merged
merged 6 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
24 changes: 24 additions & 0 deletions src/examples/nested_labels/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<View>
<Choices name="has_math_choice" toName="interaction" choice="single" showInLine="true">
<Choice value="This thread has math"/>
<Choice value="This thread does not have math"/>
</Choices>

<View style="top: 0; position: sticky; z-index: 5; background: white" visibleWhen="choice-selected" whenTagName="has_math_choice" whenChoiceValue="This thread has math">
<Labels name="interaction_correctness" toName="interaction">
<Label value="Correct" hotkey="c" hint="This statement is accurate and pedagogically sound" granularity="div" background="green"/>
<Label value="Incorrect: Khanmigo" hotkey="k" granularity="div" background="red"/>
<Label value="Incorrect: Student" hotkey="s" granularity="div" background="orange"/>
</Labels>
</View>

<View style="position: sticky; top: 32px; z-index: 5; background: white" visibleWhen="region-selected" whenTagName="interaction_correctness" whenLabelValue="Incorrect: Khanmigo">
<Labels name="khanmigo_incorrect_type" toName="interaction">
<Label alias="type-incorrect" value="Wrong calculation" hotkey="w" hint="Khanmigo calculates incorrectly, e.g. 2+2=5" granularity="div" background="pink"/>
<Label alias="type-process" value="Wrong process" hotkey="p" hint="Khanmigo suggests a bad method, e.g. 'to find 2+2 you must divide'" granularity="div" background="purple"/>
<Label alias="type-other" value="Other" hotkey="o" hint="Use this label for any noteworthy issue that is not addressed by other labels; elaborate in Labeler Notes" granularity="div" background="blue"/>
</Labels>
</View>

<TableText name="interaction" value="$json_thread" granularity="word"/>
</View>
5 changes: 5 additions & 0 deletions src/examples/nested_labels/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import config from './config.xml';
import tasks from './tasks.json';
import annotation from './annotations/nested-labels.json';

export const NestedLabels = { config, tasks, annotation };
24 changes: 24 additions & 0 deletions src/tags/control/Label.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,30 @@ const Model = types.model({
// if that's the only selected label, the only labelset assigned to region,
// and we are trying to unselect it, then don't allow that
// (except for rare labelsets that allow empty labels)

// Don't allow selecting a different top-level label when we've already labeled it: DI-1502
if (
labels.selectedLabels.length === 1 &&
!self.selected &&
labels.selectedLabels[0].value !== self.value &&
!labels.selectedLabels[0].alias // Hack: we only gave sub-labels aliases
) {
return false;
}

// If this is only top level label and there are sub labels, don't allow deselect
if (
labels.selectedLabels.length === 1 &&
self.selected &&
labels.selectedLabels[0].value == self.value &&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <eqeqeq> reported by reviewdog 🐶
Expected '===' and instead saw '=='.

!labels.selectedLabels[0].alias && // Hack: we only gave sub-labels aliases
region.labelings.length > 1
) {
console.log('can\'t deselect top level label w sub label!')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [eslint] <semi> reported by reviewdog 🐶
Missing semicolon.

Suggested change
console.log('can\'t deselect top level label w sub label!')
console.log('can\'t deselect top level label w sub label!');


return false;
}

if (
labels.selectedLabels.length === 1 &&
self.selected &&
Expand Down
Loading