-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #142 from irontec/CDL-110-flag-edit-double-check
Flag edit double check
- Loading branch information
Showing
12 changed files
with
298 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import React, { | ||
useState, | ||
useEffect, | ||
forwardRef, | ||
ComponentType, | ||
FormEvent, | ||
} from 'react'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import Button from '@mui/material/Button'; | ||
import LinearProgress from '@mui/material/LinearProgress'; | ||
import { DialogContentText, Slide, SlideProps } from '@mui/material'; | ||
import CloseRoundedIcon from '@mui/icons-material/CloseRounded'; | ||
import _ from '../../services/translations/translate'; | ||
|
||
const Transition: ComponentType<any> = forwardRef(function ( | ||
props: SlideProps, | ||
ref: React.Ref<unknown> | ||
) { | ||
return <Slide {...props} direction='up' ref={ref} />; | ||
}); | ||
Transition.displayName = 'ConfirmDialogTransition'; | ||
|
||
interface ConfirmEditDialogProps { | ||
text: React.ReactNode; | ||
open: boolean; | ||
formEvent?: FormEvent<HTMLFormElement>; | ||
handleClose: () => void; | ||
handleSave: (e: FormEvent<HTMLFormElement>) => void; | ||
} | ||
|
||
export const ConfirmEditionDialog = (props: ConfirmEditDialogProps) => { | ||
const { open, handleClose, text, handleSave, formEvent } = props; | ||
const TOTAL_TIME = 100; | ||
const [progress, setProgress] = useState(TOTAL_TIME); | ||
|
||
useEffect(() => { | ||
let timer: NodeJS.Timeout | null = null; | ||
if (open) { | ||
timer = setInterval(() => { | ||
setProgress((oldProgress) => { | ||
if (oldProgress === 0) { | ||
return 0; | ||
} | ||
return oldProgress - 5; | ||
}); | ||
}, 250); | ||
} | ||
|
||
setProgress(TOTAL_TIME); | ||
|
||
return () => { | ||
if (timer) { | ||
clearInterval(timer); | ||
} | ||
}; | ||
}, [open]); | ||
|
||
return ( | ||
<Dialog | ||
open={open} | ||
TransitionComponent={Transition} | ||
keepMounted | ||
onClose={handleClose} | ||
aria-labelledby='alert-dialog-slide-title' | ||
aria-describedby='alert-dialog-slide-description' | ||
> | ||
<CloseRoundedIcon className='close-icon' onClick={handleClose} /> | ||
<img src='assets/img/warning-dialog.svg' className='modal-icon' /> | ||
<DialogTitle id='alert-dialog-slide-title'> | ||
{_('Save element')} | ||
</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText id='alert-dialog-slide-description'> | ||
{text} | ||
</DialogContentText> | ||
<LinearProgress variant='determinate' value={progress} /> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button | ||
onClick={() => { | ||
handleClose(); | ||
}} | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
hidden={progress !== 0} | ||
onClick={() => { | ||
if (formEvent) { | ||
handleSave(formEvent); | ||
} | ||
}} | ||
disabled={progress !== 0} | ||
> | ||
Apply | ||
</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
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
53 changes: 53 additions & 0 deletions
53
library/src/services/form/InverseRealtions/InverseRelationHelper.ts
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 { PropertySpec } from 'services/api'; | ||
|
||
export const collectReferences = ( | ||
obj: any, | ||
references: PropertySpec[] = [] | ||
): PropertySpec[] => { | ||
if (isReferenceObject(obj)) { | ||
references.push(obj); | ||
} | ||
|
||
Object.keys(obj).forEach((key) => { | ||
const value = obj[key]; | ||
if (isObject(value)) { | ||
collectReferences(value, references); | ||
} | ||
}); | ||
|
||
return references; | ||
}; | ||
|
||
function isObject(value: any): boolean { | ||
return value && typeof value === 'object'; | ||
} | ||
|
||
function isReferenceObject(obj: any): boolean { | ||
return isObject(obj) && obj.hasOwnProperty('$ref'); | ||
} | ||
|
||
export const findMatchingColumns = ( | ||
columnNames: string[], | ||
inverseRelations: PropertySpec[] | ||
): string[] => { | ||
return columnNames.filter((column) => { | ||
const singularColumn = getSingularForm(column); | ||
|
||
return inverseRelations.some((relation) => { | ||
return objectHasMatchingValue(relation, singularColumn); | ||
}); | ||
}); | ||
}; | ||
|
||
function getSingularForm(word: string): string { | ||
return word.endsWith('s') | ||
? word.slice(0, -1).toLowerCase() | ||
: word.toLowerCase(); | ||
} | ||
|
||
// Helper function to check if an object contains a value that includes a target string (case-insensitive) | ||
function objectHasMatchingValue(obj: any, target: string): boolean { | ||
return Object.values(obj).some((value) => { | ||
return typeof value === 'string' && value.toLowerCase().includes(target); | ||
}); | ||
} |
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,6 @@ | ||
import { | ||
collectReferences, | ||
findMatchingColumns, | ||
} from './InverseRelationHelper'; | ||
|
||
export { collectReferences, findMatchingColumns }; |
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,4 +1,5 @@ | ||
export * from './Field'; | ||
export * from './InverseRealtions'; | ||
export * from './FormFieldFactory/FormFieldFactory.styles'; | ||
export * from './FormFieldFactory'; | ||
export * from './types'; |
Oops, something went wrong.