Skip to content

Commit 73c9f73

Browse files
committed
clean up naming and such
1 parent 3fe3193 commit 73c9f73

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,13 +36,18 @@ 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 & {
@@ -53,14 +58,6 @@ export type AnnotatedGuide = KnockGuide & {
5358
priority?: number;
5459
};
5560

56-
export const checkUsable = (guide: AnnotatedGuide | MissingGuide) => {
57-
if (guide.__typename === "MissingGuide") return false;
58-
if (!checkEligible(guide)) return false;
59-
if (!guide.annotation.activatable.status) return false;
60-
61-
return true;
62-
};
63-
6461
// Exists and ordered in control but absent in switchboard (therefore not
6562
// included in the api response), which implies a newly created guide that has
6663
// never been published to switchboard.
@@ -71,6 +68,7 @@ export type UnknownGuide = {
7168
bypass_global_group_limit: false;
7269
annotation: {
7370
isEligible: false;
71+
isQualified: false;
7472
};
7573
};
7674

@@ -117,6 +115,11 @@ const resolveIsEligible = ({
117115
return true;
118116
};
119117

118+
export const resolveIsQualified = ({ activatable }: AnnotatedStatuses) => {
119+
if (!activatable.status) return false;
120+
return true;
121+
};
122+
120123
type StoreStateSnapshot = Pick<
121124
KnockGuideClientStoreState,
122125
"location" | "guides" | "guideGroups" | "ineligibleGuides" | "debug"
@@ -130,15 +133,18 @@ const annotateGuide = (
130133
const marker = ineligibleGuides[guide.key];
131134

132135
const statuses: AnnotatedStatuses = {
136+
// isEligible:
133137
active: { status: guide.active },
134138
targetable: marker ? toTargetableStatus(marker) : { status: true },
135-
activatable: { status: checkActivatable(guide, location) },
136139
archived: marker ? toArchivedStatus(marker) : { status: false },
140+
// isQualified:
141+
activatable: { status: checkActivatable(guide, location) },
137142
};
138143

139144
const annotation: GuideAnnotation = {
140145
...statuses,
141146
isEligible: resolveIsEligible(statuses),
147+
isQualified: resolveIsQualified(statuses),
142148
};
143149

144150
return {
@@ -155,6 +161,7 @@ const newUnknownGuide = (key: KnockGuide["key"]) =>
155161
bypass_global_group_limit: false,
156162
annotation: {
157163
isEligible: false,
164+
isQualified: false,
158165
},
159166
}) as UnknownGuide;
160167

0 commit comments

Comments
 (0)