Skip to content

Commit

Permalink
feat: Triggers new, edit, delete
Browse files Browse the repository at this point in the history
  • Loading branch information
wagnercosta committed Jul 6, 2024
1 parent 8585bc2 commit d6b758a
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 119 deletions.
7 changes: 6 additions & 1 deletion src/app/[lang]/components/LeftMenu/MenuData.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ForwardIcon, HomeIcon, CogIcon } from "@heroicons/react/24/outline";
import { ForwardIcon, HomeIcon, CogIcon, FireIcon } from "@heroicons/react/24/outline";
import { ReactNode } from "react";

export const menuData: {
Expand All @@ -21,4 +21,9 @@ export const menuData: {
link: "/config",
Icon: <CogIcon className="w-7 h-7" />,
},
{
label: "Triggers",
link: "/trigger",
Icon: <FireIcon className="w-7 h-7" />,
},
];
20 changes: 12 additions & 8 deletions src/app/[lang]/trigger/components/TriggerList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"use server";

import { Locale, getDictionary } from "@/i18n/dictionaries";
import ConfigRowActions from "./TriggerRowActions";
import TriggerRowActions from "./TriggerRowActions";
import { ITable, ITableOptions } from "@/components/tables/utils";
import Table from "@/components/tables";
import ConfigPageActions from "./TriggerPageActions";
import TriggerPageActions from "./TriggerPageActions";

