Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions src/custom/YamlDialog/YamlDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React from 'react';
import {
Dialog,
DialogActions,
DialogContent,
Divider,
IconButton,
Tooltip
} from '../../base';
import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
import DeleteIcon from '@mui/icons-material/Delete';
import FullscreenIcon from '@mui/icons-material/Fullscreen';
import SaveIcon from '@mui/icons-material/Save';
import { YamlDialogTitleText, StyledCodeMirrorWrapper } from './style';

interface YamlDialogProps {
name: string;
open: boolean;
fullScreen?: boolean;
config_file: string;
isReadOnly?: boolean;
onClose: () => void;
onToggleFullScreen: () => void;
onYamlChange: (value: string) => void;
onUpdate?: () => void;
onDelete?: () => void;
editorComponent?: React.ReactNode;
}

const YamlDialog = React.forwardRef<HTMLDivElement, YamlDialogProps>(
(
{
name,
open,
fullScreen = false,
isReadOnly = false,
onClose,
onToggleFullScreen,
onUpdate,
onDelete,
editorComponent
},
ref
) => {
return (
<Dialog
ref={ref}
aria-labelledby="yaml-dialog-title"
open={open}
onClose={onClose}
maxWidth="md"
fullScreen={fullScreen}
fullWidth={!fullScreen}
>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
padding: '1rem'
}}
id="yaml-dialog-title"
>
<YamlDialogTitleText variant="h6">{name}</YamlDialogTitleText>
<Tooltip title={fullScreen ? 'Exit Fullscreen' : 'Fullscreen'} arrow placement="bottom">
<IconButton onClick={onToggleFullScreen} size="large">
{fullScreen ? <FullscreenExitIcon /> : <FullscreenIcon />}
</IconButton>
</Tooltip>
</div>
<Divider />
<DialogContent>
<StyledCodeMirrorWrapper fullScreen={fullScreen}>{editorComponent}</StyledCodeMirrorWrapper>
</DialogContent>
<Divider />
{!isReadOnly && (
<DialogActions>
<Tooltip title="Update Pattern">
<IconButton
aria-label="Update"
color="primary"
onClick={onUpdate}
size="large"
>
<SaveIcon />
</IconButton>
</Tooltip>
<Tooltip title="Delete Filter">
<IconButton
aria-label="Delete"
color="primary"
onClick={onDelete}
size="large"
>
<DeleteIcon />
</IconButton>
</Tooltip>
</DialogActions>
)}
</Dialog>
);
}
);

YamlDialog.displayName = 'YamlDialog';

export default YamlDialog;
1 change: 1 addition & 0 deletions src/custom/YamlDialog/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as YamlDialog } from './YamlDialog';
19 changes: 19 additions & 0 deletions src/custom/YamlDialog/style.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { styled } from '@mui/material';
import { DialogTitle } from '../../base/DialogTitle';

export const YamlDialogTitleText = styled(DialogTitle)(() => ({
fontWeight: 600,
fontSize: '1.25rem',
flex: 1
}));

export const StyledCodeMirrorWrapper = styled('div')<{ fullScreen?: boolean }>(
({ fullScreen }) => ({
height: fullScreen ? '100vh' : '400px',
overflow: 'auto',
'& .CodeMirror': {
height: '100%',
fontFamily: 'monospace'
}
})
);
2 changes: 2 additions & 0 deletions src/custom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { TransferListProps } from './TransferModal/TransferList/TransferList';
import UniversalFilter, { UniversalFilterProps } from './UniversalFilter';
import { UserTableAvatarInfo, UsersTable } from './UsersTable';
import { VisibilityChipMenu } from './VisibilityChipMenu';
import { YamlDialog } from './YamlDialog';
export { CatalogCard } from './CatalogCard';
export { CatalogFilterSidebar } from './CatalogFilterSection';
export type { FilterListType } from './CatalogFilterSection';
Expand All @@ -75,6 +76,7 @@ export { Terminal } from './Terminal';
export { TOC } from './TOCChapter';
export { TOCLearning } from './TOCLearning';
export { UserSearchField } from './UserSearchField';
export { YamlDialog } from './YamlDialog';

export {
ActionButton,
Expand Down
2 changes: 1 addition & 1 deletion src/icons/Description/DescriptionIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KEPPEL_GREEN_FILL, DEFAULT_HEIGHT, DEFAULT_WIDTH, DEFAULT_FILL_NONE } from '../../constants/constants';
import { DEFAULT_HEIGHT, DEFAULT_WIDTH, DEFAULT_FILL_NONE } from '../../constants/constants';
import { IconProps } from '../types';

const DescriptionIcon = ({
Expand Down