-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added preset renaming #148
Open
FyWolf
wants to merge
1
commit into
fugasjunior:dev
Choose a base branch
from
FyWolf:master
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 13 additions & 0 deletions
13
...src/main/java/cz/forgottenempire/servermanager/modpreset/dtos/RenamePresetRequestDto.java
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 @@ | ||
package cz.forgottenempire.servermanager.modpreset.dtos; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class RenamePresetRequestDto { | ||
|
||
@NotEmpty | ||
private String name; | ||
} |
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 |
---|---|---|
|
@@ -17,7 +17,6 @@ import {Backdrop, Box, CircularProgress, Divider, Modal, Stack, Toolbar} from "@ | |
import Typography from "@mui/material/Typography"; | ||
import IconButton from '@mui/material/IconButton'; | ||
import DeleteIcon from '@mui/icons-material/Delete'; | ||
import EditIcon from '@mui/icons-material/Edit'; | ||
import SERVER_NAMES from "../../util/serverNames"; | ||
import {toast} from "material-react-toastify"; | ||
import ListBuilder from "../../UI/ListBuilder/ListBuilder"; | ||
|
@@ -29,6 +28,10 @@ import DownloadIcon from '@mui/icons-material/Download'; | |
import {ModPresetDto, ModPresetModDto} from "../../dtos/ModPresetDto"; | ||
import {ModDto} from "../../dtos/ModDto.ts"; | ||
import {ServerType} from "../../dtos/ServerDto.ts"; | ||
import DriveFileRenameOutlineOutlinedIcon from '@mui/icons-material/DriveFileRenameOutlineOutlined'; | ||
import RenamePresetDialog from "./RenamePresetDialog"; | ||
import MemoryIcon from "@mui/icons-material/Memory"; | ||
import {renameModPreset} from "../../services/modPresetsService"; | ||
|
||
export default function PresetsManagement() { | ||
const [initialLoading, setInitialLoading] = useState(true); | ||
|
@@ -38,6 +41,8 @@ export default function PresetsManagement() { | |
const [selectedMods, setSelectedMods] = useState<Array<ModPresetModDto>>([]); | ||
const [availableMods, setAvailableMods] = useState<Array<ModPresetModDto>>([]); | ||
const [isUploadInProgress, setIsUploadInProgress] = useState(false); | ||
const [renamePresetDialogOpen, setRenamePresetDialogOpen] = useState(false); | ||
const [selectedPresetId, setSelectedPresetId] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
async function fetchPresets() { | ||
|
@@ -177,6 +182,29 @@ export default function PresetsManagement() { | |
} | ||
} | ||
|
||
const handlePresedDialogOpen = (presetId: string) => { | ||
setSelectedPresetId(presetId); | ||
setRenamePresetDialogOpen(true); | ||
} | ||
|
||
const handlePresedDialogClose = () => { | ||
setRenamePresetDialogOpen(false); | ||
setSelectedPresetId(null); | ||
} | ||
|
||
const handleRenameNewPreset = async (presetName: string, presetId: string) => { | ||
setRenamePresetDialogOpen(false); | ||
setSelectedPresetId(null); | ||
|
||
const request = { | ||
name: presetName, | ||
} | ||
|
||
await renameModPreset(presetId, request); | ||
toast.success(`Preset '${presetName}' successfully renamed`); | ||
window.location.reload(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using Something like this should work: const newPresets = [...presets]; // create a copy of the original state
const renamedPreset = newPresets.find(preset => preset.id === presetId); // find the renamed preset by ID
renamedPreset.name = presetName; // edit the preset name
setPresets(newPresets); // set the new state with renamed preset This should automatically re-render the component with the new state. |
||
} | ||
|
||
return ( | ||
<> | ||
<Backdrop open={isUploadInProgress}> | ||
|
@@ -233,7 +261,13 @@ export default function PresetsManagement() { | |
<TableCell> | ||
<IconButton aria-label="edit" | ||
onClick={() => handleOpenEdit(preset)}> | ||
<EditIcon color="primary"/> | ||
<MemoryIcon color="primary"/> | ||
</IconButton> | ||
</TableCell> | ||
<TableCell> | ||
<IconButton aria-label="rename" | ||
onClick={() => handlePresedDialogOpen(preset.id as string)}> | ||
<DriveFileRenameOutlineOutlinedIcon color="primary"/> | ||
</IconButton> | ||
</TableCell> | ||
<TableCell> | ||
|
@@ -264,6 +298,9 @@ export default function PresetsManagement() { | |
/> | ||
</Box> | ||
</Modal> | ||
<RenamePresetDialog open={renamePresetDialogOpen} onClose={handlePresedDialogClose} | ||
onConfirmClicked={handleRenameNewPreset} presetId={selectedPresetId} | ||
/> | ||
</> | ||
) | ||
} |
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,53 @@ | ||
import {ChangeEvent, useState} from "react"; | ||
import Button from '@mui/material/Button'; | ||
import TextField from '@mui/material/TextField'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
|
||
type RenamePresetDialogProps = { | ||
open: boolean, | ||
onConfirmClicked: (name: string, id: string) => void, | ||
onClose: () => void, | ||
presetId: string | null | ||
} | ||
|
||
const RenamePresetDialog = (props: RenamePresetDialogProps) => { | ||
const [presetName, setPresetName] = useState(""); | ||
|
||
const handlePresetNameChange = (e: ChangeEvent<HTMLInputElement>) => { | ||
setPresetName(e.target.value); | ||
} | ||
|
||
const handleConfirmClicked = () => { | ||
if (props.presetId) { // Ensure the ID is available | ||
props.onConfirmClicked(presetName, props.presetId); | ||
setPresetName(""); // Reset the input field | ||
FyWolf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
}; | ||
|
||
return ( | ||
<Dialog open={props.open} onClose={props.onClose} fullWidth maxWidth="xs"> | ||
<DialogTitle>Rename preset</DialogTitle> | ||
<DialogContent> | ||
<TextField | ||
autoFocus | ||
margin="dense" | ||
id="name" | ||
label="Preset name" | ||
fullWidth | ||
variant="standard" | ||
value={presetName} | ||
onChange={handlePresetNameChange} | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={props.onClose}>Cancel</Button> | ||
<Button onClick={handleConfirmClicked}>Confirm</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
}; | ||
|
||
export default RenamePresetDialog; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe PATCH would be more accurate as just a one attribute is being changed. PUT would be appropriate when the whole preset would be replaced, including the mods.
I'd go for either of these solutions:
@PatchMapping("/rename/{id}")
@PutMapping("/{id}")
and also send the mods in the body when renaming the preset.I'd personally prefer option 2), but I'm fine with either one.