Skip to content

Commit

Permalink
breaking: Added export progress indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkoelle committed May 19, 2021
1 parent 6a4d4c4 commit 51b792f
Show file tree
Hide file tree
Showing 16 changed files with 1,044 additions and 480 deletions.
165 changes: 24 additions & 141 deletions app/components/ConditionalCommentPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,90 +1,30 @@
/* eslint-disable react/jsx-curly-newline */
/* eslint-disable @typescript-eslint/no-empty-interface */
/* eslint-disable react/jsx-props-no-spreading */
import React, { useState } from 'react';
import { Theme, withStyles } from '@material-ui/core/styles';
import Typography from '@material-ui/core/Typography';
import { Collapse, Grid, Switch } from '@material-ui/core';
import { useDispatch, useSelector } from 'react-redux';
import {
Collapse,
Grid,
Paper,
Slider,
Switch,
TextField,
Tooltip,
} from '@material-ui/core';
selectSettingsExport,
settingsSetExport,
} from '../model/SettingsSlice';
import ConditionalCommentSettings from './ConditionalCommentSettings';

const PrimaryTooltip = withStyles((theme: Theme) => ({
tooltip: {
backgroundColor: theme.palette.primary.main,
color: theme.palette.background.default,
boxShadow: theme.shadows[1],
fontSize: 11,
},
}))(Tooltip);

