Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ import * as React from "react";

import {
AnnotatedGuide,
UnknownGuide,
isUnknownGuide,
UncommittedGuide,
isUncommittedGuide,
} from "./useInspectGuideClientStore";

type Props = {
guide: AnnotatedGuide | UnknownGuide;
guide: AnnotatedGuide | UncommittedGuide;
};

export const GuideHoverCard = ({
children,
guide,
}: React.PropsWithChildren<Props>) => {
if (isUnknownGuide(guide)) {
if (isUncommittedGuide(guide)) {
return <Stack align="center">{children}</Stack>;
}

Expand Down
22 changes: 11 additions & 11 deletions packages/react/src/modules/guide/components/Toolbar/V2/GuideRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import { GuideRowDetails } from "./GuideRowDetails";
import {
AnnotatedGuide,
AnnotatedStatuses,
UnknownGuide,
isUnknownGuide,
UncommittedGuide,
isUncommittedGuide,
} from "./useInspectGuideClientStore";

const Pill = ({
Expand Down Expand Up @@ -56,9 +56,9 @@ type StatusSummary = {
};

const getStatusSummary = (
guide: AnnotatedGuide | UnknownGuide,
guide: AnnotatedGuide | UncommittedGuide,
): StatusSummary => {
if (isUnknownGuide(guide)) {
if (isUncommittedGuide(guide)) {
return {
color: "red",
label: "Inactive",
Expand Down Expand Up @@ -135,9 +135,9 @@ type StatusDot = {
};

const getStatusDots = (
guide: AnnotatedGuide | UnknownGuide,
guide: AnnotatedGuide | UncommittedGuide,
): Record<keyof AnnotatedStatuses, StatusDot> => {
if (isUnknownGuide(guide)) {
if (isUncommittedGuide(guide)) {
return {
active: { color: "gray" },
archived: { color: "gray" },
Expand Down Expand Up @@ -193,7 +193,7 @@ const getStatusDots = (
};

type Props = {
guide: UnknownGuide | AnnotatedGuide;
guide: UncommittedGuide | AnnotatedGuide;
orderIndex: number;
isExpanded: boolean;
onClick: (guideKey: string) => void;
Expand Down Expand Up @@ -311,7 +311,7 @@ export const GuideRow = ({ guide, orderIndex, isExpanded, onClick }: Props) => {
<Pill
label="Elig:"
color={
isUnknownGuide(guide)
isUncommittedGuide(guide)
? "disabled"
: guide.annotation.isEligible
? "blue"
Expand All @@ -334,7 +334,7 @@ export const GuideRow = ({ guide, orderIndex, isExpanded, onClick }: Props) => {
<Pill
label="Vis:"
color={
isUnknownGuide(guide)
isUncommittedGuide(guide)
? "disabled"
: guide.annotation.isQualified &&
guide.annotation.selectable.status === "returned"
Expand All @@ -354,7 +354,7 @@ export const GuideRow = ({ guide, orderIndex, isExpanded, onClick }: Props) => {

<Tooltip
label={
isUnknownGuide(guide) ||
isUncommittedGuide(guide) ||
guide.annotation.selectable.status === undefined
? "No component found that can render this guide"
: isFocused
Expand All @@ -367,7 +367,7 @@ export const GuideRow = ({ guide, orderIndex, isExpanded, onClick }: Props) => {
variant={isFocused ? "solid" : "outline"}
color={isFocused ? "blue" : "gray"}
disabled={
isUnknownGuide(guide) ||
isUncommittedGuide(guide) ||
guide.annotation.selectable.status === undefined
}
onClick={(e: React.MouseEvent) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from "./GuideAnnotatedStatusDot";
import {
AnnotatedGuide,
UnknownGuide,
isUnknownGuide,
UncommittedGuide,
isUncommittedGuide,
} from "./useInspectGuideClientStore";

const CardContainer = ({
Expand Down Expand Up @@ -77,9 +77,9 @@ const getDisplayValue = (
export const GuideRowDetails = ({
guide,
}: {
guide: AnnotatedGuide | UnknownGuide;
guide: AnnotatedGuide | UncommittedGuide;
}) => {
if (isUnknownGuide(guide)) {
if (isUncommittedGuide(guide)) {
return (
<Box px="3" py="2">
<Text as="span" size="1" color="gray">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ export type AnnotatedGuide = KnockGuide & {
// Exists and ordered in control but absent in switchboard (therefore not
// included in the api response), which implies a newly created guide that has
// never been published to switchboard.
export type UnknownGuide = {
__typename: "UnknownGuide";
export type UncommittedGuide = {
__typename: "UncommittedGuide";
key: KnockGuide["key"];
active: false;
bypass_global_group_limit: false;
Expand All @@ -117,7 +117,7 @@ export type UnknownGuide = {

export type InspectionResultOk = {
status: "ok";
guides: (AnnotatedGuide | UnknownGuide)[];
guides: (AnnotatedGuide | UncommittedGuide)[];
};
type InspectionResultError = {
status: "error";
Expand Down Expand Up @@ -388,9 +388,9 @@ const annotateGuide = (
};
};

const newUnknownGuide = (key: KnockGuide["key"]) =>
const newUncommittedGuide = (key: KnockGuide["key"]) =>
({
__typename: "UnknownGuide",
__typename: "UncommittedGuide",
key,
active: false,
bypass_global_group_limit: false,
Expand All @@ -401,7 +401,7 @@ const newUnknownGuide = (key: KnockGuide["key"]) =>
status: undefined,
},
},
}) as UnknownGuide;
}) as UncommittedGuide;

export const useInspectGuideClientStore = (
runConfig: ToolbarV2RunConfig,
Expand Down Expand Up @@ -456,7 +456,7 @@ export const useInspectGuideClientStore = (
const orderedGuides = defaultGroup.display_sequence.map((guideKey) => {
const guide = snapshot.guides[guideKey];
if (!guide) {
return newUnknownGuide(guideKey);
return newUncommittedGuide(guideKey);
}

return annotateGuide(guide, snapshot, groupStage);
Expand All @@ -483,8 +483,8 @@ export const useInspectGuideClientStore = (
};
};

export const isUnknownGuide = (input: unknown): input is UnknownGuide =>
export const isUncommittedGuide = (input: unknown): input is UncommittedGuide =>
typeof input === "object" &&
input !== null &&
"__typename" in input &&
(input as UnknownGuide).__typename === "UnknownGuide";
(input as UncommittedGuide).__typename === "UncommittedGuide";
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { beforeEach, describe, expect, test, vi } from "vitest";

import {
type AnnotatedGuide,
isUnknownGuide,
isUncommittedGuide,
resolveIsQualified,
useInspectGuideClientStore,
} from "../../../../src/modules/guide/components/Toolbar/V2/useInspectGuideClientStore";
Expand Down Expand Up @@ -173,17 +173,17 @@ describe("useInspectGuideClientStore", () => {
});
});

// ----- Unknown guide -----
// ----- Uncommitted guide -----

test("produces an UnknownGuide when key is in display_sequence but not in guides", () => {
test("produces an UncommittedGuide when key is in display_sequence but not in guides", () => {
setSnapshot({
guideGroups: [makeGuideGroup(["missing_key"])],
guides: {},
});

const result = renderInspect()!;
expect(result.guides).toHaveLength(1);
expect(isUnknownGuide(result.guides[0])).toBe(true);
expect(isUncommittedGuide(result.guides[0])).toBe(true);

const unknown = result.guides[0]!;
expect(unknown.key).toBe("missing_key");
Expand Down Expand Up @@ -445,7 +445,7 @@ describe("useInspectGuideClientStore", () => {

// ----- Mixed guides: eligible, ineligible, and unknown -----

test("handles a mix of eligible, ineligible, and unknown guides", () => {
test("handles a mix of eligible, ineligible, and uncommitted guides", () => {
const eligible = makeGuide({ key: "eligible", active: true });
const inactive = makeGuide({ key: "inactive", active: false });
const archived = makeGuide({ key: "archived", active: true });
Expand Down Expand Up @@ -495,10 +495,10 @@ describe("useInspectGuideClientStore", () => {
expect(g2.annotation.isEligible).toBe(false);
expect(g2.annotation.archived.status).toBe(true);

// unknown guide
// uncommitted guide
const g3 = result.guides[3]!;
expect(g3.key).toBe("unknown_key");
expect(isUnknownGuide(g3)).toBe(true);
expect(isUncommittedGuide(g3)).toBe(true);
expect(g3.annotation.isEligible).toBe(false);
});

Expand Down
Loading