-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What problem does this PR solve? feat: Drop database #1841 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
- Loading branch information
Showing
8 changed files
with
130 additions
and
29 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,70 @@ | ||
'use client'; | ||
|
||
import { toast } from '@/components/hooks/use-toast'; | ||
import { | ||
Card, | ||
CardDescription, | ||
CardHeader, | ||
CardTitle | ||
} from '@/components/ui/card'; | ||
import { | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuTrigger | ||
} from '@/components/ui/dropdown-menu'; | ||
import { DropOption } from '@/lib/constant/common'; | ||
import { DropdownMenuItem } from '@radix-ui/react-dropdown-menu'; | ||
import { useRouter } from 'next/navigation'; | ||
import { dropDatabase } from './actions'; | ||
import DeleteIcon from '/public/delete.svg'; | ||
import MoreIcon from '/public/more.svg'; | ||
|
||
export const DeleteDropdown = ({ | ||
children, | ||
deleteItem | ||
}: React.PropsWithChildren<{ deleteItem: () => void }>) => { | ||
return ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger>{children}</DropdownMenuTrigger> | ||
<DropdownMenuContent> | ||
<DropdownMenuItem className="cursor-pointer" onClick={deleteItem}> | ||
<div className="flex items-center justify-between w-full"> | ||
<span>Drop</span> | ||
<DeleteIcon className="h-4 w-4"></DeleteIcon> | ||
</div> | ||
</DropdownMenuItem> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
}; | ||
|
||
export function DatabaseCard({ data }: { data: string }) { | ||
const router = useRouter(); | ||
const handleDelete = async () => { | ||
const ret = await dropDatabase({ | ||
database_name: data, | ||
drop_option: DropOption.IgnoreIfNotExists | ||
}); | ||
if (ret.error_code === 0) { | ||
router.refresh(); | ||
toast({ | ||
title: 'Drop Success', | ||
description: '' | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<Card className="w-full max-w-sm "> | ||
<CardHeader className="pt-3"> | ||
<div className="text-right"> | ||
<DeleteDropdown deleteItem={handleDelete}> | ||
<MoreIcon className="h-5 w-5 inline-block cursor-pointer"></MoreIcon> | ||
</DeleteDropdown> | ||
</div> | ||
<CardTitle className="text-1xl">{data}</CardTitle> | ||
<CardDescription>db description</CardDescription> | ||
</CardHeader> | ||
</Card> | ||
); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const ApiUrl = { | ||
databases: 'databases' | ||
databases: 'databases', | ||
database: 'database' | ||
}; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.