function ValueLabelComponent(props: any) {
const { children, open, value, comments } = props;
return (
<PrimaryTooltip
open={open}
hidden={!open}
placement="top"
title={`${comments[children.props['data-index']]}${value}`}
arrow
>
{children}
</PrimaryTooltip>
const ConditionalCommentPanel = () => {
const dispatch = useDispatch();
const settings = useSelector(selectSettingsExport);
const [showLabel, setShowLabel] = useState(
settings.conditionalCommentEnabled
);
}

export interface ConditionalCommentProps {
conditionalComment;
setConditionalComment;
showLabel;
setShowLabel;
value;
setValue;
comments;
setComments;
}

const ConditionalCommentPanel = (props: ConditionalCommentProps) => {
const {
conditionalComment,
setConditionalComment,
showLabel,
setShowLabel,
value,
setValue,
comments,
setComments,
} = props;

const marks = [
{
value: 0,
label: '0%',
},
{
value: 25,
label: '25%',
},
{
value: 50,
label: '50%',
},
{
value: 75,
label: '75%',
},
{
value: 100,
label: '100%',
},
];

function onToggleConditionalComment() {
setConditionalComment(!conditionalComment);
dispatch(
settingsSetExport({
...settings,
conditionalCommentEnabled: !settings.conditionalCommentEnabled,
})
);
// Workaround for using tooltips
if (showLabel) {
setShowLabel(false);
Expand All @@ -95,16 +35,6 @@ const ConditionalCommentPanel = (props: ConditionalCommentProps) => {
}
}

function onChangeSlider(event, newValue) {
setValue(newValue);
}

function onChangeComment(event) {
const temp = [...comments];
temp[event.target.name] = event.target.value;
setComments(temp);
}

return (
<Grid container direction="row" justify="flex-start" alignItems="center">
<Grid
Expand All @@ -119,63 +49,16 @@ const ConditionalCommentPanel = (props: ConditionalCommentProps) => {
</Grid>
<Grid item>
<Switch
checked={conditionalComment}
checked={settings.conditionalCommentEnabled}
onChange={onToggleConditionalComment}
/>
</Grid>
</Grid>
<Collapse in={conditionalComment} style={{ width: '100%' }}>
<Grid container justify="center" alignItems="center">
<Grid item xs={12}>
<Paper
variant="outlined"
style={{
padding: '50px 50px 10px',
marginTop: '16px',
marginBottom: '16px',
width: 'calc(100%)',
}}
>
<Slider
value={value}
valueLabelDisplay="on"
marks={marks}
onChange={onChangeSlider}
ValueLabelComponent={(p) => (
<ValueLabelComponent
{...p}
comments={comments}
open={showLabel}
/>
)}
/>
</Paper>
</Grid>
</Grid>
<Grid container justify="flex-start" alignItems="center">
<Grid item xs={12}>
<Typography>Options:</Typography>
</Grid>
{comments.map((c, i) => (
// eslint-disable-next-line react/no-array-index-key
<Grid key={`comment-${i}`} item>
<TextField
id={`comment-${i}`}
label={`Score ≥ ${value[i]}%`}
name={i.toString()}
defaultValue={c}
variant="outlined"
size="small"
onChange={onChangeComment}
style={{
width: '120px',
marginRight: '16px',
marginTop: '16px',
}}
/>
</Grid>
))}
</Grid>
<Collapse
in={settings.conditionalCommentEnabled}
style={{ width: '100%' }}
>
<ConditionalCommentSettings showLabel={showLabel} />
</Collapse>
</Grid>
);
Expand Down
130 changes: 130 additions & 0 deletions app/components/ConditionalCommentSettings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
/* eslint-disable react/jsx-curly-newline */
/* eslint-disable @typescript-eslint/no-empty-interface */
/* eslint-disable react/jsx-props-no-spreading */
import React from 'react';
import { Theme, withStyles } from '@material-ui/core/styles';
import AddCircleIcon from '@material-ui/icons/AddCircle';
import Typography from '@material-ui/core/Typography';
import {
Fade,
Grid,
IconButton,
Paper,
Slider,
Tooltip,
} from '@material-ui/core';
import { useDispatch, useSelector } from 'react-redux';
import ConditionalCommentTextInput from './ConditionalCommentTextInput';
import {
selectSettingsExport,
settingsAddConditionalComment,
settingsUpdateConditionalCommentValue,
} from '../model/SettingsSlice';

const PrimaryTooltip = withStyles((theme: Theme) => ({
tooltip: {
backgroundColor: theme.palette.primary.main,
color: theme.palette.background.default,
boxShadow: theme.shadows[1],
fontSize: 11,
},
}))(Tooltip);

function ValueLabelComponent(props: any) {
const { children, open, value, comments } = props;
return (
<PrimaryTooltip
open={open}
hidden={!open}
TransitionComponent={Fade}
TransitionProps={{ timeout: 0 }}
placement="top"
title={`${comments[children.props['data-index']]}${Math.round(
value
)}%`}
arrow
>
{children}
</PrimaryTooltip>
);
}

const ConditionalCommentSettings = (props: { showLabel: boolean }) => {
const { showLabel } = props;
const dispatch = useDispatch();
const settings = useSelector(selectSettingsExport);

return (
<>
<Grid container direction="column" justify="center" alignItems="center">
<Grid item style={{ width: '100%' }}>
<Paper
variant="outlined"
style={{
padding: '50px 50px 10px',
marginTop: '16px',
marginBottom: '16px',
width: 'calc(100%)',
}}
>
<Slider
value={settings.conditionalComments.map((c) =>
Math.round(c.minPercentage * 100)
)}
valueLabelDisplay={showLabel ? 'on' : 'off'}
track={false}
marks={[...Array(5).keys()]
.map((i, _ind, arr) => i * (100 / (arr.length - 1)))
.map((v) => {
return { value: Math.round(v), label: `${Math.round(v)}%` };
})}
onChange={(_event, values) =>
dispatch(
settingsUpdateConditionalCommentValue(
(values as number[]).map((v) => v / 100.0)
)
)
}
ValueLabelComponent={(p) => (
<ValueLabelComponent
{...p}
comments={settings.conditionalComments.map((c) => c.text)}
/>
)}
/>
</Paper>
</Grid>
<Grid item justify="flex-start" style={{ width: '100%' }}>
<Typography>Options:</Typography>
</Grid>
<Grid container item justify="flex-start" wrap="nowrap">
{settings.conditionalComments.map((c, i) => (
// eslint-disable-next-line react/no-array-index-key
<Grid key={`comment-${i}`} item>
<ConditionalCommentTextInput c={c} i={i} />
</Grid>
))}
{settings.conditionalComments.length < 4 && (
<Grid item style={{ marginTop: '19px' }}>
<IconButton
onClick={() =>
dispatch(
settingsAddConditionalComment({
text: '',
minPercentage: 1,
})
)
}
style={{ padding: '0px' }}
>
<AddCircleIcon fontSize="large" />
</IconButton>
</Grid>
)}
</Grid>
</Grid>
</>
);
};

export default ConditionalCommentSettings;
70 changes: 70 additions & 0 deletions app/components/ConditionalCommentTextInput.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* eslint-disable react/jsx-curly-newline */
/* eslint-disable react/prop-types */
import { IconButton, TextField } from '@material-ui/core';
import CancelIcon from '@material-ui/icons/Cancel';
import React, { useState } from 'react';
import { useDispatch } from 'react-redux';
import ConditionalComment from '../model/ConditionalComment';
import {
settingsRemoveConditionalComment,
settingsUpdateConditionalCommentText,
} from '../model/SettingsSlice';

interface ConditionalCommentTextInputProps {
c: ConditionalComment;
i: number;
}

const ConditionalCommentTextInput = (
props: ConditionalCommentTextInputProps
) => {
const { c, i } = props;
const dispatch = useDispatch();
const [hoverDeleteButton, setHoverDeleteButton] = useState(false);
return (
<>
<TextField
id={`comment-${i}`}
label={`Score ≥ ${Math.round(c.minPercentage * 100)}%`}
name={i.toString()}
defaultValue={c.text}
variant="outlined"
size="small"
inputProps={{ maxLength: 15 }}
onChange={(event) =>
dispatch(
settingsUpdateConditionalCommentText({
index: i,
text: event.target.value,
})
)
}
style={{
width: '110px',
marginRight: '-6px',
marginTop: '16px',
}}
onMouseEnter={() => setHoverDeleteButton(true)}
onMouseOver={() => setHoverDeleteButton(true)}
onMouseLeave={() => setHoverDeleteButton(false)}
/>
<IconButton
onClick={() => dispatch(settingsRemoveConditionalComment(i))}
onMouseEnter={() => setHoverDeleteButton(true)}
onMouseOver={() => setHoverDeleteButton(true)}
onMouseLeave={() => setHoverDeleteButton(false)}
style={{
padding: '0px',
position: 'relative',
top: '5px',
right: '7px',
opacity: hoverDeleteButton ? 1 : 0,
transition: 'opacity 150ms ease-out',
}}
>
<CancelIcon />
</IconButton>
</>
);
};
export default ConditionalCommentTextInput;
Loading

0 comments on commit 51b792f

Please sign in to comment.