-
Notifications
You must be signed in to change notification settings - Fork 9
delete rule modal push #3799
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
AbhinavGonthina
wants to merge
2
commits into
feature/rules-dashboard
Choose a base branch
from
#3651-Rule-Deletion-Modal
base: feature/rules-dashboard
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
delete rule modal push #3799
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 |
|---|---|---|
| @@ -1 +1,5 @@ | ||
| // write api functions below here! | ||
| import axios from '../utils/axios'; | ||
|
|
||
| export const deleteRule = (ruleId: string) => { | ||
| return axios.post(`/rules/rule/${ruleId}/delete`); | ||
| }; |
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 |
|---|---|---|
| @@ -1 +1,24 @@ | ||
| // write hooks below here! | ||
| import { useMutation, useQueryClient } from 'react-query'; | ||
| import { deleteRule } from '../apis/rules.api'; | ||
| import { useToast } from './toasts.hooks'; | ||
|
|
||
| export const useDeleteRule = () => { | ||
| const queryClient = useQueryClient(); | ||
| const toast = useToast(); | ||
|
|
||
| return useMutation<void, Error, string>( | ||
| ['rules', 'delete'], | ||
| async (ruleId: string) => { | ||
| await deleteRule(ruleId); | ||
| }, | ||
| { | ||
| onSuccess: () => { | ||
| toast.success('Rule deleted successfully'); | ||
| queryClient.invalidateQueries(['rulesets']); | ||
| }, | ||
| onError: (error: Error) => { | ||
| toast.error(error.message); | ||
| } | ||
| } | ||
| ); | ||
| }; |
116 changes: 116 additions & 0 deletions
116
src/frontend/src/pages/RulesPage/RulesComponents/DeleteRuleModal.tsx
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,116 @@ | ||
| /* | ||
| * This file is part of NER's FinishLine and licensed under GNU AGPLv3. | ||
| * See the LICENSE file in the repository root folder for details. | ||
| */ | ||
|
|
||
| import { Box, Typography, Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@mui/material'; | ||
| import { Rule } from 'shared'; | ||
| import WarningIcon from '@mui/icons-material/Warning'; | ||
|
|
||
| interface DeleteRuleModalProps { | ||
| open: boolean; | ||
| onHide: () => void; | ||
| onConfirm: () => void; | ||
| rule: Rule; | ||
| totalRulesToDelete: number; | ||
| } | ||
|
|
||
| const DeleteRuleModal = ({ open, onHide, onConfirm, rule, totalRulesToDelete }: DeleteRuleModalProps) => { | ||
| const hasChildren = rule.subRuleIds.length > 0; | ||
| const titlePrefix = hasChildren ? 'Delete Rule Section:' : 'Delete Rule:'; | ||
|
|
||
| const modalTitle = rule.ruleContent | ||
| ? `${titlePrefix} ${rule.ruleCode} - ${rule.ruleContent}` | ||
| : `${titlePrefix} ${rule.ruleCode}`; | ||
|
|
||
| return ( | ||
| <Dialog | ||
| open={open} | ||
| onClose={onHide} | ||
| PaperProps={{ | ||
| sx: { | ||
| borderRadius: '20px', | ||
| width: '700px', | ||
| maxWidth: '700px', | ||
| backgroundColor: '#3a3a3a' | ||
| } | ||
| }} | ||
| > | ||
| {/* Header */} | ||
| <DialogTitle | ||
| sx={{ | ||
| backgroundColor: '#ef4345', | ||
| minHeight: '90px', | ||
| display: 'flex', | ||
| alignItems: 'center', | ||
| color: '#ffffff', | ||
| fontSize: '2rem', | ||
| fontWeight: 700, | ||
| paddingLeft: '24px' | ||
| }} | ||
| > | ||
| Confirm Deletion | ||
| </DialogTitle> | ||
|
|
||
| {/* Body */} | ||
| <DialogContent | ||
| sx={{ | ||
| backgroundColor: '#3a3a3a', | ||
| '&.MuiDialogContent-root': { paddingTop: '24px' } | ||
| }} | ||
| > | ||
| <Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}> | ||
| <Typography sx={{ color: '#ffffff', fontWeight: 400, fontSize: '1.25rem' }}>{modalTitle}</Typography> | ||
|
|
||
| <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}> | ||
| <WarningIcon sx={{ color: '#ef4345', fontSize: 30 }} /> | ||
| <Typography sx={{ color: '#ffffff', fontWeight: 600, fontSize: '1.25rem' }}> | ||
| {totalRulesToDelete} {totalRulesToDelete === 1 ? 'rule' : 'rules'} will be deleted | ||
| </Typography> | ||
| </Box> | ||
| </Box> | ||
| </DialogContent> | ||
|
|
||
| {/* Footer */} | ||
| <DialogActions sx={{ backgroundColor: '#3a3a3a', pb: 2, pr: 2 }}> | ||
| <Box sx={{ display: 'flex', gap: 2 }}> | ||
| <Button | ||
| onClick={onHide} | ||
| sx={{ | ||
| backgroundColor: '#ef4345', | ||
| color: '#ffffff', | ||
| fontSize: '1.125rem', | ||
| paddingY: 0, | ||
| px: 1.5, | ||
| minHeight: 0, | ||
| textTransform: 'none', | ||
| borderRadius: '8px', | ||
| '&:hover': { backgroundColor: '#d63c37' } | ||
| }} | ||
| > | ||
| Cancel | ||
| </Button> | ||
|
|
||
| <Button | ||
| onClick={onConfirm} | ||
| sx={{ | ||
| backgroundColor: '#ef4345', | ||
| color: '#ffffff', | ||
| fontSize: '1.125rem', | ||
| paddingY: 0, | ||
| px: 1.5, | ||
| minHeight: 0, | ||
| textTransform: 'none', | ||
| borderRadius: '8px', | ||
| '&:hover': { backgroundColor: '#d63c37' } | ||
| }} | ||
| > | ||
| Delete | ||
| </Button> | ||
| </Box> | ||
| </DialogActions> | ||
| </Dialog> | ||
| ); | ||
| }; | ||
|
|
||
| export default DeleteRuleModal; | ||
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,10 @@ | ||
| import { Rule } from 'shared'; | ||
|
|
||
| export const countRulesToDelete = (rule: Rule, allRules: Rule[]): number => { | ||
| let count = 1; | ||
| const children = allRules.filter((r) => rule.subRuleIds.includes(r.ruleId)); | ||
| for (const child of children) { | ||
| count += countRulesToDelete(child, allRules); | ||
| } | ||
| return count; | ||
| }; |
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.
This looks really good but we should use the prebuilt NERModal so it better matches the rest of the website. A good example might be the AdminToolsPage/ProjectsConfig/PartTagDeleteModal