Skip to content

Commit

Permalink
frontend: Add cron variables UI
Browse files Browse the repository at this point in the history
  • Loading branch information
pschlan committed Aug 3, 2024
1 parent 161b87c commit 73b990d
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 3 deletions.
11 changes: 11 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"clsx": "^1.1.1",
"i18next": "^19.4.5",
"i18next-browser-languagedetector": "^6.0.1",
"insert-text-at-cursor": "^0.3.0",
"moment": "^2.29.4",
"moment-timezone": "^0.5.35",
"notistack": "^0.9.17",
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/components/jobs/JobEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import useUserProfile from '../../hooks/useUserProfile';
import JobTestRun from './JobTestRun';
import JobExport from './JobExport';
import useFolder from '../../hooks/useFolder';
import VariableMenu from '../misc/VariableMenu';

const useStyles = makeStyles((theme) => ({
paper: {
Expand Down Expand Up @@ -346,6 +347,10 @@ export default function JobEditor({ match }) {
size='small'
defaultValue={item.value}
onBlur={({target}) => updateHeaderValue(rowNo, target.value)}
InputProps={{ endAdornment: <InputAdornment position='end'>
<VariableMenu />
</InputAdornment>
}}
fullWidth />
},
{
Expand Down Expand Up @@ -435,6 +440,10 @@ export default function JobEditor({ match }) {
onBlur={({target}) => setJobURL(target.value.trim())}
inputRef={jobURLRef}
InputLabelProps={{shrink: true}}
InputProps={{ endAdornment: <InputAdornment position='end'>
<VariableMenu />
</InputAdornment>
}}
fullWidth
required
/>
Expand Down
65 changes: 65 additions & 0 deletions frontend/src/components/misc/VariableMenu.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React, { useRef } from 'react';

import ActionMenu from './ActionMenu';
import { IconButton } from '@material-ui/core';
import insertTextAtCursor from 'insert-text-at-cursor';
import { useTranslation } from 'react-i18next';

import { Config } from '../../utils/Config';

import VariableIcon from '@material-ui/icons/Code';
import HelpIcon from '@material-ui/icons/HelpOutline';

function getTextField(elem) {
while (elem) {
elem = elem.parentNode;
if (!elem) {
break;
}
const textField = elem.querySelector('input[type=text]');
if (textField) {
return textField;
}
}
return undefined;
}

export default function VariableMenu() {
const { t } = useTranslation();
const buttonRef = useRef();

const insertVariable = text => {
const textField = getTextField(buttonRef.current);
if (textField != null) {
insertTextAtCursor(textField, text);
window.setTimeout(() => textField.focus(), 100);
}
};

return <ActionMenu
variant='contained'
size='small'
component={<IconButton />}
buttonRef={buttonRef}
items={[
{
icon: <VariableIcon />,
text: '%cjo:unixtime%'
},
{
icon: <VariableIcon />,
text: '%cjo:uuid4%'
},
{
divider: true
},
{
icon: <HelpIcon />,
text: t('common.help'),
onClick: () => window.open(Config.variablesDocsURL)
}
]}
onClickItem={item => item.onClick ? item.onClick() : insertVariable(item.text)}
text={<VariableIcon />}
/>;
}
1 change: 1 addition & 0 deletions frontend/src/locales/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"paddleLocale": "de",
"landingLocale": "de",
"common": {
"help": "Hilfe",
"menu": "Menü",
"contact": "Kontakt",
"followontwitter": "Twitter",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"paddleLocale": "en",
"landingLocale": "en",
"common": {
"help": "Help",
"menu": "Menu",
"contact": "Contact",
"followontwitter": "Twitter",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/fr/translation.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"paddleLocale": "fr",
"common": {
"help": "Aide",
"menu": "Menu",
"followontwitter": "Twitter",
"forkongithub": "GitHub",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/it/translation.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"paddleLocale": "it",
"common": {
"help": "Aiuto",
"menu": "Menu",
"contact": "Contatti",
"followontwitter": "Twitter",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/locales/pl/translation.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"paddleLocale": "pl",
"landingLocale": "pl",
"landingLocale": "en",
"common": {
"help": "Pomoc",
"menu": "Menu",
"contact": "Kontakt",
"followontwitter": "Twitter",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/locales/ro/translation.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"paddleLocale": "ro",
"paddleLocale": "en",
"common": {
"help": "Ajutor",
"menu": "Meniu",
"contact": "Contact",
"followontwitter": "Twitter",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/locales/ru/translation.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"paddleLocale": "de",
"paddleLocale": "ru",
"common": {
"help": "Помощь",
"menu": "Меню",
"followontwitter": "Twitter",
"forkongithub": "GitHub",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/locales/zh_TW/translation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"common": {
"help": "幫助",
"menu": "選單",
"contact": "聯繫",
"followontwitter": "Twitter",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/utils/Config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const Config = {
'termsOfServiceURL': 'https://example.com/tos/',
'returnPolicyURL': 'https://example.com/returnpolicy/',
'apiDocsURL': 'https://example.com/docs/rest-api.html',
'variablesDocsURL': 'https://example.com/creating-cron-jobs.html#cron-job-variables',

//! @note The URL of the API webserver (/api/ folder in this repo)
'apiURL': 'https://api.example.com/',
Expand Down

0 comments on commit 73b990d

Please sign in to comment.