refactor: improve action config type safe

This commit is contained in:
Stephen Zhou
2025-06-20 09:21:21 +08:00
parent 20858f6614
commit eb3f663a67
+45 -30
View File
@@ -1,109 +1,124 @@
import type { ActionId, SupportedLanguages } from "@follow/models/types"
import type {
ActionFeedField,
ActionId,
ActionOperation,
SupportedLanguages,
} from "@follow/models/types"
import type { ParseKeys } from "i18next"
import type { SFSymbol } from "sf-symbols-typescript"
import { actionActions } from "./store"
export const filterFieldOptions: Array<{
label: Extract<ParseKeys<"settings">, `actions.action_card.feed_options.${string}`>
value: string
type?: "text" | "number" | "view" | "status"
}> = [
const filterFieldOptionsMap: Record<
ActionFeedField,
{
label: Extract<ParseKeys<"settings">, `actions.action_card.feed_options.${string}`>
value: ActionFeedField
type?: "text" | "number" | "view" | "status"
}
> = {
status: {
label: "actions.action_card.feed_options.status",
value: "status",
type: "status",
},
{
view: {
label: "actions.action_card.feed_options.subscription_view",
value: "view",
type: "view",
},
{
title: {
label: "actions.action_card.feed_options.feed_title",
value: "title",
},
{
category: {
label: "actions.action_card.feed_options.feed_category",
value: "category",
},
{
site_url: {
label: "actions.action_card.feed_options.site_url",
value: "site_url",
},
{
feed_url: {
label: "actions.action_card.feed_options.feed_url",
value: "feed_url",
},
{
entry_title: {
label: "actions.action_card.feed_options.entry_title",
value: "entry_title",
},
{
entry_content: {
label: "actions.action_card.feed_options.entry_content",
value: "entry_content",
},
{
entry_url: {
label: "actions.action_card.feed_options.entry_url",
value: "entry_url",
},
{
entry_author: {
label: "actions.action_card.feed_options.entry_author",
value: "entry_author",
},
{
entry_media_length: {
label: "actions.action_card.feed_options.entry_media_length",
value: "entry_media_length",
type: "number",
},
{
entry_attachments_duration: {
label: "actions.action_card.feed_options.entry_attachments_duration",
value: "entry_attachments_duration",
type: "number",
},
]
}
export const filterOperatorOptions: Array<{
label: Extract<ParseKeys<"settings">, `actions.action_card.operation_options.${string}`>
value: string
types: Array<"text" | "number" | "view" | "status">
}> = [
export const filterFieldOptions = Object.values(filterFieldOptionsMap)
const filterOperatorOptionsMap: Record<
ActionOperation,
{
label: Extract<ParseKeys<"settings">, `actions.action_card.operation_options.${string}`>
value: ActionOperation
types: Array<"text" | "number" | "view" | "status">
}
> = {
contains: {
label: "actions.action_card.operation_options.contains",
value: "contains",
types: ["text"],
},
{
not_contains: {
label: "actions.action_card.operation_options.does_not_contain",
value: "not_contains",
types: ["text"],
},
{
eq: {
label: "actions.action_card.operation_options.is_equal_to",
value: "eq",
types: ["number", "text", "view", "status"],
},
{
not_eq: {
label: "actions.action_card.operation_options.is_not_equal_to",
value: "not_eq",
types: ["number", "text", "view"],
},
{
gt: {
label: "actions.action_card.operation_options.is_greater_than",
value: "gt",
types: ["number"],
},
{
lt: {
label: "actions.action_card.operation_options.is_less_than",
value: "lt",
types: ["number"],
},
{
regex: {
label: "actions.action_card.operation_options.matches_regex",
value: "regex",
types: ["text"],
},
]
}
export const filterOperatorOptions = Object.values(filterOperatorOptionsMap)
export type ActionAction = {
value: ActionId