From c6b2ace61272535e4dfedb97315a406aee7f729c Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sat, 30 Oct 2021 18:41:18 +0200 Subject: feat(web): show error count on generate button --- language-web/src/main/js/App.tsx | 11 +----- language-web/src/main/js/editor/EditorButtons.tsx | 2 +- language-web/src/main/js/editor/GenerateButton.tsx | 44 ++++++++++++++++++++++ 3 files changed, 47 insertions(+), 10 deletions(-) create mode 100644 language-web/src/main/js/editor/GenerateButton.tsx (limited to 'language-web/src') diff --git a/language-web/src/main/js/App.tsx b/language-web/src/main/js/App.tsx index d25ac4d3..2567aa9c 100644 --- a/language-web/src/main/js/App.tsx +++ b/language-web/src/main/js/App.tsx @@ -1,15 +1,14 @@ import AppBar from '@mui/material/AppBar'; import Box from '@mui/material/Box'; -import Button from '@mui/material/Button'; import IconButton from '@mui/material/IconButton'; import Toolbar from '@mui/material/Toolbar'; import Typography from '@mui/material/Typography'; import MenuIcon from '@mui/icons-material/Menu'; -import PlayArrowIcon from '@mui/icons-material/PlayArrow'; import React from 'react'; import { EditorArea } from './editor/EditorArea'; import { EditorButtons } from './editor/EditorButtons'; +import { GenerateButton } from './editor/GenerateButton'; export const App = (): JSX.Element => ( ( p={1} > - + { editorStore.toggleLintPanel()} - aria-label={`${editorStore.errorCount} errors, ${editorStore.warningCount} warnings, ${editorStore.infoCount} info`} + aria-label="Show diagnostics panel" value="show-lint-panel" > {getLintIcon(editorStore.highestDiagnosticLevel)} diff --git a/language-web/src/main/js/editor/GenerateButton.tsx b/language-web/src/main/js/editor/GenerateButton.tsx new file mode 100644 index 00000000..3834cec4 --- /dev/null +++ b/language-web/src/main/js/editor/GenerateButton.tsx @@ -0,0 +1,44 @@ +import { observer } from 'mobx-react-lite'; +import Button from '@mui/material/Button'; +import PlayArrowIcon from '@mui/icons-material/PlayArrow'; +import React from 'react'; + +import { useRootStore } from '../RootStore'; + +const GENERATE_LABEL = 'Generate'; + +export const GenerateButton = observer(() => { + const { editorStore } = useRootStore(); + const { errorCount, warningCount } = editorStore; + + const diagnostics: string[] = []; + if (errorCount > 0) { + diagnostics.push(`${errorCount} error${errorCount === 1 ? '' : 's'}`); + } + if (warningCount > 0) { + diagnostics.push(`${warningCount} warning${warningCount === 1 ? '' : 's'}`); + } + const summary = diagnostics.join(' and '); + + if (errorCount > 0) { + return ( + + ); + } + + return ( + + ); +}); -- cgit v1.2.3-54-g00ecf