export type TriggerData = {
name: string;
Expand All @@ -17,26 +17,30 @@ export type TriggerData = {
};

interface IConfigListProps {
configPromise: Promise<TriggerData[]>;
triggerPromise: Promise<TriggerData[]>;
lang: Locale;
tableOptions: ITableOptions<TriggerData>;
}

const TriggerList = async (props: IConfigListProps) => {
const { lang, tableOptions, configPromise } = props;
const { lang, tableOptions, triggerPromise } = props;
const dict = getDictionary(lang);
const configData = await configPromise;
const triggerData = await triggerPromise;
const localDict = dict["trigger"];
const globalDict = dict["global"];

const tableProps: ITable<TriggerData> = {
tableOptions,
data: configData,
data: triggerData,
tableHeaders: [
{
fieldName: "name",
label: localDict.name,
},
{
fieldName: "type",
label: localDict.type,
},
{
fieldName: "uid",
label: globalDict.uid,
Expand All @@ -51,7 +55,7 @@ const TriggerList = async (props: IConfigListProps) => {
fieldType: "date",
},
],
RowActions: ConfigRowActions,
RowActions: TriggerRowActions,
actionsLabel: globalDict.actions,
pathname: "config",
selectRowOptions: {
Expand All @@ -60,7 +64,7 @@ const TriggerList = async (props: IConfigListProps) => {
},
pageHeaderOptions: {
title: localDict.title,
rightElement: <ConfigPageActions />,
rightElement: <TriggerPageActions />,
},
};
return <Table {...tableProps} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import Modal from "@/components/common/Modal";
import useDictionaries from "@/hooks/useDictionaries";
import { useRouter } from "next/navigation";
import { useState, useTransition } from "react";
import { deleteAllConfigs } from "../../server-actions";
import { deleteAllTriggers } from "../../server-actions";

interface IModalDeleteSelectedConfigs {
configNames: string[];
modalDeleteAllId: string;
}
const ModalDeleteSelectedConfigs = (props: IModalDeleteSelectedConfigs) => {
const ModalDeleteSelectedTriggers = (props: IModalDeleteSelectedConfigs) => {
const { modalDeleteAllId, configNames } = props;
const router = useRouter();
const dict = useDictionaries();
Expand All @@ -20,7 +20,7 @@ const ModalDeleteSelectedConfigs = (props: IModalDeleteSelectedConfigs) => {
const deleteAll = async () => {
setIsFetching(true);

await deleteAllConfigs(configNames);
await deleteAllTriggers(configNames);
setIsFetching(false);
startTransition(() => {
// Refresh the current route:
Expand All @@ -41,12 +41,12 @@ const ModalDeleteSelectedConfigs = (props: IModalDeleteSelectedConfigs) => {
actionCallback={deleteAll}
action={dict.global.delete}
cancel={dict.global.cancel}
description={dict.configs.modalConfirmDeleteSelected}
description={dict.trigger.modalConfirmDeleteSelected}
modalId={modalDeleteAllId}
title={dict.configs.modalDeleteSelectedTitle}
title={dict.trigger.modalDeleteSelectedTitle}
isMutating={isMutating}
/>
);
};

export default ModalDeleteSelectedConfigs;
export default ModalDeleteSelectedTriggers;
10 changes: 5 additions & 5 deletions src/app/[lang]/trigger/components/TriggerPageActions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use client";

import DropdownPageActions from "../../../../../components/DropdownPageActions";
import ModalDeleteSelectedConfigs from "./ModalDeleteSelectedConfigs";
import ModalDeleteSelectedTriggers from "./ModalDeleteSelectedTriggers";
import useDictionaries from "@/hooks/useDictionaries";
import Link from "next/link";
import { ReactNode, useContext } from "react";
Expand All @@ -12,13 +12,13 @@ import { TableContext } from "@/components/tables/TableContext";
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime";

export const getDropdownItems = (
worklowsSelected: string[],
itemsSelected: string[],
dict: LanguageDictType,
router: AppRouterInstance,
modalDeleteAllId: string
) => {
const dropdownItems: ReactNode[] = [];
if (worklowsSelected.length > 0) {
if (itemsSelected.length > 0) {
dropdownItems.push(
<button
type="button"
Expand All @@ -31,7 +31,7 @@ export const getDropdownItems = (
);
}
dropdownItems.push(
<Link href={"/config/yaml/new"} key={"newyaml"} className="justify-between">
<Link href={"/trigger/yaml/new"} key={"newyaml"} className="justify-between">
{dict.configs.newFromYaml}
</Link>
);
Expand Down Expand Up @@ -59,7 +59,7 @@ const ConfigPageActions = () => {
<div>
<InputTableSearch />
<DropdownPageActions title={dict.global.actions} dropdownItems={dropdownItems}>
<ModalDeleteSelectedConfigs
<ModalDeleteSelectedTriggers
modalDeleteAllId={modalDeleteAllId}
configNames={allSelectedItems}
/>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"use client";

import Modal from "@/components/common/Modal";
import useDictionaries from "@/hooks/useDictionaries";
import { useRouter } from "next/navigation";
import { deleteTrigger } from "../../server-actions";

interface IModalDeleteTrigger {
triggerName: string;
modalId: string;
}
const ModalDeleteTrigger = (props: IModalDeleteTrigger) => {
const { triggerName, modalId } = props;
const router = useRouter();
const dict = useDictionaries();

const deleteWithId = async () => {
await deleteTrigger(triggerName);
router.refresh();
};

return (
<Modal
actionCallback={deleteWithId}
action={dict.global.delete}
cancel={dict.global.cancel}
description={dict.trigger.modalConfirmDeleteRow}
modalId={modalId}
title={dict.trigger.modalDeleteRowTitle}
/>
);
};

export default ModalDeleteTrigger;
8 changes: 4 additions & 4 deletions src/app/[lang]/trigger/components/TriggerRowActions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

import TableRowActions, { ITableRowActions } from "@/components/tables/TableRowActions";
import useDictionaries from "@/hooks/useDictionaries";
import ModalDeleteConfig from "./ModalDeleteConfig";
import ModalDeleteTrigger from "./ModalDeleteTrigger";
import { TriggerData } from "../TriggerList";

const ConfigRowActions = (props: TriggerData) => {
const { name } = props;
const dict = useDictionaries();
const modalDeleteId = `modal-delete-config-${name}`;
const modalDeleteId = `modal-delete-trigger-${name}`;
const actions: ITableRowActions[] = [
{
label: dict.global.delete,
modalId: modalDeleteId,
},
{
label: dict.global.editYaml,
link: `/config/yaml/edit/${name}`,
link: `/trigger/yaml/edit/${name}`,
},
];

return (
<TableRowActions actions={actions}>
<ModalDeleteConfig configName={name} modalId={modalDeleteId} />
<ModalDeleteTrigger triggerName={name} modalId={modalDeleteId} />
</TableRowActions>
);
};
Expand Down
25 changes: 13 additions & 12 deletions src/app/[lang]/trigger/components/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { notFound } from "next/navigation";
import { FLOWDAPT_API_VERSION, getClient } from "@/lib/util";
import { TriggerData } from "./TriggerList";
import { ConfigResourceReadResponseDTOType } from "@emergentmethods/flowdapt-ts-sdk";
import { TriggerRuleResourceReadResponseDTOType } from "@emergentmethods/flowdapt-ts-sdk";

export async function getTriggers() {
const flowdaptSDK = getClient();
Expand Down Expand Up @@ -36,7 +36,7 @@ export async function getTrigger(id: string) {
}
}

export const handleConfigflowNewEditRoute = (props: Flowdapt.IPageParams) => {
export const handleTriggerflowNewEditRoute = (props: Flowdapt.IPageParams) => {
const action = (props?.params?.id || [])[0];
const editId = (props?.params?.id || [])[1];

Expand All @@ -52,25 +52,26 @@ export const handleConfigflowNewEditRoute = (props: Flowdapt.IPageParams) => {
return { id: editId, type: action as "new" | "edit" };
};

export const getInitialConfigPageData = async (id: string, type: "new" | "edit") => {
export const getInitialTriggerPageData = async (id: string, type: "new" | "edit") => {
if (type === "new") {
const config: ConfigResourceReadResponseDTOType[FLOWDAPT_API_VERSION]["data"] = {
kind: "config",
const trigger: TriggerRuleResourceReadResponseDTOType[FLOWDAPT_API_VERSION]["data"] = {
kind: "trigger",
metadata: {
name: "",
annotations: {},
},
spec: {
selector: {
type: "annotation",
value: "",
type: "schedule",
rule: {},
action: {
target: "",
parameters: {},
},
data: {},
},
};
return config;
return trigger;
} else {
const config = await getTrigger(id);
return config;
const trigger = await getTrigger(id);
return trigger;
}
};
10 changes: 5 additions & 5 deletions src/app/[lang]/trigger/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import { getTriggersFlatData } from "./components/utils";
export const revalidate = 0;

const getTriggersPageData = async (tableOptions: ITableOptions<TriggerData>) => {
const configList: TriggerData[] = await getTriggersFlatData();
const filteredConfigs: TriggerData[] = await filterOrderDataTable(tableOptions, configList);
return filteredConfigs;
const dataList: TriggerData[] = await getTriggersFlatData();
const filteredTriggers: TriggerData[] = await filterOrderDataTable(tableOptions, dataList);
return filteredTriggers;
};

export default async function Page(props: Flowdapt.IPageParams) {
const lang = getLanguage(props);
const tableOptions = getTableOptions<TriggerData>(props, ["name", "uid", "group"]);
const tableOptions = getTableOptions<TriggerData>(props, ["name", "type", "uid", "group"]);
const data = getTriggersPageData(tableOptions);

return (
<Container>
<TriggerList configPromise={data} tableOptions={tableOptions} lang={lang} />
<TriggerList triggerPromise={data} tableOptions={tableOptions} lang={lang} />
</Container>
);
}
18 changes: 9 additions & 9 deletions src/app/[lang]/trigger/server-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@

import { getClient } from "@/lib/util";

export async function saveConfig(definition: any, identifier?: string) {
export async function saveTrigger(definition: any, id?: string) {
const flowdaptSDK = getClient();

if (identifier) {
await flowdaptSDK.configs.updateConfig({
if (id) {
await flowdaptSDK.triggers.updateTrigger({
request: definition,
identifier: identifier,
id: id,
});
} else {
await flowdaptSDK.configs.createConfig({
await flowdaptSDK.triggers.createTrigger({
request: definition,
});
}
}

export async function deleteConfig(identifier: string) {
export async function deleteTrigger(id: string) {
const flowdaptSDK = getClient();
await flowdaptSDK.configs.deleteConfig({ identifier: identifier });
await flowdaptSDK.triggers.deleteTrigger({ id: id });
}

export async function deleteAllConfigs(identifierList: string[]) {
export async function deleteAllTriggers(idList: string[]) {
const flowdaptSDK = getClient();
await Promise.all(identifierList.map(w => flowdaptSDK.configs.deleteConfig({ identifier: w })));
await Promise.all(idList.map(w => flowdaptSDK.triggers.deleteTrigger({ id: w })));
}
Loading

0 comments on commit d6b758a

Please sign in to comment.