-
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.
[225] Add some DevTools to help build and test the application
Bug: #225 Signed-off-by: Stéphane Bégaudeau <[email protected]>
- Loading branch information
1 parent
a271ac0
commit e802c31
Showing
39 changed files
with
1,738 additions
and
286 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,46 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import { useEffect, useState } from 'react'; | ||
import { DevToolsProps, DevToolsState } from './DevTools.types'; | ||
import { DevToolsDialog } from './dialog/DevToolsDialog'; | ||
|
||
export const DevTools = ({ children }: DevToolsProps) => { | ||
const [state, setState] = useState<DevToolsState>({ dialogOpen: false }); | ||
|
||
useEffect(() => { | ||
const listener = (event: KeyboardEvent) => { | ||
if (event.key === 'F12' && event.shiftKey) { | ||
setState((prevState) => ({ ...prevState, dialogOpen: true })); | ||
} | ||
}; | ||
document.addEventListener('keydown', listener); | ||
|
||
return () => document.removeEventListener('keydown', listener); | ||
}, []); | ||
|
||
const handleClose = () => setState((prevState) => ({ ...prevState, dialogOpen: false })); | ||
|
||
return ( | ||
<> | ||
<div id="devtools">{children}</div> | ||
<DevToolsDialog open={state.dialogOpen} onClose={handleClose} /> | ||
</> | ||
); | ||
}; |
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,26 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
export interface DevToolsProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export interface DevToolsState { | ||
dialogOpen: boolean; | ||
} |
51 changes: 51 additions & 0 deletions
51
frontend/svalyn-studio-app/src/devtools/console/ConsoleContextProvider.tsx
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,51 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { Message } from '../../snackbar/ErrorSnackbar.types'; | ||
import { | ||
ConsoleContextProviderProps, | ||
ConsoleContextProviderState, | ||
ConsoleContextValue, | ||
} from './ConsoleContextProvider.types'; | ||
|
||
export const ConsoleContext = React.createContext<ConsoleContextValue>({ | ||
messages: [], | ||
pushMessage: () => {}, | ||
clearMessages: () => {}, | ||
}); | ||
|
||
export const ConsoleContextProvider = ({ children }: ConsoleContextProviderProps) => { | ||
const [state, setState] = useState<ConsoleContextProviderState>({ | ||
messages: [], | ||
}); | ||
|
||
const pushMessage = (message: Message) => | ||
setState((prevState) => ({ ...prevState, messages: [...prevState.messages, message] })); | ||
|
||
const clearMessages = () => setState((prevState) => ({ ...prevState, messages: [] })); | ||
|
||
const value: ConsoleContextValue = { | ||
messages: [...state.messages], | ||
pushMessage, | ||
clearMessages, | ||
}; | ||
|
||
return <ConsoleContext.Provider value={value}>{children}</ConsoleContext.Provider>; | ||
}; |
34 changes: 34 additions & 0 deletions
34
frontend/svalyn-studio-app/src/devtools/console/ConsoleContextProvider.types.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,34 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import { Message } from '../../snackbar/ErrorSnackbar.types'; | ||
|
||
export interface ConsoleContextValue { | ||
messages: Message[]; | ||
pushMessage: (message: Message) => void; | ||
clearMessages: () => void; | ||
} | ||
|
||
export interface ConsoleContextProviderProps { | ||
children: React.ReactNode; | ||
} | ||
|
||
export interface ConsoleContextProviderState { | ||
messages: Message[]; | ||
} |
77 changes: 77 additions & 0 deletions
77
frontend/svalyn-studio-app/src/devtools/console/ConsoleLine.tsx
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,77 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import Box from '@mui/material/Box'; | ||
import Typography from '@mui/material/Typography'; | ||
import { Theme, alpha } from '@mui/material/styles'; | ||
import { VariantType } from '../../snackbar/ErrorSnackbar.types'; | ||
import { ConsoleLineProps } from './ConsoleLine.types'; | ||
|
||
const getTextColor = (theme: Theme, severity: VariantType): string => { | ||
let textColor = theme.palette.getContrastText(theme.palette.code.main); | ||
if (severity === 'error') { | ||
textColor = theme.palette.error[theme.palette.mode]; | ||
} else if (severity === 'warning') { | ||
textColor = theme.palette.warning[theme.palette.mode]; | ||
} else if (severity === 'success') { | ||
textColor = theme.palette.success[theme.palette.mode]; | ||
} | ||
return textColor; | ||
}; | ||
|
||
export const ConsoleLine = ({ index, line, severity }: ConsoleLineProps) => { | ||
return ( | ||
<Box | ||
key={index} | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
gap: (theme) => theme.spacing(2), | ||
paddingY: (theme) => theme.spacing(0.25), | ||
color: (theme) => alpha(getTextColor(theme, severity), 0.7), | ||
'&:hover': { | ||
color: (theme) => getTextColor(theme, severity), | ||
backgroundColor: (theme) => alpha(theme.palette.divider, 0.1), | ||
}, | ||
}} | ||
> | ||
<Typography | ||
variant="tcontent" | ||
sx={{ | ||
width: (theme) => theme.spacing(6), | ||
textAlign: 'right', | ||
textOverflow: 'ellipsis', | ||
overflow: 'hidden', | ||
whiteSpace: 'nowrap', | ||
userSelect: 'none', | ||
}} | ||
> | ||
{index} | ||
</Typography> | ||
<Typography | ||
variant="tcontent" | ||
sx={{ | ||
whiteSpace: 'nowrap', | ||
}} | ||
> | ||
{line} | ||
</Typography> | ||
</Box> | ||
); | ||
}; |
26 changes: 26 additions & 0 deletions
26
frontend/svalyn-studio-app/src/devtools/console/ConsoleLine.types.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,26 @@ | ||
/* | ||
* Copyright (c) 2023 Stéphane Bégaudeau. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and | ||
* associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, | ||
* subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all copies or substantial | ||
* portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT | ||
* LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
import { VariantType } from '../../snackbar/ErrorSnackbar.types'; | ||
|
||
export interface ConsoleLineProps { | ||
index: number; | ||
line: string; | ||
severity: VariantType; | ||
} |
Oops, something went wrong.