@@ -5,19 +5,23 @@ import {
55} from "@knocklabs/client" ;
66import { useGuideContext , useStore } from "@knocklabs/react-core" ;
77
8- export const checkEligible = ( guide : AnnotatedGuide | MissingGuide ) => {
9- if ( guide . __typename === "MissingGuide" ) return false ;
10- if ( ! guide . annotation . active . status ) return false ;
11- if ( ! guide . annotation . targetable . status ) return false ;
12- if ( guide . annotation . archived . status ) return false ;
13-
8+ const resolveIsEligible = ( {
9+ active,
10+ targetable,
11+ archived,
12+ } : Pick < GuideAnnotation , "active" | "targetable" | "archived" > ) => {
13+ if ( ! active . status ) return false ;
14+ if ( ! targetable . status ) return false ;
15+ if ( archived . status ) return false ;
1416 return true ;
1517} ;
1618
19+ // Active: `true` status = good
1720type ActiveStatus = {
1821 status : boolean ;
1922} ;
2023
24+ // Targetable: `true` status = good
2125type TargetableStatusTrue = {
2226 status : true ;
2327} ;
@@ -28,18 +32,26 @@ type TargetableStatusFalse = {
2832} ;
2933type TargetableStatus = TargetableStatusTrue | TargetableStatusFalse ;
3034
35+ // Archived: `false` status = good
3136type ArchivedStatus = {
3237 status : boolean ;
3338} ;
3439
40+ type AnnotatedStatuses = {
41+ // Individual eligibility statuses:
42+ active : ActiveStatus ;
43+ targetable : TargetableStatus ;
44+ archived : ArchivedStatus ;
45+ } ;
46+
47+ export type GuideAnnotation = AnnotatedStatuses & {
48+ // Resolved eligibility based on active, targetable and archived statuses,
49+ // which are backend driven evaluation results that are exposed for debugging.
50+ isEligible : boolean ;
51+ } ;
52+
3553export type AnnotatedGuide = KnockGuide & {
36- annotation : {
37- // true status = good
38- active : ActiveStatus ;
39- targetable : TargetableStatus ;
40- // false status = good
41- archived : ArchivedStatus ;
42- } ;
54+ annotation : GuideAnnotation ;
4355} ;
4456
4557// Exists and ordered in control but absent in switchboard (therefore not
@@ -50,6 +62,9 @@ export type MissingGuide = {
5062 key : KnockGuide [ "key" ] ;
5163 active : false ;
5264 bypass_global_group_limit : false ;
65+ annotation : {
66+ isEligible : false ;
67+ } ;
5368} ;
5469
5570export type InspectionResult = {
@@ -96,12 +111,17 @@ const annotateGuide = (
96111 const { ineligibleGuides } = snapshot ;
97112 const marker = ineligibleGuides [ guide . key ] ;
98113
99- const annotation : AnnotatedGuide [ "annotation" ] = {
114+ const statuses : AnnotatedStatuses = {
100115 active : { status : guide . active } ,
101116 targetable : marker ? toTargetableStatus ( marker ) : { status : true } ,
102117 archived : marker ? toArchivedStatus ( marker ) : { status : false } ,
103118 } ;
104119
120+ const annotation : GuideAnnotation = {
121+ ...statuses ,
122+ isEligible : resolveIsEligible ( statuses ) ,
123+ } ;
124+
105125 return {
106126 ...guide ,
107127 annotation,
@@ -114,6 +134,9 @@ const newMissingGuide = (key: KnockGuide["key"]) =>
114134 key,
115135 active : false ,
116136 bypass_global_group_limit : false ,
137+ annotation : {
138+ isEligible : false ,
139+ } ,
117140 } ) as MissingGuide ;
118141
119142export const useInspectGuideClientStore = ( ) : InspectionResult | undefined => {
0 commit comments