Skip to content

Commit 8c519c1

Browse files
committed
clean up naming and such
1 parent 5d48009 commit 8c519c1

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

packages/react/src/modules/guide/components/Toolbar/V2/V2.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
import { detectToolbarParam } from "./helpers";
1717
import {
1818
InspectionResult,
19-
checkUsable,
2019
useInspectGuideClientStore,
2120
} from "./useInspectGuideClientStore";
2221

@@ -28,7 +27,11 @@ const GuidesList = ({
2827
displayOption: DisplayOption;
2928
}) => {
3029
return guides.map((guide, idx) => {
31-
if (displayOption === "current-page" && !checkUsable(guide)) {
30+
if (
31+
displayOption === "current-page" &&
32+
!guide.annotation.isEligible &&
33+
!guide.annotation.isQualified
34+
) {
3235
return null;
3336
}
3437
if (displayOption === "all-eligible" && !guide.annotation.isEligible) {

packages/react/src/modules/guide/components/Toolbar/V2/useInspectGuideClientStore.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,24 @@ type AnnotatedStatuses = {
3636
active: ActiveStatus;
3737
targetable: TargetableStatus;
3838
archived: ArchivedStatus;
39+
// Individual qualified statuses:
3940
activatable: ActivatableStatus;
4041
};
4142

4243
type GuideAnnotation = AnnotatedStatuses & {
4344
// Resolved eligibility based on active, targetable and archived statuses,
4445
// which are backend driven evaluation results that are exposed for debugging.
4546
isEligible: boolean;
47+
48+
// Resolved display qualification based on an activatable status, which
49+
// informs "when" and "where" an eligible guide can be displayed to user.
50+
isQualified: boolean;
4651
};
4752

4853
export type AnnotatedGuide = KnockGuide & {
4954
annotation: GuideAnnotation;
5055
};
5156

52-
export const checkUsable = (guide: AnnotatedGuide | MissingGuide) => {
53-
if (guide.__typename === "MissingGuide") return false;
54-
if (!checkEligible(guide)) return false;
55-
if (!guide.annotation.activatable.status) return false;
56-
57-
return true;
58-
};
59-
6057
// Exists and ordered in control but absent in switchboard (therefore not
6158
// included in the api response), which implies a newly created guide that has
6259
// never been published to switchboard.
@@ -67,6 +64,7 @@ export type MissingGuide = {
6764
bypass_global_group_limit: false;
6865
annotation: {
6966
isEligible: false;
67+
isQualified: false;
7068
};
7169
};
7270

@@ -113,6 +111,11 @@ const resolveIsEligible = ({
113111
return true;
114112
};
115113

114+
export const resolveIsQualified = ({ activatable }: AnnotatedStatuses) => {
115+
if (!activatable.status) return false;
116+
return true;
117+
};
118+
116119
type StoreStateSnapshot = Pick<
117120
KnockGuideClientStoreState,
118121
"location" | "guides" | "guideGroups" | "ineligibleGuides" | "debug"
@@ -126,15 +129,18 @@ const annotateGuide = (
126129
const marker = ineligibleGuides[guide.key];
127130

128131
const statuses: AnnotatedStatuses = {
132+
// isEligible:
129133
active: { status: guide.active },
130134
targetable: marker ? toTargetableStatus(marker) : { status: true },
131-
activatable: { status: checkActivatable(guide, location) },
132135
archived: marker ? toArchivedStatus(marker) : { status: false },
136+
// isQualified:
137+
activatable: { status: checkActivatable(guide, location) },
133138
};
134139

135140
const annotation: GuideAnnotation = {
136141
...statuses,
137142
isEligible: resolveIsEligible(statuses),
143+
isQualified: resolveIsQualified(statuses),
138144
};
139145

140146
return {
@@ -151,6 +157,7 @@ const newMissingGuide = (key: KnockGuide["key"]) =>
151157
bypass_global_group_limit: false,
152158
annotation: {
153159
isEligible: false,
160+
isQualified: false,
154161
},
155162
}) as MissingGuide;
156163

0 commit comments

Comments
 (0)