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

Polish metrics page and flow #2461

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0693528
move all button actions to the right, move toolbar, add background
rebecarubio Jan 8, 2025
a39420e
remove update label, give minwidth to metricCard, add Modal when edit…
rebecarubio Jan 8, 2025
ed0ecd9
show delete modal for all delete cases
rebecarubio Jan 8, 2025
b3bb801
implement design for reporting level
rebecarubio Jan 8, 2025
a03e712
remove delete action from edit modal, place questions toolbar in the …
rebecarubio Jan 8, 2025
042757e
update mui-icons dependency to latest
rebecarubio Jan 9, 2025
db8f370
remove unnecessary / from import to prevent it of breaking import
rebecarubio Jan 9, 2025
7006dfd
add type icons, polish styles
rebecarubio Jan 9, 2025
c5214d4
add alert component, remove checkbox logic from MetricCard and add it…
rebecarubio Jan 9, 2025
5386604
rename outcomes page for logging page, sort imports alphabetically
rebecarubio Jan 9, 2025
980f6fd
add updated yarn.lock file
rebecarubio Jan 9, 2025
2b2adb7
change title for Log survey, move icons to left in edit modal, enable…
rebecarubio Jan 9, 2025
7027ea7
change Modal for Dialog component as it allows closing it with esq key
rebecarubio Jan 9, 2025
d93335d
remove unnecessary brackets
rebecarubio Jan 14, 2025
d8fe3ea
merge main and fix conflicts
rebecarubio Jan 14, 2025
466e53d
rename page component
rebecarubio Jan 14, 2025
cb74a0f
sort imports, implement new data collection card design, remove unnec…
rebecarubio Jan 14, 2025
0b71f30
implement new design for successful visit choice, remove adsClick ico…
rebecarubio Jan 15, 2025
da39efa
fix radiobuttons labels
rebecarubio Jan 15, 2025
a64fd77
Revert "update mui-icons dependency to latest"
rebecarubio Jan 16, 2025
8db2e8a
Revert "add updated yarn.lock file"
rebecarubio Jan 16, 2025
981700e
rename logging file to report and remove old report file
rebecarubio Jan 16, 2025
38babe9
rename page and props variables to report
rebecarubio Jan 16, 2025
8b906c0
add internationalization, change long ternary expression for two cond…
rebecarubio Jan 20, 2025
2a42304
refactor Delete dialogs, add missing internationalization
rebecarubio Jan 29, 2025
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
71 changes: 22 additions & 49 deletions src/features/areaAssignments/components/MetricCard.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
import { Close } from '@mui/icons-material';
import { Close, LinearScale, SwitchLeft } from '@mui/icons-material';
import React, { FC, useEffect, useState } from 'react';
import {
Card,
CardContent,
Typography,
Box,
TextField,
Checkbox,
Button,
IconButton,
} from '@mui/material';

import messageIds from '../l10n/messageIds';
import { Msg } from 'core/i18n';
import { ZetkinMetric } from '../types';

type MetricCardProps = {
hasDefinedDone: boolean;
isOnlyQuestion: boolean;
metric: ZetkinMetric;
onClose: () => void;
onDelete: (target: EventTarget & HTMLButtonElement) => void;
onSave: (metric: ZetkinMetric) => void;
};

