@rivm-loculus-tools/sequence-editor 0.0.0-stage → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitkeep +0 -0
- package/CHANGELOG.md +30 -0
- package/LICENSE +288 -0
- package/eslint.config.js +16 -0
- package/package.json +144 -3
- package/scripts/update-exports.js +9 -0
- package/src/classes/services/EditorWorkerService/EditorWorkerService.ts +163 -0
- package/src/classes/services/EditorWorkerService/index.ts +1 -0
- package/src/classes/services/SequenceEditorEventBusService/SequenceEditorEventBusService.ts +37 -0
- package/src/classes/services/SequenceEditorEventBusService/index.ts +1 -0
- package/src/classes/workers/EngineWorker/EngineWorker.ts +196 -0
- package/src/classes/workers/EngineWorker/index.ts +1 -0
- package/src/components/app/App/App.tsx +22 -0
- package/src/components/app/App/index.ts +1 -0
- package/src/components/pages/EmptyWorkspace.tsx +43 -0
- package/src/components/pages/SequenceEditorErrorPage/SequenceEditorErrorPage.tsx +16 -0
- package/src/components/pages/SequenceEditorErrorPage/index.ts +1 -0
- package/src/components/pages/SequenceEditorMainPage/SequenceEditorMainPage.tsx +76 -0
- package/src/components/pages/SequenceEditorMainPage/index.ts +1 -0
- package/src/components/ui/SequenceEditor/SequenceEditor.tsx +896 -0
- package/src/components/ui/SequenceEditor/SequenceEditorGotoPositionDialog.tsx +108 -0
- package/src/components/ui/SequenceEditor/SequenceEditorStatusBar.tsx +72 -0
- package/src/components/ui/SequenceEditor/index.ts +1 -0
- package/src/components/ui/SequenceEditorPage/SequenceEditorPage.tsx +23 -0
- package/src/components/ui/SequenceEditorPage/index.ts +1 -0
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawer.tsx +234 -0
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerColorForm.tsx +73 -0
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerKeyboardShortcuts.tsx +230 -0
- package/src/components/ui/SequenceEditorPageDrawer/index.ts +1 -0
- package/src/components/ui/SequenceEditorPageHeader/SequenceEditorPageHeader.tsx +71 -0
- package/src/components/ui/SequenceEditorPageHeader/index.ts +1 -0
- package/src/components/ui/SequenceEditorSearchBar/SequenceEditorSearchBar.tsx +35 -0
- package/src/components/ui/SequenceEditorSearchBar/index.ts +1 -0
- package/src/constants/editor.ts +15 -0
- package/src/constants/index.ts +3 -0
- package/src/constants/keyboard.ts +154 -0
- package/src/constants/palette.ts +227 -0
- package/src/models/editor.ts +6 -0
- package/src/models/index.ts +3 -0
- package/src/models/model.ts +295 -0
- package/src/models/palette.ts +68 -0
- package/src/stores/sequenceEditorStore/index.ts +1 -0
- package/src/stores/sequenceEditorStore/sequenceEditorStore.ts +103 -0
- package/src/utils/EditorUtil/EditorUtil.ts +892 -0
- package/src/utils/EditorUtil/index.ts +1 -0
- package/src/utils/EngineErrorUtil/EngineErrorUtil.ts +25 -0
- package/src/utils/PaletteUtil/PaletteUtil.ts +31 -0
- package/src/utils/PaletteUtil/index.ts +1 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +32 -0
- package/vite.config.ts +177 -0
- package/README.md +0 -3
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { TextField } from '@mui/material';
|
|
2
|
+
import type {
|
|
3
|
+
WithDialogRefMethods,
|
|
4
|
+
WithDialogRenderProps,
|
|
5
|
+
} from '@gen-epix/ui-core-components/hoc/withDialog';
|
|
6
|
+
import { withDialog } from '@gen-epix/ui-core-components/hoc/withDialog';
|
|
7
|
+
import type { DialogAction } from '@gen-epix/ui-core-components/components/Dialog';
|
|
8
|
+
import type {
|
|
9
|
+
ChangeEvent,
|
|
10
|
+
KeyboardEvent,
|
|
11
|
+
ReactElement,
|
|
12
|
+
} from 'react';
|
|
13
|
+
import {
|
|
14
|
+
useCallback,
|
|
15
|
+
useEffect,
|
|
16
|
+
useRef,
|
|
17
|
+
useState,
|
|
18
|
+
} from 'react';
|
|
19
|
+
|
|
20
|
+
const GOTO_POSITION_REGEX = /^(?:\d+|,\d+|\d+,\d+)$/;
|
|
21
|
+
|
|
22
|
+
export interface SequenceEditorGotoPositionDialogOpenProps {
|
|
23
|
+
//
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface SequenceEditorGotoPositionDialogProps extends WithDialogRenderProps<SequenceEditorGotoPositionDialogOpenProps> {
|
|
27
|
+
onGotoPosition: (x: null | number, y: null | number) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export type SequenceEditorGotoPositionDialogRefMethods = WithDialogRefMethods<SequenceEditorGotoPositionDialogProps, SequenceEditorGotoPositionDialogOpenProps>;
|
|
31
|
+
|
|
32
|
+
export const SequenceEditorGotoPositionDialog = withDialog<SequenceEditorGotoPositionDialogProps, SequenceEditorGotoPositionDialogOpenProps>((
|
|
33
|
+
{
|
|
34
|
+
onActionsChange,
|
|
35
|
+
onClose,
|
|
36
|
+
onGotoPosition,
|
|
37
|
+
}: SequenceEditorGotoPositionDialogProps,
|
|
38
|
+
): ReactElement => {
|
|
39
|
+
const [value, setValue] = useState('');
|
|
40
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
41
|
+
const isValid = value === '' || GOTO_POSITION_REGEX.test(value);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
inputRef.current?.focus();
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
const onChange = useCallback((event: ChangeEvent<HTMLInputElement>) => {
|
|
48
|
+
setValue(event.target.value);
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
const onSubmit = useCallback(() => {
|
|
52
|
+
if (!isValid) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const [x, y] = value.split(',');
|
|
56
|
+
onGotoPosition(x ? Number(x) : null, y ? Number(y) : null);
|
|
57
|
+
onClose?.();
|
|
58
|
+
}, [isValid, onClose, onGotoPosition, value]);
|
|
59
|
+
|
|
60
|
+
const onKeyDown = useCallback((event: KeyboardEvent<HTMLInputElement>) => {
|
|
61
|
+
if (event.key === 'Enter') {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
onSubmit();
|
|
64
|
+
}
|
|
65
|
+
}, [onSubmit]);
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
const actions: DialogAction[] = [];
|
|
69
|
+
actions.push(
|
|
70
|
+
{
|
|
71
|
+
color: 'secondary',
|
|
72
|
+
label: 'Close',
|
|
73
|
+
onClick: onClose,
|
|
74
|
+
variant: 'outlined',
|
|
75
|
+
},
|
|
76
|
+
);
|
|
77
|
+
actions.push(
|
|
78
|
+
{
|
|
79
|
+
color: 'primary',
|
|
80
|
+
disabled: !isValid,
|
|
81
|
+
label: 'Ok',
|
|
82
|
+
onClick: onSubmit,
|
|
83
|
+
variant: 'contained',
|
|
84
|
+
},
|
|
85
|
+
);
|
|
86
|
+
onActionsChange?.(actions);
|
|
87
|
+
}, [isValid, onActionsChange, onClose, onSubmit]);
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<TextField
|
|
91
|
+
error={!isValid}
|
|
92
|
+
fullWidth
|
|
93
|
+
helperText={'Use x, ,y, or x,y.'}
|
|
94
|
+
inputRef={inputRef}
|
|
95
|
+
label={'Position'}
|
|
96
|
+
onChange={onChange}
|
|
97
|
+
onKeyDown={onKeyDown}
|
|
98
|
+
placeholder={'x or ,y or x,y'}
|
|
99
|
+
value={value}
|
|
100
|
+
/>
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
}, {
|
|
104
|
+
defaultTitle: 'Goto position (x) or (,y) or (x,y)',
|
|
105
|
+
fullWidth: true,
|
|
106
|
+
maxWidth: 'xs',
|
|
107
|
+
testId: 'SequenceEditorGotoPositionDialog',
|
|
108
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Box,
|
|
3
|
+
darken,
|
|
4
|
+
useTheme,
|
|
5
|
+
} from '@mui/material';
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
import { useStore } from 'zustand';
|
|
8
|
+
|
|
9
|
+
import { sequenceEditorStore } from '../../../stores/sequenceEditorStore';
|
|
10
|
+
import { EditorUtil } from '../../../utils/EditorUtil';
|
|
11
|
+
|
|
12
|
+
export const SequenceEditorStatusBar = () => {
|
|
13
|
+
const theme = useTheme();
|
|
14
|
+
const latestMessage = useStore(sequenceEditorStore, (state) => state.latestMessage);
|
|
15
|
+
const meta = useStore(sequenceEditorStore, (state) => state.meta);
|
|
16
|
+
const selection = useStore(sequenceEditorStore, (state) => state.selection);
|
|
17
|
+
|
|
18
|
+
const normalizedSelection = useMemo(
|
|
19
|
+
() => EditorUtil.getStatusBarSelectionStats(selection, meta),
|
|
20
|
+
[meta, selection],
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<Box
|
|
25
|
+
sx={{
|
|
26
|
+
backgroundColor: darken(theme.palette.background.paper, 0.1),
|
|
27
|
+
borderTop: `1px solid ${darken(theme.palette.background.paper, 0.2)}`,
|
|
28
|
+
fontSize: theme.typography.caption,
|
|
29
|
+
height: '100%',
|
|
30
|
+
width: '100%',
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
<Box
|
|
34
|
+
sx={{
|
|
35
|
+
'& > div': {
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
borderLeft: `1px solid ${darken(theme.palette.background.paper, 0.2)}`,
|
|
38
|
+
display: 'flex',
|
|
39
|
+
paddingLeft: theme.spacing(1),
|
|
40
|
+
},
|
|
41
|
+
'& > div:first-of-type': {
|
|
42
|
+
borderLeft: 'none',
|
|
43
|
+
},
|
|
44
|
+
display: 'grid',
|
|
45
|
+
gap: 4,
|
|
46
|
+
gridTemplateColumns: '1fr repeat(5, max-content)',
|
|
47
|
+
paddingLeft: theme.spacing(1),
|
|
48
|
+
paddingRight: theme.spacing(1),
|
|
49
|
+
}}
|
|
50
|
+
>
|
|
51
|
+
<Box>
|
|
52
|
+
{latestMessage ?? ''}
|
|
53
|
+
</Box>
|
|
54
|
+
<Box>
|
|
55
|
+
{`Pos: ${normalizedSelection.pos}`}
|
|
56
|
+
</Box>
|
|
57
|
+
<Box>
|
|
58
|
+
{`Selected seqs: ${normalizedSelection.selectedSeqs}`}
|
|
59
|
+
</Box>
|
|
60
|
+
<Box>
|
|
61
|
+
{`Cols: ${normalizedSelection.cols}`}
|
|
62
|
+
</Box>
|
|
63
|
+
<Box>
|
|
64
|
+
{`Total selected chars: ${normalizedSelection.totalSelectedChars}`}
|
|
65
|
+
</Box>
|
|
66
|
+
<Box>
|
|
67
|
+
{`Alignment: ${meta?.alignmentWidth ?? '0'} sequences ${meta?.sequenceCount ?? '0'} pos.`}
|
|
68
|
+
</Box>
|
|
69
|
+
</Box>
|
|
70
|
+
</Box>
|
|
71
|
+
);
|
|
72
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SequenceEditor';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { PageCommon } from '@rivm-loculus-tools/common-frontend/components/page';
|
|
2
|
+
import type { PropsWithChildren } from 'react';
|
|
3
|
+
|
|
4
|
+
import { SequenceEditorPageDrawer } from '../SequenceEditorPageDrawer';
|
|
5
|
+
import { SequenceEditorPageHeader } from '../SequenceEditorPageHeader';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export type SequenceEditorPageProps = PropsWithChildren<{
|
|
9
|
+
isNoInteraction: boolean;
|
|
10
|
+
}>;
|
|
11
|
+
|
|
12
|
+
export const SequenceEditorPage = ({ children, isNoInteraction }: SequenceEditorPageProps) => {
|
|
13
|
+
return (
|
|
14
|
+
<PageCommon
|
|
15
|
+
drawerComponent={<SequenceEditorPageDrawer />}
|
|
16
|
+
headerComponent={<SequenceEditorPageHeader />}
|
|
17
|
+
isNoInteraction={isNoInteraction}
|
|
18
|
+
>
|
|
19
|
+
{children}
|
|
20
|
+
</PageCommon>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './SequenceEditorPage';
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useState,
|
|
6
|
+
} from 'react';
|
|
7
|
+
import {
|
|
8
|
+
Accordion,
|
|
9
|
+
AccordionDetails,
|
|
10
|
+
AccordionSummary,
|
|
11
|
+
Box,
|
|
12
|
+
Typography,
|
|
13
|
+
} from '@mui/material';
|
|
14
|
+
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
15
|
+
import TuneOutlinedIcon from '@mui/icons-material/TuneOutlined';
|
|
16
|
+
import PaletteOutlinedIcon from '@mui/icons-material/PaletteOutlined';
|
|
17
|
+
import InvertColorsIcon from '@mui/icons-material/InvertColors';
|
|
18
|
+
import KeyboardOutlinedIcon from '@mui/icons-material/KeyboardOutlined';
|
|
19
|
+
import { useStore } from 'zustand';
|
|
20
|
+
import { PageCommonDrawer } from '@rivm-loculus-tools/common-frontend/components/page';
|
|
21
|
+
|
|
22
|
+
import { sequenceEditorStore } from '../../../stores/sequenceEditorStore';
|
|
23
|
+
import type {
|
|
24
|
+
AminoAcidPalette,
|
|
25
|
+
NucleotidePalette,
|
|
26
|
+
} from '../../../models';
|
|
27
|
+
import {
|
|
28
|
+
ALI_VIEW_CLUSTAL_X_AMINO_ACID_PALETTE,
|
|
29
|
+
ALI_VIEW_DEFAULT_AMINO_ACID_PALETTE,
|
|
30
|
+
ALI_VIEW_DEFAULT_NUCLEOTIDE_PALETTE,
|
|
31
|
+
ALI_VIEW_FAST_NUCLEOTIDE_PALETTE,
|
|
32
|
+
ALI_VIEW_SEA_VIEW_AMINO_ACID_PALETTE,
|
|
33
|
+
ALI_VIEW_SEA_VIEW_NUCLEOTIDE_PALETTE,
|
|
34
|
+
} from '../../../constants';
|
|
35
|
+
|
|
36
|
+
import { SequenceEditorPageDrawerColorForm } from './SequenceEditorPageDrawerColorForm';
|
|
37
|
+
import { SequenceEditorPageDrawerKeyboardShortcuts } from './SequenceEditorPageDrawerKeyboardShortcuts';
|
|
38
|
+
|
|
39
|
+
enum ACCORDIONS {
|
|
40
|
+
AMINO_ACID_COLORS = 'AMINO_ACID_COLORS',
|
|
41
|
+
KEYBOARD_SHORTCUTS = 'KEYBOARD_SHORTCUTS',
|
|
42
|
+
METADATA = 'METADATA',
|
|
43
|
+
NUCLEOTIDE_COLORS = 'NUCLEOTIDE_COLORS',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const SequenceEditorPageDrawer = () => {
|
|
47
|
+
const parsedMetadata = useStore(sequenceEditorStore, (state) => state.parsedMetadata);
|
|
48
|
+
const aminoAcidPalette = useStore(sequenceEditorStore, (state) => state.aminoAcidPalette);
|
|
49
|
+
const nucleotidePalette = useStore(sequenceEditorStore, (state) => state.nucleotidePalette);
|
|
50
|
+
const setAminoAcidPalette = useStore(sequenceEditorStore, (state) => state.setAminoAcidPalette);
|
|
51
|
+
const setNucleotidePalette = useStore(sequenceEditorStore, (state) => state.setNucleotidePalette);
|
|
52
|
+
const meta = useStore(sequenceEditorStore, (state) => state.meta);
|
|
53
|
+
const [expandedAccordions, setExpandedAccordions] = useState<ACCORDIONS[]>([]);
|
|
54
|
+
|
|
55
|
+
const toggleAccordion = useCallback((panel: ACCORDIONS) => {
|
|
56
|
+
setExpandedAccordions((prev) =>
|
|
57
|
+
prev.includes(panel) ? prev.filter((p) => p !== panel) : [...prev, panel]);
|
|
58
|
+
}, []);
|
|
59
|
+
|
|
60
|
+
const collapseAccordion = useCallback((panel: ACCORDIONS) => {
|
|
61
|
+
setExpandedAccordions((prev) => prev.filter((p) => p !== panel));
|
|
62
|
+
}, []);
|
|
63
|
+
|
|
64
|
+
const onColorsAccordionChange = useCallback(() => toggleAccordion(ACCORDIONS.NUCLEOTIDE_COLORS), [toggleAccordion]);
|
|
65
|
+
const onAminoAcidColorsAccordionChange = useCallback(() => toggleAccordion(ACCORDIONS.AMINO_ACID_COLORS), [toggleAccordion]);
|
|
66
|
+
const onMetaDataAccordionChange = useCallback(() => toggleAccordion(ACCORDIONS.METADATA), [toggleAccordion]);
|
|
67
|
+
const onKeyboardShortcutsAccordionChange = useCallback(() => toggleAccordion(ACCORDIONS.KEYBOARD_SHORTCUTS), [toggleAccordion]);
|
|
68
|
+
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (!parsedMetadata) {
|
|
71
|
+
collapseAccordion(ACCORDIONS.METADATA);
|
|
72
|
+
}
|
|
73
|
+
}, [collapseAccordion, parsedMetadata]);
|
|
74
|
+
|
|
75
|
+
const onNucleotidePaletteChange = useCallback((palette: NucleotidePalette) => {
|
|
76
|
+
setNucleotidePalette(palette);
|
|
77
|
+
}, [setNucleotidePalette]);
|
|
78
|
+
|
|
79
|
+
const onAminoAcidPaletteChange = useCallback((palette: AminoAcidPalette) => {
|
|
80
|
+
setAminoAcidPalette(palette);
|
|
81
|
+
}, [setAminoAcidPalette]);
|
|
82
|
+
|
|
83
|
+
const nucleotidePalettes = useMemo(() => {
|
|
84
|
+
return [
|
|
85
|
+
ALI_VIEW_DEFAULT_NUCLEOTIDE_PALETTE,
|
|
86
|
+
ALI_VIEW_FAST_NUCLEOTIDE_PALETTE,
|
|
87
|
+
ALI_VIEW_SEA_VIEW_NUCLEOTIDE_PALETTE,
|
|
88
|
+
];
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
const aminoAcidPalettes = useMemo(() => {
|
|
92
|
+
return [
|
|
93
|
+
ALI_VIEW_DEFAULT_AMINO_ACID_PALETTE,
|
|
94
|
+
ALI_VIEW_SEA_VIEW_AMINO_ACID_PALETTE,
|
|
95
|
+
ALI_VIEW_CLUSTAL_X_AMINO_ACID_PALETTE,
|
|
96
|
+
];
|
|
97
|
+
}, []);
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<PageCommonDrawer>
|
|
102
|
+
{/* Header with Close and Data Load trigger */}
|
|
103
|
+
<Box sx={{ borderBottom: '1px solid', borderColor: 'divider', display: 'flex', flexDirection: 'column', gap: 1.5, p: 2 }}>
|
|
104
|
+
{meta && (
|
|
105
|
+
<>
|
|
106
|
+
<Typography
|
|
107
|
+
sx={{ fontWeight: 600 }}
|
|
108
|
+
variant={'body2'}
|
|
109
|
+
>
|
|
110
|
+
{'Alignment dimensions'}
|
|
111
|
+
</Typography>
|
|
112
|
+
<Typography
|
|
113
|
+
sx={{ fontWeight: 400 }}
|
|
114
|
+
variant={'body2'}
|
|
115
|
+
>
|
|
116
|
+
{`${meta.sequenceCount} sequences x ${meta.alignmentWidth} bases`}
|
|
117
|
+
</Typography>
|
|
118
|
+
</>
|
|
119
|
+
)}
|
|
120
|
+
</Box>
|
|
121
|
+
<Box sx={{ pb: 3 }}>
|
|
122
|
+
<Accordion
|
|
123
|
+
disableGutters
|
|
124
|
+
elevation={0}
|
|
125
|
+
expanded={expandedAccordions.includes(ACCORDIONS.KEYBOARD_SHORTCUTS)}
|
|
126
|
+
onChange={onKeyboardShortcutsAccordionChange}
|
|
127
|
+
sx={{ borderBottom: '1px solid', borderColor: 'divider' }}
|
|
128
|
+
>
|
|
129
|
+
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
|
130
|
+
<Box sx={{ alignItems: 'center', display: 'flex', gap: 1 }}>
|
|
131
|
+
<KeyboardOutlinedIcon
|
|
132
|
+
color={'primary'}
|
|
133
|
+
fontSize={'small'}
|
|
134
|
+
/>
|
|
135
|
+
<Typography
|
|
136
|
+
sx={{ fontWeight: 600 }}
|
|
137
|
+
variant={'body2'}
|
|
138
|
+
>
|
|
139
|
+
{'Keyboard shortcuts'}
|
|
140
|
+
</Typography>
|
|
141
|
+
</Box>
|
|
142
|
+
</AccordionSummary>
|
|
143
|
+
<AccordionDetails sx={{ p: 0 }}>
|
|
144
|
+
<SequenceEditorPageDrawerKeyboardShortcuts />
|
|
145
|
+
</AccordionDetails>
|
|
146
|
+
</Accordion>
|
|
147
|
+
<Accordion
|
|
148
|
+
disableGutters
|
|
149
|
+
elevation={0}
|
|
150
|
+
expanded={expandedAccordions.includes(ACCORDIONS.NUCLEOTIDE_COLORS)}
|
|
151
|
+
onChange={onColorsAccordionChange}
|
|
152
|
+
sx={{ borderBottom: '1px solid', borderColor: 'divider' }}
|
|
153
|
+
>
|
|
154
|
+
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
|
155
|
+
<Box sx={{ alignItems: 'center', display: 'flex', gap: 1 }}>
|
|
156
|
+
<PaletteOutlinedIcon
|
|
157
|
+
color={'primary'}
|
|
158
|
+
fontSize={'small'}
|
|
159
|
+
/>
|
|
160
|
+
<Typography
|
|
161
|
+
sx={{ fontWeight: 600 }}
|
|
162
|
+
variant={'body2'}
|
|
163
|
+
>
|
|
164
|
+
{'Nucleotide Colors'}
|
|
165
|
+
</Typography>
|
|
166
|
+
</Box>
|
|
167
|
+
</AccordionSummary>
|
|
168
|
+
<AccordionDetails sx={{ pb: 2, pt: 0, px: 2 }}>
|
|
169
|
+
<SequenceEditorPageDrawerColorForm
|
|
170
|
+
currentPalette={nucleotidePalette}
|
|
171
|
+
onPaletteChange={onNucleotidePaletteChange}
|
|
172
|
+
palettes={nucleotidePalettes}
|
|
173
|
+
/>
|
|
174
|
+
</AccordionDetails>
|
|
175
|
+
</Accordion>
|
|
176
|
+
<Accordion
|
|
177
|
+
disableGutters
|
|
178
|
+
elevation={0}
|
|
179
|
+
expanded={expandedAccordions.includes(ACCORDIONS.AMINO_ACID_COLORS)}
|
|
180
|
+
onChange={onAminoAcidColorsAccordionChange}
|
|
181
|
+
sx={{ borderBottom: '1px solid', borderColor: 'divider' }}
|
|
182
|
+
>
|
|
183
|
+
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
|
184
|
+
<Box sx={{ alignItems: 'center', display: 'flex', gap: 1 }}>
|
|
185
|
+
<InvertColorsIcon
|
|
186
|
+
color={'primary'}
|
|
187
|
+
fontSize={'small'}
|
|
188
|
+
/>
|
|
189
|
+
<Typography
|
|
190
|
+
sx={{ fontWeight: 600 }}
|
|
191
|
+
variant={'body2'}
|
|
192
|
+
>
|
|
193
|
+
{'Amino-acid colors'}
|
|
194
|
+
</Typography>
|
|
195
|
+
</Box>
|
|
196
|
+
</AccordionSummary>
|
|
197
|
+
<AccordionDetails sx={{ pb: 2, pt: 0, px: 2 }}>
|
|
198
|
+
<SequenceEditorPageDrawerColorForm
|
|
199
|
+
currentPalette={aminoAcidPalette}
|
|
200
|
+
onPaletteChange={onAminoAcidPaletteChange}
|
|
201
|
+
palettes={aminoAcidPalettes}
|
|
202
|
+
/>
|
|
203
|
+
</AccordionDetails>
|
|
204
|
+
</Accordion>
|
|
205
|
+
<Accordion
|
|
206
|
+
disabled={!parsedMetadata}
|
|
207
|
+
disableGutters
|
|
208
|
+
elevation={0}
|
|
209
|
+
expanded={expandedAccordions.includes(ACCORDIONS.METADATA)}
|
|
210
|
+
onChange={onMetaDataAccordionChange}
|
|
211
|
+
sx={{ borderBottom: '1px solid', borderColor: 'divider' }}
|
|
212
|
+
>
|
|
213
|
+
<AccordionSummary expandIcon={<ExpandMoreIcon />}>
|
|
214
|
+
<Box sx={{ alignItems: 'center', display: 'flex', gap: 1 }}>
|
|
215
|
+
<TuneOutlinedIcon
|
|
216
|
+
color={'primary'}
|
|
217
|
+
fontSize={'small'}
|
|
218
|
+
/>
|
|
219
|
+
<Typography
|
|
220
|
+
sx={{ fontWeight: 600 }}
|
|
221
|
+
variant={'body2'}
|
|
222
|
+
>
|
|
223
|
+
{'Metadata'}
|
|
224
|
+
</Typography>
|
|
225
|
+
</Box>
|
|
226
|
+
</AccordionSummary>
|
|
227
|
+
<AccordionDetails sx={{ pb: 2, pt: 0, px: 2 }}>
|
|
228
|
+
{'Metadata'}
|
|
229
|
+
</AccordionDetails>
|
|
230
|
+
</Accordion>
|
|
231
|
+
</Box>
|
|
232
|
+
</PageCommonDrawer>
|
|
233
|
+
);
|
|
234
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useId,
|
|
4
|
+
useMemo,
|
|
5
|
+
} from 'react';
|
|
6
|
+
import { useForm } from 'react-hook-form';
|
|
7
|
+
import { GenericForm } from '@gen-epix/ui-core-form/components/helpers/GenericForm';
|
|
8
|
+
import type { FormFieldDefinition } from '@gen-epix/ui-core-form/models/form';
|
|
9
|
+
import { FORM_FIELD_DEFINITION_TYPE } from '@gen-epix/ui-core-form/models/form';
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
AminoAcidPalette,
|
|
13
|
+
NucleotidePalette,
|
|
14
|
+
} from '../../../models';
|
|
15
|
+
|
|
16
|
+
export type SequenceEditorPageDrawerColorFormProps<TPalette extends AminoAcidPalette | NucleotidePalette> = {
|
|
17
|
+
currentPalette: TPalette;
|
|
18
|
+
onPaletteChange: (palettes: TPalette) => void;
|
|
19
|
+
palettes: Array<TPalette>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
type FormFields = {
|
|
23
|
+
palette?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const SequenceEditorPageDrawerColorForm = <TPalette extends AminoAcidPalette | NucleotidePalette, >({ currentPalette, onPaletteChange, palettes }: SequenceEditorPageDrawerColorFormProps<TPalette>) => {
|
|
27
|
+
const formId = useId();
|
|
28
|
+
|
|
29
|
+
const onChangePalette = useCallback((paletteName: string) => {
|
|
30
|
+
const palette = palettes.find((candidate) => candidate.name === paletteName);
|
|
31
|
+
if (palette) {
|
|
32
|
+
onPaletteChange(palette);
|
|
33
|
+
}
|
|
34
|
+
}, [onPaletteChange, palettes]);
|
|
35
|
+
|
|
36
|
+
const paletteOptions = useMemo(() => palettes.map((palette) => ({
|
|
37
|
+
label: palette.name,
|
|
38
|
+
value: palette.name,
|
|
39
|
+
})), [palettes]);
|
|
40
|
+
|
|
41
|
+
const formFieldDefinitions = useMemo<FormFieldDefinition<FormFields>[]>(() => [
|
|
42
|
+
{
|
|
43
|
+
definition: FORM_FIELD_DEFINITION_TYPE.RADIO_GROUP,
|
|
44
|
+
label: 'Color palette',
|
|
45
|
+
name: 'palette',
|
|
46
|
+
onChange: onChangePalette,
|
|
47
|
+
options: paletteOptions,
|
|
48
|
+
required: true,
|
|
49
|
+
} as const satisfies FormFieldDefinition<FormFields>,
|
|
50
|
+
] as const, [onChangePalette, paletteOptions]);
|
|
51
|
+
|
|
52
|
+
const values = useMemo<FormFields>(() => ({
|
|
53
|
+
palette: currentPalette.name,
|
|
54
|
+
}), [currentPalette.name]);
|
|
55
|
+
|
|
56
|
+
const formMethods = useForm<FormFields>({
|
|
57
|
+
values,
|
|
58
|
+
});
|
|
59
|
+
const { handleSubmit } = formMethods;
|
|
60
|
+
|
|
61
|
+
const onFormSubmit = useCallback((_formValues: FormFields) => {
|
|
62
|
+
// do nothing
|
|
63
|
+
}, []);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<GenericForm<FormFields>
|
|
67
|
+
formFieldDefinitions={formFieldDefinitions}
|
|
68
|
+
formId={formId}
|
|
69
|
+
formMethods={formMethods}
|
|
70
|
+
onSubmit={handleSubmit(onFormSubmit)}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
};
|