Skip to content

Commit

Permalink
feat: webhook action setting
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Sep 28, 2024
1 parent 31591d6 commit 0016a07
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 52 deletions.
24 changes: 24 additions & 0 deletions apps/renderer/src/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,27 @@ export type MediaModel = Exclude<
ExtractBizResponse<typeof apiClient.entries.$get>["data"],
undefined
>["entries"]["media"]

export type ActionsInput = {
name: string
condition: {
field?: ActionFeedField
operator?: ActionOperation
value?: string
}[]
result: {
translation?: string
summary?: boolean
readability?: boolean
rewriteRules?: {
from: string
to: string
}[]
blockRules?: {
field?: ActionEntryField
operator?: ActionOperation
value?: string | number
}[]
webhooks?: string[]
}
}[]
80 changes: 51 additions & 29 deletions apps/renderer/src/modules/settings/action-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,35 +27,7 @@ import {
import { ViewSelectContent } from "~/components/view-select-content"
import { stopPropagation } from "~/lib/dom"
import { cn } from "~/lib/utils"
import type {
ActionEntryField,
ActionFeedField,
ActionOperation,
SupportedLanguages,
} from "~/models"

type ActionsInput = {
name: string
condition: {
field?: ActionFeedField
operator?: ActionOperation
value?: string
}[]
result: {
translation?: string
summary?: boolean
readability?: boolean
rewriteRules?: {
from: string
to: string
}[]
blockRules?: {
field?: ActionEntryField
operator?: ActionOperation
value?: string | number
}[]
}
}[]
import type { ActionFeedField, ActionOperation, ActionsInput, SupportedLanguages } from "~/models"

const TransitionOptions: {
name: string
Expand Down Expand Up @@ -620,6 +592,56 @@ export function ActionCard({
</>
)}
</SettingCollapsible>
<Divider />

<SettingCollapsible
title={t("actions.action_card.webhooks")}
open={!!data.result.webhooks}
onOpenChange={(open) => {
if (open) {
data.result.webhooks = [""]
} else {
delete data.result.webhooks
}
onChange(data)
}}
>
{data.result.webhooks && data.result.webhooks.length > 0 && (
<>
{data.result.webhooks.map((webhook, rewriteIdx) => {
return (
<div key={rewriteIdx} className="flex items-center gap-2">
<DeleteTableCell
onClick={() => {
if (data.result.webhooks?.length === 1) {
delete data.result.webhooks
} else {
data.result.webhooks?.splice(rewriteIdx, 1)
}
onChange(data)
}}
/>
<Input
value={webhook}
className="h-8"
placeholder="https://"
onChange={(e) => {
data.result.webhooks![rewriteIdx] = e.target.value
onChange(data)
}}
/>
</div>
)
})}
<AddTableRow
onClick={() => {
data.result.webhooks!.push("")
onChange(data)
}}
/>
</>
)}
</SettingCollapsible>
</div>
</div>
</div>
Expand Down
25 changes: 2 additions & 23 deletions apps/renderer/src/pages/settings/(settings)/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Button } from "~/components/ui/button"
import { useAuthQuery } from "~/hooks/common"
import { apiClient } from "~/lib/api-fetch"
import { toastFetchError } from "~/lib/error-parser"
import type { ActionEntryField, ActionFeedField, ActionOperation, ActionsResponse } from "~/models"
import type { ActionsInput, ActionsResponse } from "~/models"
import { ActionCard } from "~/modules/settings/action-card"
import { SettingsTitle } from "~/modules/settings/title"
import { defineSettingPageData } from "~/modules/settings/utils"
Expand All @@ -22,28 +22,6 @@ export const loader = defineSettingPageData({
priority,
})

type ActionsInput = {
name: string
condition: {
field?: ActionFeedField
operator?: ActionOperation
value?: string
}[]
result: {
translation?: string
summary?: boolean
rewriteRules?: {
from: string
to: string
}[]
blockRules?: {
field?: ActionEntryField
operator?: ActionOperation
value?: string | number
}[]
}
}[]

export function Component() {
const { t } = useTranslation("settings")
const actions = useAuthQuery(Queries.action.getAll())
Expand All @@ -63,6 +41,7 @@ export function Component() {
action.result.blockRules = action.result.blockRules?.filter(
(r) => r.field && r.operator && r.value,
)
action.result.webhooks = action.result.webhooks?.filter((w) => w)
})
await apiClient.actions.$put({
json: {
Expand Down
1 change: 1 addition & 0 deletions locales/errors/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"1001": "create session failed",
"1002": "Invalid parameter",
"1003": "Invalid invitation",
"1004": "No permission",
"2000": "Only admins can refresh feeds",
"2001": "Feed not found",
"2002": "feedId or url required",
Expand Down
1 change: 1 addition & 0 deletions locales/settings/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"actions.action_card.to": "To",
"actions.action_card.translate_into": "Translate into",
"actions.action_card.value": "Value",
"actions.action_card.webhooks": "Webhooks",
"actions.action_card.when_feeds_match": "When feeds match…",
"actions.newRule": "New Rule",
"actions.save": "Save",
Expand Down
31 changes: 31 additions & 0 deletions packages/shared/src/hono.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ declare const actions: drizzle_orm_pg_core.PgTableWithColumns<{
operator: z.infer<typeof ruleOperatorSchema>;
value: string | number;
}[];
webhooks?: string[];
};
}[];
driverParam: unknown;
Expand Down Expand Up @@ -281,6 +282,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}>, "many">>;
webhooks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
summary?: boolean | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
Expand All @@ -294,6 +296,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
}, {
summary?: boolean | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
Expand All @@ -307,6 +310,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
}>;
}, "strip", z.ZodTypeAny, {
name: string;
Expand All @@ -323,6 +327,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
Expand All @@ -344,6 +349,7 @@ declare const actionsItemOpenAPISchema: z.ZodObject<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
Expand Down Expand Up @@ -401,6 +407,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}>, "many">>;
webhooks: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
}, "strip", z.ZodTypeAny, {
summary?: boolean | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
Expand All @@ -414,6 +421,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
}, {
summary?: boolean | undefined;
translation?: "en" | "ja" | "zh-CN" | "zh-TW" | undefined;
Expand All @@ -427,6 +435,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
}>;
}, "strip", z.ZodTypeAny, {
name: string;
Expand All @@ -443,6 +452,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
Expand All @@ -464,6 +474,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
Expand All @@ -488,6 +499,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
Expand All @@ -512,6 +524,7 @@ declare const actionsOpenAPISchema: z.ZodObject<z.objectUtil.extendShape<Omit<{
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
Expand Down Expand Up @@ -3211,6 +3224,21 @@ declare const feedPowerTokensRelations: drizzle_orm.Relations<"feedPowerTokens",
}>;

declare const _routes: hono_hono_base.HonoBase<Env, {
"/admin/clean": {
$post: {
input: {
json: {
type: string;
};
};
output: {
code: 0;
};
outputFormat: "json" | "text";
status: 200;
};
};
} & {
"/lists": {
$get: {
input: {
Expand Down Expand Up @@ -4382,6 +4410,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
from: string;
to: string;
}[] | undefined;
webhooks?: string[] | undefined;
} | undefined;
}[] | undefined;
total?: number | undefined;
Expand Down Expand Up @@ -4878,6 +4907,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
Expand Down Expand Up @@ -4908,6 +4938,7 @@ declare const _routes: hono_hono_base.HonoBase<Env, {
field: "title" | "all" | "content" | "author" | "url" | "order";
operator: "contains" | "not_contains" | "eq" | "not_eq" | "gt" | "lt" | "regex";
}[] | undefined;
webhooks?: string[] | undefined;
};
condition: {
value: string;
Expand Down

0 comments on commit 0016a07

Please sign in to comment.