-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
559 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use client' | ||
|
||
import { useState } from 'react' | ||
import { | ||
CheckCircledIcon, | ||
ExclamationTriangleIcon, | ||
UpdateIcon, | ||
} from '@radix-ui/react-icons' | ||
|
||
import { DropdownMenuItem } from '@/components/ui/dropdown-menu' | ||
import { useToast } from '@/components/ui/use-toast' | ||
|
||
import { killQuery } from './actions' | ||
import type { Action } from './types' | ||
|
||
type Message = { | ||
message: string | ||
} | ||
|
||
interface ActionButtonProps { | ||
action: Action | ||
value: any | ||
} | ||
|
||
export function ActionItem({ action, value }: ActionButtonProps) { | ||
const { toast, dismiss } = useToast() | ||
const [status, updateStatus] = useState< | ||
'none' | 'loading' | 'success' | 'failed' | ||
>('none') | ||
|
||
const availableActions: { | ||
[key: string]: { label: string; handler: (_: FormData) => Promise<Message> } | ||
} = { | ||
'kill-query': { | ||
label: 'Kill Query', | ||
handler: killQuery.bind(null, value), | ||
}, | ||
} | ||
|
||
const { label, handler } = availableActions[action] | ||
|
||
return ( | ||
<form | ||
action={async (formData: FormData) => { | ||
updateStatus('loading') | ||
toast({ title: 'Message', description: 'Loading...' }) | ||
|
||
try { | ||
const msg: Message = await handler(formData) | ||
console.debug('Action Response', msg) | ||
updateStatus('success') | ||
toast({ title: 'Message', description: msg.message }) | ||
} catch (e) { | ||
updateStatus('failed') | ||
toast({ title: 'Error', description: `${e}`, variant: 'destructive' }) | ||
} finally { | ||
dismiss() | ||
} | ||
}} | ||
> | ||
<DropdownMenuItem> | ||
{status == 'loading' && ( | ||
<span className="flex flex-row items-center gap-2"> | ||
<UpdateIcon className="h-4 w-4 animate-spin" /> {label} | ||
</span> | ||
)} | ||
|
||
{status == 'failed' && ( | ||
<span className="flex flex-row items-center gap-2"> | ||
<ExclamationTriangleIcon className="h-4 w-4 text-orange-500" />{' '} | ||
{label} | ||
</span> | ||
)} | ||
|
||
{status == 'success' && ( | ||
<span className="flex flex-row items-center gap-2"> | ||
<CheckCircledIcon className="h-4 w-4 text-lime-600" /> {label} | ||
</span> | ||
)} | ||
|
||
{status == 'none' && ( | ||
<button type="submit" className="m-0 border-none p-0"> | ||
{label} | ||
</button> | ||
)} | ||
</DropdownMenuItem> | ||
</form> | ||
) | ||
} |
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,38 @@ | ||
import { MoreHorizontal } from 'lucide-react' | ||
|
||
import { Button } from '@/components/ui/button' | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuLabel, | ||
DropdownMenuSeparator, | ||
DropdownMenuTrigger, | ||
} from '@/components/ui/dropdown-menu' | ||
|
||
import { ActionItem } from './action-item' | ||
import type { Action } from './types' | ||
|
||
interface ActionButtonProps { | ||
value: any | ||
actions: Action[] | ||
} | ||
|
||
export function ActionMenu({ value, actions }: ActionButtonProps) { | ||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button variant="ghost" className="h-8 w-8 p-0"> | ||
<span className="sr-only">Open menu</span> | ||
<MoreHorizontal className="h-4 w-4" /> | ||
</Button> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent align="end"> | ||
<DropdownMenuLabel>Actions</DropdownMenuLabel> | ||
<DropdownMenuSeparator /> | ||
{actions.map((action) => ( | ||
<ActionItem key={action} value={value} action={action} /> | ||
))} | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
) | ||
} |
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,13 @@ | ||
'use server' | ||
|
||
import { fetchData } from '@/lib/clickhouse' | ||
|
||
export async function killQuery(queryId: string) { | ||
console.log('Killing query', queryId) | ||
const res = await fetchData(`KILL QUERY WHERE query_id = '${queryId}'`) | ||
console.log('Killed query', queryId, res) | ||
|
||
return { | ||
message: `Killed query ${queryId}`, | ||
} | ||
} |
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 @@ | ||
export type Action = 'kill-query' |
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
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
Oops, something went wrong.