11import { getParent , types } from 'mobx-state-tree' ;
2+ import { FF_LSDV_4583 , isFF } from '../utils/feature-flags' ;
23
34const RequiredMixin = types
45 . model ( {
@@ -13,10 +14,10 @@ const RequiredMixin = types
1314 // validating when choices labeling is done per region,
1415 // for example choice may be required to be selected for
1516 // every bbox
16- const objectTag = self . annotation . names . get ( self . toname ) ;
17+ const objectTag = self . toNameTag ;
1718
1819 // if regions don't meet visibility conditions skip validation
19- for ( const reg of objectTag . regs ) {
20+ for ( const reg of objectTag . allRegs ) {
2021 const s = reg . results . find ( s => s . from_name === self ) ;
2122
2223 if ( self . visiblewhen === 'region-selected' ) {
@@ -35,6 +36,27 @@ const RequiredMixin = types
3536 self . annotation . selectArea ( reg ) ;
3637 self . requiredModal ( ) ;
3738
39+ return false ;
40+ }
41+ }
42+ } else if ( isFF ( FF_LSDV_4583 ) && self . peritem ) {
43+ // validating when choices labeling is done per item,
44+ const objectTag = self . toNameTag ;
45+ const maxItemIndex = objectTag . maxItemIndex ;
46+ const existingResultsIndexes = self . annotation . regions
47+ . reduce ( ( existingResultsIndexes , reg ) => {
48+ const result = reg . results . find ( s => s . from_name === self ) ;
49+
50+ if ( result ?. hasValue ) {
51+ existingResultsIndexes . add ( reg . item_index ) ;
52+ }
53+ return existingResultsIndexes ;
54+ } , new Set ( ) ) ;
55+
56+ for ( let idx = 0 ; idx <= maxItemIndex ; idx ++ ) {
57+ if ( ! existingResultsIndexes . has ( idx ) ) {
58+ objectTag . setCurrentItem ( idx ) ;
59+ self . requiredModal ( ) ;
3860 return false ;
3961 }
4062 }
0 commit comments