Skip to content

Commit

Permalink
feat: entry and exit action icons
Browse files Browse the repository at this point in the history
  • Loading branch information
abrgr committed Sep 1, 2023
1 parent 9f8cdbc commit 87fd984
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/components/flow-graph/flow-item-list/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {
DrawableFlow,
FlowItemIdentifier,
FlowItem,
getMetadata,
} from "../../../flow-utils";
import { FlowItemIcon } from "../../flow-items";
import styles from "./flow-item-list.module.css";
import { FlowItem } from "../../../transformers/types";
import { RiAddCircleLine, RiDeleteBinLine } from "react-icons/ri";
import { IconButton } from "../../icon-button";
import { useModal } from "../../../hooks/use-modal";
Expand Down
2 changes: 1 addition & 1 deletion src/components/flow-graph/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { usePanAndZoom } from "./use-pan-and-zoom";
import { TransitionNode } from "./transition-node";
import { TransitionsView } from "./transitions-view";
import { usePosition } from "../../hooks/use-position";
import { FlowItem } from "../../transformers/types";
import { FlowItem } from "../../flow-utils";

const getElk = (() => {
let elk: iELK | undefined;
Expand Down
11 changes: 9 additions & 2 deletions src/components/flow-graph/state-node/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,20 @@ export const StateNode = ({
);

const flowItems = state.entryActions
.concat(state.exitActions)
.map(
(action): FlowItemIdentifier => ({
flowItemId: action,
flowItemType: "action",
flowItemType: "entry-action",
})
)
.concat(
state.exitActions.map(
(action): FlowItemIdentifier => ({
flowItemId: action,
flowItemType: "exit-action",
})
)
)
.concat(
state.assertions.map((assertion) => ({
flowItemId: assertion,
Expand Down
3 changes: 1 addition & 2 deletions src/components/flow-graph/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as schema from "../../schema";
import { FlowItem } from "../../transformers/types";
import { DrawableFlow, FlowItemIdentifier } from "../../flow-utils";
import { DrawableFlow, FlowItemIdentifier, FlowItem } from "../../flow-utils";

export type Editable = {
getAvailableStates: () => Array<{ id: schema.StateId; name: string }>;
Expand Down
17 changes: 17 additions & 0 deletions src/components/flow-items/entry-action.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions src/components/flow-items/exit-action.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions src/components/flow-items/flow-icon.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,38 @@
border: none;
}

.entryAction {
composes: flowItemIcon;
background-color: var(--action-background-color);
border: 1px solid var(--action-border-color);
background-image: url(./entry-action.svg);
}

.entryAction.filled {
background-image: url(./entry-action.svg);
}

.entryAction.transparent {
background-color: transparent;
border: none;
}

.exitAction {
composes: flowItemIcon;
background-color: var(--action-background-color);
border: 1px solid var(--action-border-color);
background-image: url(./exit-action.svg);
}

.exitAction.filled {
background-image: url(./exit-action.svg);
}

.exitAction.transparent {
background-color: transparent;
border: none;
}

.assertion {
composes: flowItemIcon;
background-color: var(--expectation-background-color);
Expand Down
34 changes: 34 additions & 0 deletions src/components/flow-items/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export const flowItemIconComponentForType = (
switch (flowItemType) {
case "action":
return ActionIcon;
case "entry-action":
return EntryActionIcon;
case "exit-action":
return ExitActionIcon;
case "assertion":
return AssertionIcon;
case "condition":
Expand Down Expand Up @@ -64,6 +68,36 @@ export const ActionIcon = ({ className, transparent, filled }: IconProps) => {
);
};

export const EntryActionIcon = ({
className,
transparent,
filled,
}: IconProps) => {
return (
<span
title={flowItemTypePresentation.action.title}
className={`${styles.entryAction} ${
transparent ? styles.transparent : ""
} ${className ?? ""} ${filled ? styles.filled : ""}`}
></span>
);
};

export const ExitActionIcon = ({
className,
transparent,
filled,
}: IconProps) => {
return (
<span
title={flowItemTypePresentation.action.title}
className={`${styles.exitAction} ${
transparent ? styles.transparent : ""
} ${className ?? ""} ${filled ? styles.filled : ""}`}
></span>
);
};

export const AssertionIcon = ({
className,
transparent,
Expand Down
8 changes: 8 additions & 0 deletions src/data/flows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ export const flowItemTypePresentation: Record<
title: "Action",
groupTitle: "Actions",
},
"entry-action": {
title: "Entry action",
groupTitle: "Entry actions",
},
"exit-action": {
title: "Exit action",
groupTitle: "Exit actions",
},
assertion: {
title: "Expectation",
groupTitle: "Expectations",
Expand Down
12 changes: 12 additions & 0 deletions src/flow-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ export const flowItemSchema = z.discriminatedUnion("flowItemType", [
flowItemId: schema.actionIdSchema,
flowItemName: z.string(),
}),
z.object({
flowItemType: z.literal("entry-action"),
flowItemId: schema.actionIdSchema,
flowItemName: z.string(),
}),
z.object({
flowItemType: z.literal("exit-action"),
flowItemId: schema.actionIdSchema,
flowItemName: z.string(),
}),
z.object({
flowItemType: z.literal("assertion"),
flowItemId: schema.assertionIdSchema,
Expand Down Expand Up @@ -190,6 +200,8 @@ export const getMetadata = (
) => {
switch (flowItem.flowItemType) {
case "action":
case "entry-action":
case "exit-action":
return flow.metadata.actions[flowItem.flowItemId];
case "assertion":
return flow.metadata.assertions[flowItem.flowItemId];
Expand Down
10 changes: 10 additions & 0 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ export const flowItemTypeSchema = z.enum([
"event",
"condition",
"action",
"entry-action",
"exit-action",
"assertion",
]);
export type FlowItemType = z.infer<typeof flowItemTypeSchema>;
Expand All @@ -107,6 +109,14 @@ export const flowItemRefSchema = z.discriminatedUnion("type", [
type: z.literal("action"),
id: actionIdSchema,
}),
z.object({
type: z.literal("entry-action"),
id: actionIdSchema,
}),
z.object({
type: z.literal("exit-action"),
id: actionIdSchema,
}),
z.object({
type: z.literal("assertion"),
id: assertionIdSchema,
Expand Down
28 changes: 0 additions & 28 deletions src/transformers/types.ts

This file was deleted.

0 comments on commit 87fd984

Please sign in to comment.