Skip to content
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

fix: help menu shortcuts #2740

Merged
merged 2 commits into from
Dec 2, 2024
Merged
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
8 changes: 8 additions & 0 deletions webapp/src/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@ const getTheme = (mode: PaletteMode) => {
},
},
},
MuiMenu: {
styleOverrides: {
list: {
paddingTop: 8,
paddingBottom: 8,
},
},
},
MuiLink: {
styleOverrides: {
root: {
Expand Down
35 changes: 35 additions & 0 deletions webapp/src/component/HelpMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ import {
DialogContent,
DialogActions,
Button,
Divider,
Typography,
} from '@mui/material';
import {
BookOpen01,
MessageSquare01,
Mail01,
HelpCircle,
Keyboard02,
} from '@untitled-ui/icons-react';
import { T, useTranslate } from '@tolgee/react';

Expand All @@ -29,6 +32,7 @@ import {
useUser,
} from 'tg.globalContext/helpers';
import { GitHub, Slack } from './CustomIcons';
import { TranslationsShortcuts } from './shortcuts/TranslationsShortcuts';

const BASE_URL = 'https://app.chatwoot.com';
let scriptPromise: Promise<void> | null = null;
Expand Down Expand Up @@ -91,12 +95,18 @@ export const HelpMenu = () => {
};

const [dialogOpen, setDialogOpen] = useState(false);
const [shortcutsOpen, setShortcutsOpen] = useState(false);

function handleOpenDialog() {
setDialogOpen(true);
handleClose();
}

function handleOpenShortcuts() {
setShortcutsOpen(true);
handleClose();
}

const darkMode = mode === 'dark';

useEffect(() => {
Expand Down Expand Up @@ -219,6 +229,14 @@ export const HelpMenu = () => {
</ListItemIcon>
<ListItemText primary={t('help_menu_email')} />
</MenuItem>
<Divider />

<MenuItem onClick={handleOpenShortcuts}>
<ListItemIcon>
<Keyboard02 />
</ListItemIcon>
<ListItemText primary={t('help_menu_shortcuts')} />
</MenuItem>
</Menu>

<Dialog open={dialogOpen}>
Expand All @@ -235,6 +253,23 @@ export const HelpMenu = () => {
</Button>
</DialogActions>
</Dialog>

<Dialog open={shortcutsOpen} onClose={() => setShortcutsOpen(false)}>
<DialogTitle>{t('help_menu_shortcuts_dialog_title')}</DialogTitle>
<DialogContent sx={{ width: '85vw', maxWidth: '400px' }}>
<Typography
sx={{ fontWeight: 'bold', paddingBottom: 1, fontSize: 14 }}
>
<T keyName="help_menu_shortcuts_dialog_translations_view" />
</Typography>
<TranslationsShortcuts />
</DialogContent>
<DialogActions>
<Button onClick={() => setShortcutsOpen(false)}>
{t('global_close_button')}
</Button>
</DialogActions>
</Dialog>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const Shortcut = ({ name, formula }: Props) => {
>
{name}
</StyledItemContent>
<StyledItemContent sx={{ whiteSpace: 'nowrap' }}>
<StyledItemContent variant="body2" sx={{ whiteSpace: 'nowrap' }}>
{formula}
</StyledItemContent>
</StyledItem>
Expand Down
101 changes: 101 additions & 0 deletions webapp/src/component/shortcuts/TranslationsShortcuts.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Box, Typography, styled } from '@mui/material';
import { T } from '@tolgee/react';
import { IS_MAC, getMetaName } from 'tg.fixtures/isMac';
import { formatShortcut } from 'tg.fixtures/shortcuts';
import { Shortcut } from './Shortcut';

const StyledContainer = styled(Box)`
height: 100%;
padding: 16px 12px 8px 12px;
display: grid;
position: relative;
background: ${({ theme }) => theme.palette.cell.hover};
border-radius: 16px;
`;

const StyledItems = styled(Box)`
display: grid;
gap: 8px;
padding-top: 8px;
padding-bottom: 24px;
`;

export const TranslationsShortcuts = () => {
const listShorttcuts = [
{
name: <T keyName="translations_shortcuts_move" />,
formula: ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].map((i) =>
formatShortcut(i)
),
},
{
name: <T keyName="translations_cell_edit" />,
formula: formatShortcut('Enter'),
},
];

const batchShortcuts = [
{
name: <T keyName="translations_shortcut_shift_checkbox" />,
formula: (
<Box display="flex" alignItems="center">
{formatShortcut('Shift')}
<Box px="2px">+</Box>
<T keyName="translations_shortcut_click" />
</Box>
),
},
];

const editorShortcuts = [
{
name: <T keyName="translations_cell_save" />,
formula: formatShortcut('Enter'),
},
{
name: <T keyName="translations_cell_save_and_continue" />,
formula: formatShortcut(`${getMetaName()} + Enter`),
},
{
name: <T keyName="translations_cell_change_state" />,
formula: formatShortcut(`${getMetaName()} + E`),
},
{
name: <T keyName="translations_cell_insert_base" />,
formula: IS_MAC
? formatShortcut(`${getMetaName()} + Shift + S`)
: formatShortcut(`${getMetaName()} + Insert`),
},
];

return (
<StyledContainer>
<Typography variant="subtitle2">
<T keyName="translations_shortcuts_in_list_title" />
</Typography>
<StyledItems>
{listShorttcuts.map((item, i) => {
return <Shortcut key={i} {...item} />;
})}
</StyledItems>

<Typography variant="subtitle2">
<T keyName="translations_shortcuts_in_editor_title" />
</Typography>
<StyledItems>
{editorShortcuts.map((item, i) => {
return <Shortcut key={i} {...item} />;
})}
</StyledItems>

<Typography variant="subtitle2">
<T keyName="translations_shortcuts_batch_title" />
</Typography>
<StyledItems>
{batchShortcuts.map((item, i) => {
return <Shortcut key={i} {...item} />;
})}
</StyledItems>
</StyledContainer>
);
};
Original file line number Diff line number Diff line change
@@ -1,81 +1,16 @@
import { Box, Typography, styled } from '@mui/material';
import { T } from '@tolgee/react';
import { IS_MAC, getMetaName } from 'tg.fixtures/isMac';
import { formatShortcut } from 'tg.fixtures/shortcuts';
import { Shortcut } from './Shortcut';
import { Box, styled } from '@mui/material';
import { TranslationsShortcuts } from 'tg.component/shortcuts/TranslationsShortcuts';

const StyledContainer = styled(Box)`
height: 100%;
padding: 16px 12px 8px 12px;
margin: 0px 8px;
display: flex;
flex-direction: column;
position: relative;
background: ${({ theme }) => theme.palette.cell.hover};
border-radius: 16px;
`;

const StyledItems = styled(Box)`
display: grid;
gap: 8px;
padding-top: 8px;
padding-bottom: 24px;
`;

export const KeyboardShortcuts = () => {
const listShorttcuts = [
{
name: <T keyName="translations_shortcuts_move" />,
formula: ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].map((i) =>
formatShortcut(i)
),
},
{
name: <T keyName="translations_cell_edit" />,
formula: formatShortcut('Enter'),
},
];

const editorShortcuts = [
{
name: <T keyName="translations_cell_save" />,
formula: formatShortcut('Enter'),
},
{
name: <T keyName="translations_cell_save_and_continue" />,
formula: formatShortcut(`${getMetaName()} + Enter`),
},
{
name: <T keyName="translations_cell_change_state" />,
formula: formatShortcut(`${getMetaName()} + E`),
},
{
name: <T keyName="translations_cell_insert_base" />,
formula: IS_MAC
? formatShortcut(`${getMetaName()} + Shift + S`)
: formatShortcut(`${getMetaName()} + Insert`),
},
];

return (
<StyledContainer>
<Typography variant="subtitle2">
<T keyName="translations_shortcuts_in_list_title" />
</Typography>
<StyledItems>
{listShorttcuts.map((item, i) => {
return <Shortcut key={i} {...item} />;
})}
</StyledItems>

<Typography variant="subtitle2">
<T keyName="translations_shortcuts_in_editor_title" />
</Typography>
<StyledItems>
{editorShortcuts.map((item, i) => {
return <Shortcut key={i} {...item} />;
})}
</StyledItems>
<TranslationsShortcuts />
</StyledContainer>
);
};
Loading