-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from emergentmethods/feat/triggers
Feat/triggers
- Loading branch information
Showing
20 changed files
with
765 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
"use server"; | ||
|
||
import { Locale, getDictionary } from "@/i18n/dictionaries"; | ||
import TriggerRowActions from "./TriggerRowActions"; | ||
import { ITable, ITableOptions } from "@/components/tables/utils"; | ||
import Table from "@/components/tables"; | ||
import TriggerPageActions from "./TriggerPageActions"; | ||
|
||
export type TriggerData = { | ||
name: string; | ||
type: "schedule" | "condition"; | ||
uid?: string | undefined; | ||
created_at?: string | undefined; | ||
updated_at?: string | undefined; | ||
annotations?: Record<string, string> | undefined; | ||
group?: string; | ||
}; | ||
|
||
interface IConfigListProps { | ||
triggerPromise: Promise<TriggerData[]>; | ||
lang: Locale; | ||
tableOptions: ITableOptions<TriggerData>; | ||
} | ||
|
||
const TriggerList = async (props: IConfigListProps) => { | ||
const { lang, tableOptions, triggerPromise } = props; | ||
const dict = getDictionary(lang); | ||
const triggerData = await triggerPromise; | ||
const localDict = dict["trigger"]; | ||
const globalDict = dict["global"]; | ||
|
||
const tableProps: ITable<TriggerData> = { | ||
tableOptions, | ||
data: triggerData, | ||
tableHeaders: [ | ||
{ | ||
fieldName: "name", | ||
label: localDict.name, | ||
}, | ||
{ | ||
fieldName: "type", | ||
label: localDict.type, | ||
}, | ||
{ | ||
fieldName: "uid", | ||
label: globalDict.uid, | ||
}, | ||
{ | ||
fieldName: "group", | ||
label: globalDict.group, | ||
}, | ||
{ | ||
fieldName: "created_at", | ||
label: globalDict.createdAt, | ||
fieldType: "date", | ||
}, | ||
], | ||
RowActions: TriggerRowActions, | ||
actionsLabel: globalDict.actions, | ||
pathname: "config", | ||
selectRowOptions: { | ||
enabled: true, | ||
fieldKey: "name", | ||
}, | ||
pageHeaderOptions: { | ||
title: localDict.title, | ||
rightElement: <TriggerPageActions />, | ||
}, | ||
}; | ||
return <Table {...tableProps} />; | ||
}; | ||
|
||
export default TriggerList; |
52 changes: 52 additions & 0 deletions
52
src/app/[lang]/trigger/components/TriggerPageActions/ModalDeleteSelectedTriggers.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"use client"; | ||
|
||
import Modal from "@/components/common/Modal"; | ||
import useDictionaries from "@/hooks/useDictionaries"; | ||
import { useRouter } from "next/navigation"; | ||
import { useState, useTransition } from "react"; | ||
import { deleteAllTriggers } from "../../server-actions"; | ||
|
||
interface IModalDeleteSelectedConfigs { | ||
configNames: string[]; | ||
modalDeleteAllId: string; | ||
} | ||
const ModalDeleteSelectedTriggers = (props: IModalDeleteSelectedConfigs) => { | ||
const { modalDeleteAllId, configNames } = props; | ||
const router = useRouter(); | ||
const dict = useDictionaries(); | ||
const [isPending, startTransition] = useTransition(); | ||
const [isFetching, setIsFetching] = useState(false); | ||
const isMutating = isFetching || isPending; | ||
const deleteAll = async () => { | ||
setIsFetching(true); | ||
|
||
await deleteAllTriggers(configNames); | ||
setIsFetching(false); | ||
startTransition(() => { | ||
// Refresh the current route: | ||
// - Makes a new request to the server for the route | ||
// - Re-fetches data requests and re-renders Server Components | ||
// - Sends the updated React Server Component payload to the client | ||
// - The client merges the payload without losing unaffected | ||
// client-side React state or browser state | ||
router.refresh(); | ||
|
||
// Note: If fetch requests are cached, the updated data will | ||
// produce the same result. | ||
}); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
actionCallback={deleteAll} | ||
action={dict.global.delete} | ||
cancel={dict.global.cancel} | ||
description={dict.trigger.modalConfirmDeleteSelected} | ||
modalId={modalDeleteAllId} | ||
title={dict.trigger.modalDeleteSelectedTitle} | ||
isMutating={isMutating} | ||
/> | ||
); | ||
}; | ||
|
||
export default ModalDeleteSelectedTriggers; |
71 changes: 71 additions & 0 deletions
71
src/app/[lang]/trigger/components/TriggerPageActions/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"use client"; | ||
|
||
import DropdownPageActions from "../../../../../components/DropdownPageActions"; | ||
import ModalDeleteSelectedTriggers from "./ModalDeleteSelectedTriggers"; | ||
import useDictionaries from "@/hooks/useDictionaries"; | ||
import Link from "next/link"; | ||
import { ReactNode, useContext } from "react"; | ||
import { LanguageDictType } from "@/i18n/dictionaries"; | ||
import { useRouter } from "next/navigation"; | ||
import InputTableSearch from "@/components/tables/InputTableSearch"; | ||
import { TableContext } from "@/components/tables/TableContext"; | ||
import { AppRouterInstance } from "next/dist/shared/lib/app-router-context.shared-runtime"; | ||
|
||
export const getDropdownItems = ( | ||
itemsSelected: string[], | ||
dict: LanguageDictType, | ||
router: AppRouterInstance, | ||
modalDeleteAllId: string | ||
) => { | ||
const dropdownItems: ReactNode[] = []; | ||
if (itemsSelected.length > 0) { | ||
dropdownItems.push( | ||
<button | ||
type="button" | ||
key={"deleteAll"} | ||
onClick={() => window[modalDeleteAllId].showModal()} | ||
className="justify-between" | ||
> | ||
{dict.global.delete} | ||
</button> | ||
); | ||
} | ||
dropdownItems.push( | ||
<Link href={"/trigger/yaml/new"} key={"newyaml"} className="justify-between"> | ||
{dict.configs.newFromYaml} | ||
</Link> | ||
); | ||
|
||
dropdownItems.push( | ||
<button className="justify-between" key={"refresh"} onClick={() => router.refresh()}> | ||
{dict.global.refresh} | ||
</button> | ||
); | ||
|
||
return dropdownItems; | ||
}; | ||
|
||
const ConfigPageActions = () => { | ||
const dict = useDictionaries(); | ||
const modalDeleteAllId = "delete-all-modal"; | ||
const router = useRouter(); | ||
|
||
const tableContext = useContext(TableContext); | ||
const { allSelectedItems = [] } = tableContext || {}; | ||
|
||
const dropdownItems = getDropdownItems(allSelectedItems, dict, router, modalDeleteAllId); | ||
|
||
return ( | ||
<div> | ||
<InputTableSearch /> | ||
<DropdownPageActions title={dict.global.actions} dropdownItems={dropdownItems}> | ||
<ModalDeleteSelectedTriggers | ||
modalDeleteAllId={modalDeleteAllId} | ||
configNames={allSelectedItems} | ||
/> | ||
</DropdownPageActions> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ConfigPageActions; |
34 changes: 34 additions & 0 deletions
34
src/app/[lang]/trigger/components/TriggerRowActions/ModalDeleteTrigger.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Oops, something went wrong.