const MetricCard: FC<MetricCardProps> = ({
hasDefinedDone,
isOnlyQuestion,
metric,
onClose,
onDelete,
onSave,
}) => {
const MetricCard: FC<MetricCardProps> = ({ metric, onClose, onSave }) => {
const [question, setQuestion] = useState<string>(metric.question || '');
const [description, setDescription] = useState<string>(
metric.description || ''
Expand All @@ -38,32 +29,36 @@ const MetricCard: FC<MetricCardProps> = ({
metric.definesDone || false
);

const isEditing = !!metric?.id;

useEffect(() => {
setQuestion(metric.question || '');
setDescription(metric.description || '');
setDefinesDone(metric.definesDone || false);
}, [metric]);

const showDefinesDoneCheckbox =
metric.kind == 'boolean' && (metric.definesDone || !hasDefinedDone);

return (
<Card sx={{ marginTop: 2 }}>
<Card sx={{ minWidth: 400 }}>
<CardContent>
<Box alignItems="center" display="flex" justifyContent="space-between">
<Typography gutterBottom variant="h5">
{metric.kind === 'boolean' ? 'Yes/No Question' : 'Scale Question'}
</Typography>
{metric.kind === 'boolean' ? (
<Typography alignItems="center" display="flex" variant="h6">
<SwitchLeft color="secondary" sx={{ marginRight: 1 }} />
<Msg id={messageIds.report.metricCard.choice} />
</Typography>
) : (
<Typography alignItems="center" display="flex" variant="h6">
<LinearScale color="secondary" sx={{ marginRight: 1 }} />
<Msg id={messageIds.report.metricCard.scale} />
</Typography>
)}

<IconButton onClick={onClose}>
<Close />
</IconButton>
</Box>
<Box display="flex" flexDirection="column" justifyContent="center">
{metric.kind == 'scale5' && (
<Typography fontStyle="italic" mb={1}>
The areaAssignee will respond by giving a rating from 1 to 5
<Typography color="secondary" fontStyle="italic" mb={1}>
<Msg id={messageIds.report.metricCard.ratingDescription} />
</Typography>
)}
<TextField
Expand All @@ -80,29 +75,7 @@ const MetricCard: FC<MetricCardProps> = ({
value={description}
variant="outlined"
/>
{showDefinesDoneCheckbox && (
<Box alignItems="center" display="flex">
<Checkbox
checked={definesDone}
disabled={definesDone && isOnlyQuestion}
onChange={(ev) => setDefinesDone(ev.target.checked)}
/>
<Typography>
The answer to this question defines if the mission was
successful
</Typography>
</Box>
)}
<Box display="flex" gap={1} justifyContent="center" width="100%">
{isEditing && !isOnlyQuestion && (
<Button
color="error"
onClick={(ev) => onDelete(ev.currentTarget)}
variant="outlined"
>
Delete
</Button>
)}
<Box display="flex" gap={1} justifyContent="right" width="100%">
<Button
onClick={() => {
onSave({
Expand All @@ -113,9 +86,9 @@ const MetricCard: FC<MetricCardProps> = ({
question,
});
}}
variant="outlined"
variant="contained"
>
{isEditing ? 'Update' : 'Save'}
<Msg id={messageIds.report.metricCard.save} />
</Button>
</Box>
</Box>
Expand Down
45 changes: 45 additions & 0 deletions src/features/areaAssignments/l10n/messageIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,49 @@ export default makeMessages('feat.areaAssignments', {
},
},
},
report: {
card: {
definesSuccess: m('Defines success'),
delete: m('Delete'),
description: m('No description'),
question: m('Untitled question'),
},
dataCard: {
header: m('Data precision & privacy'),
household: m('per household (most precise)'),
info: m('Collect data...'),
location: m('per location (less precise, more privacy)'),
subheader: m(
'Configuring where to store the data is a matter of striking a balance between precision and privacy that is right for your cause'
),
},
delete: {
cancel: m('Cancel'),
confirm: m('Confirm'),
deleteWarningText: m<{ title: string }>(
'If you want to delete {title} you need to pick another choice question to be the question that defines if the visit was successful'
),
dialog: m(
'Are you sure you want to delete this question? This action is permanent and it cannot be undone.'
),
select: m('Select'),
},
metricCard: {
choice: m('Choice question'),
ratingDescription: m(
' The assignee will respond by giving a rating from 1 to 5'
),
save: m('Save'),
scale: m('Scale question'),
},
successCard: {
header: m('Successful visit'),
subheader: m(
'Pick a question to use when counting successful visits. Answering yes to this question will count the visit as successful'
),
},
toolBar: {
title: m('Add questions for your canvass assignment.'),
},
},
});
Loading
Loading