@@ -35,6 +35,7 @@ export type ResolvedIssueControl = ResolvedIssueControlOptions &
3535 | {
3636 type : 'toggle'
3737 id ?: string
38+ unselectToggles ?: readonly string [ ]
3839 issueCardDisplay ?: {
3940 icon ?: string
4041 label : string
@@ -329,11 +330,11 @@ export function createReviewPanels(
329330 const bindings = new Map < string , ReviewPanelBinding > ( )
330331 const projectV3 = project . value
331332 if ( ! projectV3 ) return bindings
332- const issueIds = preview
333- ? [ ...new Set ( [ ...selectedIssueIds . value , preview . control . issueId ] ) ]
334- : selectedIssueIds . value
335333 const toggleIds = ( issueId : string ) => {
336334 const ids = new Set ( selectedToggleIds ( projectV3 . id , issueId ) )
335+ if ( preview ?. control . type === 'toggle' ) {
336+ for ( const id of preview . control . unselectToggles ?? [ ] ) ids . delete ( id )
337+ }
337338 if ( preview ?. control . type === 'toggle' && preview . control . issueId === issueId ) {
338339 for ( const id of preview . control . childToggleIds ??
339340 ( preview . control . id === undefined ? [ ] : [ preview . control . id ] ) ) {
@@ -342,6 +343,17 @@ export function createReviewPanels(
342343 }
343344 return [ ...ids ]
344345 }
346+ const issueIds = preview
347+ ? [
348+ ...new Set ( [
349+ ...selectedIssueIds . value . filter (
350+ ( id ) =>
351+ session . read ( projectV3 . id , 'issue-active' ) [ id ] === true || toggleIds ( id ) . length > 0 ,
352+ ) ,
353+ preview . control . issueId ,
354+ ] ) ,
355+ ]
356+ : selectedIssueIds . value
345357 const showAllIssueControls = reviewData . value . showAllIssueControls === true
346358 const context : ReviewContext = {
347359 projectV3,
@@ -430,6 +442,7 @@ export function createReviewPanels(
430442 ...options ,
431443 type : 'toggle' ,
432444 id : node . id ,
445+ unselectToggles : node . unselectToggles ,
433446 issueCardDisplay : node . issueCardDisplay
434447 ? {
435448 icon : resolveWithContext ( node . issueCardDisplay . icon , issueContext ) ,
@@ -522,6 +535,14 @@ export function createReviewPanels(
522535 control . childToggleIds = children . flatMap ( ( item ) =>
523536 item . type === 'toggle' && ! item . disabled && item . id ? [ item . id ] : [ ] ,
524537 )
538+ control . unselectToggles = [
539+ ...new Set ( [
540+ ...( control . unselectToggles ?? [ ] ) ,
541+ ...children . flatMap ( ( item ) =>
542+ item . type === 'toggle' && ! item . disabled ? ( item . unselectToggles ?? [ ] ) : [ ] ,
543+ ) ,
544+ ] ) ,
545+ ]
525546 control . disabled ||= control . childToggleIds . length === 0
526547 }
527548 }
@@ -645,6 +666,16 @@ export function createReviewPanels(
645666 return
646667 }
647668 if ( typeof value !== 'boolean' ) return
669+ if ( value && current . unselectToggles ?. length ) {
670+ const toggleIdsToUnselect = new Set ( current . unselectToggles )
671+ for ( const [ issueId , selected ] of Object . entries ( session . read ( binding . projectId , 'issues' ) ) ) {
672+ if ( ! ( selected instanceof Set ) || ! [ ...selected ] . some ( ( id ) => toggleIdsToUnselect . has ( id ) ) )
673+ continue
674+ const keys = new Set ( [ ...selected ] . filter ( ( id ) => ! toggleIdsToUnselect . has ( id ) ) )
675+ session . write ( binding . projectId , 'issues' , issueId , keys . size ? keys : undefined )
676+ if ( issueId !== current . issueId ) updateIssueOrder ( binding . projectId , issueId )
677+ }
678+ }
648679 if ( current . childToggleIds ) {
649680 const keys = new Set ( selectedToggleIds ( binding . projectId , current . issueId ) )
650681 for ( const id of current . childToggleIds ) {
@@ -839,22 +870,21 @@ export function createReviewPanels(
839870 sharedInputs . textValues [ control . key ] = textValue ( binding , control )
840871 continue
841872 }
873+ const previewSelected =
874+ control . type === 'toggle' &&
875+ control . issueId === preview ?. control . issueId &&
876+ preview . control . type === 'toggle' &&
877+ ( control . id === preview . control . id ||
878+ ( control . id !== undefined && preview . control . childToggleIds ?. includes ( control . id ) ) )
842879 if (
843880 control . childToggleIds ||
844881 control . disabled ||
845882 ( control . type === 'toggle' &&
846- ! (
847- binding . key === preview ?. binding . key &&
848- control . issueId === preview . control . issueId &&
849- preview . control . type === 'toggle' &&
850- control . id === preview . control . id
851- ) &&
852- ! (
853- control . issueId === preview ?. control . issueId &&
854- control . id !== undefined &&
855- preview . control . childToggleIds ?. includes ( control . id )
856- ) &&
857- ! selected ( binding , control ) )
883+ ! previewSelected &&
884+ ( ! selected ( binding , control ) ||
885+ ( preview ?. control . type === 'toggle' &&
886+ control . id !== undefined &&
887+ preview . control . unselectToggles ?. includes ( control . id ) ) ) )
858888 )
859889 continue
860890 const selection : IssueSelection = issues . get ( control . issueId ) ?? {
@@ -896,7 +926,7 @@ export function createReviewPanels(
896926 selected : {
897927 items : { } ,
898928 issueIds : preview
899- ? [ ...new Set ( [ ... selectedIssueIds . value , preview . control . issueId ] ) ]
929+ ? [ ...issues ] . filter ( ( [ , { active } ] ) => active ) . map ( ( [ id ] ) => id )
900930 : selectedIssueIds . value ,
901931 toggleIds : [ ...keys ] ,
902932 } ,
0 commit comments