-
Couldn't load subscription status.
- Fork 60
Add Confirmation Before Dev Tool Removal and Modification [AARD-2033]
#1265
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
Open
ryanzhangofficial
wants to merge
18
commits into
dev
Choose a base branch
from
ryan/2033/add-confirmation-before-dev-tool-removal
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 4 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
10988c4
Add zone utils
ryanzhangofficial f1c94c5
Add zone removal modal
ryanzhangofficial 45d77da
chore: formatting
ryanzhangofficial 3f794cc
Merge branch 'dev' into ryan/2033/add-confirmation-before-dev-tool-re…
ryanzhangofficial 2d92ac9
Update toasts and descs
ryanzhangofficial 10c8f1a
Add permanent modification
ryanzhangofficial cde88ab
Update temporary modification
ryanzhangofficial f9d0900
chore: formatting
ryanzhangofficial 988f39a
Merge branch 'dev' into ryan/2033/add-confirmation-before-dev-tool-re…
ryanzhangofficial ddff42f
cleanup
ryanzhangofficial 74d249f
Update removal to modification
ryanzhangofficial 99f51e9
Update DevtoolZoneUtils for restructure & BaseZonePreferences
ryanzhangofficial 273982e
Update interfaces
ryanzhangofficial 9527d0a
chore: formatting
ryanzhangofficial 72888a1
chore: formatting
ryanzhangofficial 232faca
fix: save/cancel button dissappearing
ryanzhangofficial 0aba2ae
Add caching for manual scoring zones
ryanzhangofficial be65676
Update devtool panel to include devhandlers only
ryanzhangofficial 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 hidden or 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,82 @@ | ||
| import { Button, Dialog, DialogActions, DialogContent, DialogTitle, Stack, Typography } from "@mui/material" | ||
| import type React from "react" | ||
| import { useState } from "react" | ||
| import { globalAddToast } from "../components/GlobalUIControls" | ||
|
|
||
| interface DevtoolZoneRemovalModalProps { | ||
| isOpen: boolean | ||
| onClose: () => void | ||
| zoneType: "scoring" | "protected" | ||
| zoneName: string | ||
| onTemporaryRemoval: () => void | ||
| onPermanentRemoval: () => void | ||
| } | ||
|
|
||
| const DevtoolZoneRemovalModal: React.FC<DevtoolZoneRemovalModalProps> = ({ | ||
| isOpen, | ||
| onClose, | ||
| zoneType, | ||
| zoneName, | ||
| onTemporaryRemoval, | ||
| onPermanentRemoval, | ||
| }) => { | ||
| const [isRemoving, setIsRemoving] = useState(false) | ||
|
|
||
| const handleTemporaryRemoval = () => { | ||
| onTemporaryRemoval() | ||
| onClose() | ||
| } | ||
|
|
||
| const handlePermanentRemoval = async () => { | ||
| setIsRemoving(true) | ||
| try { | ||
| await onPermanentRemoval() | ||
| globalAddToast?.("info", "Zone Removed", `${zoneName} has been permanently removed from dev tools.`) | ||
| } catch (error) { | ||
| globalAddToast?.("error", "Removal Failed", "Failed to permanently remove zone from dev tools cache.") | ||
| console.error("Failed to remove zone from dev tools:", error) | ||
| } finally { | ||
| setIsRemoving(false) | ||
| onClose() | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <Dialog open={isOpen} onClose={onClose} maxWidth="sm" fullWidth> | ||
ryanzhangofficial marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <DialogTitle>Remove {zoneType === "scoring" ? "Scoring" : "Protected"} Zone</DialogTitle> | ||
| <DialogContent> | ||
| <Stack spacing={2}> | ||
| <Typography variant="body1"> | ||
| The {zoneType} zone "{zoneName}" was placed using dev tools and is cached. | ||
| </Typography> | ||
| <Typography variant="body2" color="text.secondary"> | ||
| Choose how you'd like to remove it: | ||
| </Typography> | ||
| <Stack spacing={1}> | ||
| <Typography variant="body2"> | ||
| <strong>Temporary removal:</strong> Remove zone until next field reload. The zone will | ||
| reappear when you refresh or reload the field. | ||
| </Typography> | ||
| <Typography variant="body2"> | ||
| <strong>Permanent removal:</strong> Remove zone from dev tools cache. This will prevent it | ||
| from reappearing on future loads. | ||
| </Typography> | ||
| </Stack> | ||
| </Stack> | ||
| </DialogContent> | ||
| <DialogActions> | ||
| <Button onClick={onClose} disabled={isRemoving}> | ||
| Cancel | ||
| </Button> | ||
| <Button onClick={handleTemporaryRemoval} disabled={isRemoving} variant="outlined" color="warning"> | ||
| Temporary Removal | ||
| </Button> | ||
| <Button onClick={handlePermanentRemoval} disabled={isRemoving} variant="contained" color="error"> | ||
| {isRemoving ? "Removing..." : "Permanent Removal"} | ||
| </Button> | ||
| </DialogActions> | ||
| </Dialog> | ||
| ) | ||
| } | ||
|
|
||
| export default DevtoolZoneRemovalModal | ||
This file contains hidden or 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 hidden or 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,117 @@ | ||
| import MirabufCachingService, { MiraType } from "@/mirabuf/MirabufLoader" | ||
| import FieldMiraEditor from "@/mirabuf/FieldMiraEditor" | ||
| import PreferencesSystem from "@/systems/preferences/PreferencesSystem" | ||
| import type { ScoringZonePreferences, ProtectedZonePreferences } from "@/systems/preferences/PreferenceTypes" | ||
| import World from "@/systems/World" | ||
|
|
||
| export type ZoneType = "scoring" | "protected" | ||
|
|
||
| /** | ||
| * Checks if a zone was originally placed by dev tools by comparing it with the cached dev tool data. | ||
| */ | ||
| export function isZoneFromDevtools( | ||
| zone: ScoringZonePreferences | ProtectedZonePreferences, | ||
| zoneType: ZoneType | ||
| ): boolean { | ||
| const field = World.sceneRenderer.mirabufSceneObjects.getField() | ||
| if (!field) return false | ||
|
|
||
| const parts = field.mirabufInstance.parser.assembly.data?.parts | ||
| if (!parts) return false | ||
|
|
||
| const editor = new FieldMiraEditor(parts) | ||
|
|
||
| if (zoneType === "scoring") { | ||
| const devtoolZones = editor.getUserData("devtool:scoring_zones") as ScoringZonePreferences[] | undefined | ||
| if (!devtoolZones) return false | ||
|
|
||
| return devtoolZones.some( | ||
| devZone => | ||
| devZone.name === zone.name && | ||
| devZone.alliance === zone.alliance && | ||
| devZone.parentNode === zone.parentNode && | ||
| JSON.stringify(devZone.deltaTransformation) === JSON.stringify(zone.deltaTransformation) | ||
| ) | ||
| } else { | ||
| // For protected zones, we'd need to add dev tool support first | ||
| // For now, return false as protected zones don't have dev tool support yet | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Removes a zone from dev tools cache permanently. | ||
| */ | ||
| export async function removeZoneFromDevtools( | ||
| zone: ScoringZonePreferences | ProtectedZonePreferences, | ||
| zoneType: ZoneType | ||
| ): Promise<void> { | ||
| const field = World.sceneRenderer.mirabufSceneObjects.getField() | ||
| if (!field) throw new Error("No field loaded") | ||
|
|
||
| const parts = field.mirabufInstance.parser.assembly.data?.parts | ||
| if (!parts) throw new Error("No field parts found") | ||
|
|
||
| const editor = new FieldMiraEditor(parts) | ||
|
|
||
| if (zoneType === "scoring") { | ||
ryanzhangofficial marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const devtoolZones = editor.getUserData("devtool:scoring_zones") as ScoringZonePreferences[] | undefined | ||
| if (!devtoolZones) return | ||
|
|
||
| // Remove the zone from dev tool data | ||
| const filteredZones = devtoolZones.filter( | ||
| devZone => | ||
| !( | ||
| devZone.name === zone.name && | ||
| devZone.alliance === zone.alliance && | ||
| devZone.parentNode === zone.parentNode && | ||
| JSON.stringify(devZone.deltaTransformation) === JSON.stringify(zone.deltaTransformation) | ||
| ) | ||
| ) | ||
|
|
||
| // Update the dev tool data | ||
| if (filteredZones.length === 0) { | ||
| editor.removeUserData("devtool:scoring_zones") | ||
| } else { | ||
| editor.setUserData("devtool:scoring_zones", filteredZones) | ||
| } | ||
|
|
||
| // Update field preferences to match the filtered dev tool data | ||
| if (field.fieldPreferences) { | ||
| field.fieldPreferences.scoringZones = filteredZones | ||
| PreferencesSystem.savePreferences?.() | ||
| field.updateScoringZones() | ||
| } | ||
|
|
||
| // Persist changes to cache | ||
| const assembly = field.mirabufInstance.parser.assembly | ||
| const cacheId = field.cacheId | ||
| if (cacheId) { | ||
| const success = await MirabufCachingService.persistDevtoolChanges(cacheId, MiraType.FIELD, assembly) | ||
| if (!success) { | ||
| throw new Error("Failed to persist changes to cache") | ||
| } | ||
| } | ||
| } else { | ||
| throw new Error("Protected zone dev tool removal not yet implemented") | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets all zones that exist in dev tools for a given type. | ||
| */ | ||
| export function getDevtoolZones(zoneType: ZoneType): ScoringZonePreferences[] | ProtectedZonePreferences[] | undefined { | ||
| const field = World.sceneRenderer.mirabufSceneObjects.getField() | ||
| if (!field) return undefined | ||
|
|
||
| const parts = field.mirabufInstance.parser.assembly.data?.parts | ||
| if (!parts) return undefined | ||
|
|
||
| const editor = new FieldMiraEditor(parts) | ||
|
|
||
| if (zoneType === "scoring") { | ||
| return editor.getUserData("devtool:scoring_zones") as ScoringZonePreferences[] | undefined | ||
| } else { | ||
| return undefined | ||
| } | ||
| } | ||
Oops, something went wrong.
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.
should probably be renamed if this is being generalized