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

Feature/UI improvements #1371

Merged
merged 5 commits into from
Nov 1, 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
58 changes: 49 additions & 9 deletions frontend/src/components/Charts/FinancesBarChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import { css } from '@mui/material';
import {
BarLabel,
BarPlot,
ChartsLegend,
ChartsReferenceLine,
ChartsXAxis,
ChartsYAxis,
DefaultChartsLegend,
ResponsiveChartContainer,
useDrawingArea,
useYScale,
} from '@mui/x-charts';
import { ScaleLinear } from 'd3-scale';
import { translate } from 'ol/transform';

import { useTranslations } from '@frontend/stores/lang';

Expand Down Expand Up @@ -59,12 +62,27 @@ export function FinancesBarChart({ colors, barData, dataLabels, totalAmount, yAx

function getTickInterval() {
if (!yAxisScale) return 'auto';
return [0, yAxisScale.min / 2, yAxisScale.min, yAxisScale.max / 2, yAxisScale.max];

if (yAxisScale.min == 0) {
return [0, yAxisScale.max / 2, yAxisScale.max];
}
if (yAxisScale.max == 0) {
return [0, yAxisScale.min / 2, yAxisScale.min];
}

const interval = Math.max(Math.abs(yAxisScale.max), Math.abs(yAxisScale.min)) / 2;
return [
0,
yAxisScale.min,
yAxisScale.min + interval,
yAxisScale.max - interval,
yAxisScale.max,
];
}

return (
<ResponsiveChartContainer
height={220}
height={240}
css={css`
padding: 7px; // Dirty trick to display ticklabels
& .MuiLineElement-root {
Expand Down Expand Up @@ -126,13 +144,35 @@ export function FinancesBarChart({ colors, barData, dataLabels, totalAmount, yAx
}}
/>
{refValue && (
<ChartsReferenceLine
y={refValue}
label={tr('financesChart.averageLineLabel')}
labelAlign="end"
lineStyle={{ stroke: '#4BA226', strokeWidth: 1, strokeDasharray: '6' }}
labelStyle={{ fontSize: 12, fill: labelColor }}
/>
<>
<ChartsReferenceLine
y={refValue}
labelAlign="end"
lineStyle={{ stroke: '#4BA226', strokeWidth: 1, strokeDasharray: '6' }}
/>
<ChartsLegend
slots={{
legend: () => {
const { width } = useDrawingArea();

return (
<g transform={`translate(${width - 160}, 40)`}>
<line
x1="50"
y1="-3"
x2="80"
y2="-3"
style={{ stroke: '#4BA226', strokeWidth: 1, strokeDasharray: '6' }}
/>
<text x={90} style={{ fontSize: 12, fill: labelColor }}>
{tr('financesChart.averageLineLabel')}
</text>
</g>
);
},
}}
/>
</>
)}
<ChartsXAxis position="bottom" axisId="x-axis-id" tickPlacement="middle" tickSize={4} />
<ChartsYAxis
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Charts/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ export function ProgressBar({ fillPrecentage }: Props) {
<div
css={css`
${baseStyle}
margin: 0 1rem;
min-width: 200px;
margin: 0 1rem 0 auto;
width: min(40em, 40%);
flex: none;
display: flex;
flex: 1;
background-color: #fff;
gap: 2px;
`}
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/Charts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ export function getYAxisScale(values: { max: number; min: number }) {
const maxDatasetYValue = getYAxisScaleValue(values.max);
const minDatasetYValue = getYAxisScaleValue(values.min);

const maxAbsoluteValue = Math.max(Math.abs(maxDatasetYValue), Math.abs(minDatasetYValue * 1.5));

return {
max: maxDatasetYValue > 0 ? Math.max(Math.abs(minDatasetYValue) / 2, maxDatasetYValue) : 0,
min:
minDatasetYValue < 0 ? Math.min(Math.abs(maxDatasetYValue) / -2, minDatasetYValue * 1.5) : 0,
max: maxDatasetYValue > 0 ? maxAbsoluteValue : 0,
min: minDatasetYValue < 0 ? maxAbsoluteValue * -1 : 0,
};
}
6 changes: 4 additions & 2 deletions frontend/src/components/Map/MapToolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@mui/icons-material';
import { Box, Divider, IconButton, Tooltip } from '@mui/material';
import { useState } from 'react';
import { useParams } from 'react-router';
import { useLocation, useParams } from 'react-router';

import { useTranslations } from '@frontend/stores/lang';

Expand Down Expand Up @@ -140,6 +140,8 @@ export function MapToolbar(props: Props) {
const tr = useTranslations();
const [selectedTool, setSelectedTool] = useState<ToolType | null>(null);
const { projectObjectId } = useParams() as { projectObjectId?: string };
const { pathname } = useLocation();
const isProjectObjectView = projectObjectId || pathname.includes('uusi-kohde');

function handleToolClick(tool: ToolType | null) {
if (tool === 'copyFromSelection' || tool === 'deleteAllFeatures') {
Expand All @@ -164,7 +166,7 @@ export function MapToolbar(props: Props) {
: typeof tool.tooltip === 'object'
? tr(
tool.tooltip[props.geometryExists ? 'existing' : 'new'][
projectObjectId ? 'projectObject' : 'project'
isProjectObjectView ? 'projectObject' : 'project'
],
)
: tr(tool.tooltip)
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/components/Map/MapWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,12 @@ export const MapWrapper = forwardRef(function MapWrapper<
function copySelectionToDrawSource() {
const drawFeatureIds = drawSource.getFeatures().map((feature) => olUtil.getUid(feature));
const selectionFeatures = selectionSource.getFeatures();
const featuresToCopy = selectionFeatures.filter(
(feature) => !drawFeatureIds.includes(olUtil.getUid(feature)),
);
const featuresToCopy = selectionFeatures
.filter((feature) => !drawFeatureIds.includes(olUtil.getUid(feature)))
.map((feature) => {
feature.setProperties({ editing: true });
return feature;
});
drawSource.addFeatures(featuresToCopy);
selectionSource.clear();
drawFinished();
Expand Down
24 changes: 17 additions & 7 deletions frontend/src/components/Map/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,25 @@ const _PROJ_OBJ_DRAW_FILL = _PROJ_OBJ_FILL;
const _PROJ_OBJ_DRAW_STROKE = _PROJ_OBJ_STROKE;
const _PROJ_OBJ_DRAW_STROKE_WIDTH = 2;

export const PROJ_OBJ_DRAW_STYLE = new Style({
fill: new Fill({
color: _PROJ_OBJ_DRAW_FILL,
export const PROJ_OBJ_DRAW_STYLE = [
new Style({
fill: new Fill({
color: _PROJ_OBJ_DRAW_FILL,
}),
stroke: new Stroke({
color: _PROJ_OBJ_DRAW_STROKE,
width: _PROJ_OBJ_DRAW_STROKE_WIDTH,
}),
zIndex: 1,
}),
stroke: new Stroke({
color: _PROJ_OBJ_DRAW_STROKE,
width: _PROJ_OBJ_DRAW_STROKE_WIDTH,
new Style({
stroke: new Stroke({
color: _DEFAULT_HIGHLIGHT_STROKE,
width: _PROJECT_STROKE_WIDTH + 4,
}),
zIndex: 0,
}),
});
];

export function getStyleWithPointIcon(styleLike: StyleLike, isFaded: boolean): StyleFunction {
return function (feature: FeatureLike, resolution: number) {
Expand Down
26 changes: 21 additions & 5 deletions frontend/src/views/Project/BudgetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,15 @@ export const BudgetTable = forwardRef(function BudgetTable(props: Props, ref) {
return !budget ? null : (
<>
<FormProvider {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} autoComplete="off">
<form
css={css`
& .MuiFormControl-root {
margin: 0;
}
`}
onSubmit={form.handleSubmit(onSubmit)}
autoComplete="off"
>
<TableContainer>
<Table size="small">
<TableHead
Expand Down Expand Up @@ -341,10 +349,18 @@ export const BudgetTable = forwardRef(function BudgetTable(props: Props, ref) {
{fields?.includes('actual') && (
<TableCell>
{!props.actualsLoading ? (
<CurrencyInput
directlyHandleValueChange
value={props.actuals?.find((data) => data.year === year)?.total ?? null}
/>
<Box
css={css`
margin: 8px 4px;
`}
>
<CurrencyInput
directlyHandleValueChange
value={
props.actuals?.find((data) => data.year === year)?.total ?? null
}
/>
</Box>
) : (
<Skeleton
variant="rectangular"
Expand Down
1 change: 1 addition & 0 deletions frontend/src/views/Project/ProjectFinancesCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function ProjectFinancesCharts(props: Props) {
startYear: props.startYear,
endYear: props.endYear,
});

const budget = trpc.project.getBudget.useQuery(
{ projectId: props.projectId },
{ enabled: Boolean(monthlyActuals.data) },
Expand Down
10 changes: 9 additions & 1 deletion frontend/src/views/Task/TaskRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ interface Props {

export function TaskRow(props: Readonly<Props>) {
const tr = useTranslations();

function getActivityDescription() {
if (!props.task.activityId && !props.task.description) {
return tr('task.noActivityDescription');
}
return `${props.task.activityId ?? ''} ${props.task.description ?? ''}`;
}

return (
<>
<TableRow>
<TableCell>{props.task.description ?? tr('task.noActivityDescription')}</TableCell>
<TableCell>{getActivityDescription()}</TableCell>
<TableCell>{formatCurrency(props.task.total)}</TableCell>
</TableRow>
</>
Expand Down
4 changes: 2 additions & 2 deletions shared/src/language/fi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ export const fi = {
'dataTable.noData': 'Ei hakutuloksia.',
'financesChart.averageLineLabel': 'Talousarvio/kuukausi',
'financesChart.totalLabel': 'Yhteensä',
'financesChart.noTotalLabel': 'Ei kuluja tänä vuonna',
'financesChart.noTotalLabel': 'Ei kuluja tänä vuonna.',
'financesChart.totalsErrorLabel': 'Virhe haettaessa toteumatietoja',
'financesChart.amountLabel': 'Talousarvio',
'financesChart.noAmountLabel': 'Talousarvio puuttuu',
'financesChart.noAmountLabel': 'Talousarvio puuttuu.',
'financesChart.loading': 'Ladataan toteumia...',
'itemInfoBox.dateRange': 'Aikaväli',
'itemInfoBox.lifecycleState': 'Elinkaaritila',
Expand Down
Loading