forked from apache/kvrocks-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support namespace creation and deletion
- Loading branch information
1 parent
2cd86bc
commit d9624af
Showing
8 changed files
with
230 additions
and
46 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
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,44 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
'use server'; | ||
|
||
import { redirect } from "next/navigation"; | ||
import { createNamespace, deleteNamespace } from "./api"; | ||
import { revalidatePath } from "next/cache"; | ||
|
||
export async function createNamespaceAction(formData: FormData) { | ||
const formObj = Object.fromEntries(formData.entries()); | ||
if(typeof formObj['name'] === 'string') { | ||
const success = await createNamespace(formObj['name']); | ||
if(success) { | ||
revalidatePath('/cluster'); | ||
return true; | ||
} else { | ||
return false; | ||
} | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
export async function deleteNamespaceAction(name: string) { | ||
const result = deleteNamespace(name); | ||
revalidatePath('/cluster'); | ||
return result; | ||
} |
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 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
'use client'; | ||
import { createNamespaceAction } from "@/app/lib/actions"; | ||
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, TextField } from "@mui/material"; | ||
import { useCallback, useState } from "react"; | ||
|
||
export default function NamespaceCreation() { | ||
const [showDialog, setShowDialog] = useState(false); | ||
const openDialog = useCallback(() => setShowDialog(true), []); | ||
const closeDialog = useCallback(() => setShowDialog(false), []); | ||
return ( | ||
<> | ||
<Button variant="outlined" onClick={openDialog}>Create Namespace</Button> | ||
<Dialog | ||
open={showDialog} | ||
PaperProps={{ | ||
component: 'form', | ||
action: async (formData: FormData) => { | ||
const success = await createNamespaceAction(formData); | ||
if(success) { | ||
closeDialog(); | ||
} else { | ||
//todo: error handle | ||
} | ||
}, | ||
}} | ||
onClose={closeDialog} | ||
> | ||
<DialogTitle>Create Namespace</DialogTitle> | ||
<DialogContent | ||
sx={{ | ||
width: '500px' | ||
}} | ||
> | ||
<TextField | ||
autoFocus | ||
required | ||
name="name" | ||
label="Input Name" | ||
type="name" | ||
fullWidth | ||
variant="standard" | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={closeDialog}>Cancel</Button> | ||
<Button type="submit">Create</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</> | ||
) | ||
} |
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,81 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
'use client'; | ||
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Divider, Drawer, IconButton, List, ListItem, ListItemButton, ListItemIcon, ListItemText, Menu, MenuItem, Popover, Tooltip } from "@mui/material"; | ||
import MoreHorizIcon from '@mui/icons-material/MoreHoriz'; | ||
import { useCallback, useRef, useState } from "react"; | ||
import { deleteNamespaceAction } from "@/app/lib/actions"; | ||
|
||
export default function NamespaceItem({ item }: {item: string}) { | ||
const [hover, setHover] = useState<boolean>(false); | ||
const [showMenu, setShowMenu] = useState<boolean>(false); | ||
const listItemTextRef = useRef(null); | ||
const openMenu = useCallback(() => setShowMenu(true), []); | ||
const closeMenu = useCallback(() => (setShowMenu(false), setHover(false)), []); | ||
const [showDeleteConfirm, setShowDeleteConfirm] = useState<boolean>(false); | ||
const openDeleteConfirmDialog = useCallback(() => (setShowDeleteConfirm(true), closeMenu()), [closeMenu]); | ||
const closeDeleteConfirmDialog = useCallback(() => setShowDeleteConfirm(false), []); | ||
const confirmDelete = useCallback(async () => { | ||
await deleteNamespaceAction(item); | ||
closeMenu(); | ||
},[item, closeMenu]) | ||
return (<ListItem | ||
disablePadding | ||
secondaryAction={ | ||
hover && <IconButton onClick={openMenu} ref={listItemTextRef} > | ||
<MoreHorizIcon /> | ||
</IconButton> | ||
} | ||
onMouseEnter={() => setHover(true)} | ||
onMouseLeave={() => !showMenu && setHover(false)} | ||
> | ||
<ListItemButton sx={{paddingRight: '10px'}}> | ||
<Tooltip title={item} arrow> | ||
<ListItemText classes={{primary: 'overflow-hidden text-ellipsis text-nowrap'}} primary={`${item}`} /> | ||
</Tooltip> | ||
</ListItemButton> | ||
<Menu | ||
id={item} | ||
open={showMenu} | ||
onClose={closeMenu} | ||
anchorEl={listItemTextRef.current} | ||
anchorOrigin={{ | ||
vertical: 'center', | ||
horizontal: 'center', | ||
}} | ||
> | ||
<MenuItem color="red" onClick={openDeleteConfirmDialog}>Delete</MenuItem> | ||
</Menu> | ||
<Dialog | ||
open={showDeleteConfirm} | ||
> | ||
<DialogTitle>Confirm</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText> | ||
Please confirm you want to delete namespace {item} | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={closeDeleteConfirmDialog}>Cancel</Button> | ||
<Button onClick={confirmDelete} color="error">Delete</Button> | ||
</DialogActions> | ||
</Dialog> | ||
</ListItem>) | ||
} |
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