This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4756 from minvws/release/2.73.0
Release/2.73.0
- Loading branch information
Showing
33 changed files
with
484 additions
and
995 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { colors } from '@corona-dashboard/common'; | ||
import styled from 'styled-components'; | ||
import { Box } from '~/components/base'; | ||
import { mediaQueries, space } from '~/style/theme'; | ||
import { KpiTile } from '../kpi-tile'; | ||
import { Metadata, MetadataProps } from '../metadata'; | ||
import { TwoKpiSection } from '../two-kpi-section'; | ||
import { Text } from '../typography'; | ||
import { KpiContent } from './components/kpi-content'; | ||
import { BorderedKpiSectionProps } from './types'; | ||
|
||
export const BorderedKpiSection = ({ title, description, source, dateUnix, tilesData }: BorderedKpiSectionProps) => { | ||
const metadata: MetadataProps = { | ||
date: dateUnix, | ||
source: source, | ||
}; | ||
|
||
return ( | ||
<KpiTile title={title} hasNoPaddingBottom> | ||
<Text>{description}</Text> | ||
<TwoKpiSection spacing={5}> | ||
<KpiContentContainer> | ||
{tilesData.map((tile, index) => ( | ||
<KpiContent key={index} tile={tile} /> | ||
))} | ||
</KpiContentContainer> | ||
</TwoKpiSection> | ||
<Metadata {...metadata} isTileFooter /> | ||
</KpiTile> | ||
); | ||
}; | ||
|
||
const KpiContentContainer = styled(Box)` | ||
border: 1px solid ${colors.gray3}; | ||
display: flex; | ||
flex-direction: column; | ||
gap: ${space[5]}; | ||
justify-content: space-between; | ||
padding: 24px ${space[3]}; | ||
@media ${mediaQueries.sm} { | ||
flex-direction: row; | ||
padding: 24px; | ||
} | ||
`; |
48 changes: 48 additions & 0 deletions
48
packages/app/src/components/kpi/components/kpi-content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Box } from '~/components/base'; | ||
import { KpiValue } from '~/components/kpi-value'; | ||
import { Markdown } from '~/components/markdown'; | ||
import { BoldText } from '~/components/typography'; | ||
import { Bar } from '~/domain/vaccine/components/bar'; | ||
import { parseBirthyearRange } from '~/domain/vaccine/logic/parse-birthyear-range'; | ||
import { useIntl } from '~/intl'; | ||
import { space } from '~/style/theme'; | ||
import { replaceVariablesInText } from '~/utils'; | ||
import { KpiContentProps } from '../types'; | ||
|
||
export const KpiContent = ({ tile }: KpiContentProps) => { | ||
const { commonTexts, formatPercentage } = useIntl(); | ||
const parsedAgePercentage = tile.value ? `${formatPercentage(tile.value)}%` : '-'; | ||
const parsedBirthyearRange = tile.birthyear ? parseBirthyearRange(tile.birthyear) : null; | ||
|
||
return ( | ||
<Box> | ||
<BoldText>{tile.title}</BoldText> | ||
|
||
<Box paddingTop={space[3]} paddingBottom={tile.differenceValue ? space[1] : space[3]}> | ||
<KpiValue | ||
absolute={tile.differenceValue ? tile.value : null} | ||
difference={tile.differenceValue || undefined} | ||
isAmount={!!tile.differenceValue} | ||
text={!tile.differenceValue ? parsedAgePercentage : undefined} | ||
color={tile?.bar?.color} | ||
/> | ||
</Box> | ||
|
||
{tile.bar && ( | ||
<Box paddingTop={space[2]} paddingBottom={space[3]}> | ||
<Bar value={tile.bar.value} color={tile.bar.color} height={12} /> | ||
</Box> | ||
)} | ||
|
||
<Markdown | ||
content={ | ||
parsedBirthyearRange | ||
? replaceVariablesInText(tile.description, { | ||
birthyear: replaceVariablesInText(commonTexts.common.birthyear_ranges[parsedBirthyearRange.type], parsedBirthyearRange), | ||
}) | ||
: tile.description | ||
} | ||
/> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { DifferenceInteger } from '@corona-dashboard/common'; | ||
|
||
type TileData = { | ||
description: string; | ||
title: string; | ||
value: number | null; | ||
bar?: BarType; | ||
birthyear?: string | null; | ||
differenceValue?: DifferenceInteger; | ||
}; | ||
|
||
export interface BorderedKpiSectionProps { | ||
dateUnix: number; | ||
description: string; | ||
source: { | ||
href: string; | ||
text: string; | ||
}; | ||
tilesData: [TileData, TileData]; | ||
title: string; | ||
} | ||
|
||
export interface KpiContentProps { | ||
tile: TileData; | ||
} | ||
|
||
export type BarType = { | ||
value: number; | ||
color: string; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
packages/app/src/components/severity-indicator-tile/components/timeline/logic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { middleOfDayInSeconds } from '@corona-dashboard/common'; | ||
import { createDateFromUnixTimestamp } from '~/utils/create-date-from-unix-timestamp'; | ||
import { SeverityIndicatorTimelineEventConfig } from './timeline'; | ||
|
||
/** | ||
* Calculated the difference, in days, between two dates. | ||
* @param start - the start date of a given range | ||
* @param end - the end date of a given range | ||
* @returns the number of days between two dates | ||
*/ | ||
export const getDifferenceInDays = (start: Date, end: Date): number => { | ||
return Math.floor((end.getTime() - start.getTime()) / (1000 * 3600 * 24)); | ||
}; | ||
|
||
/** | ||
* Calculates the middle of the day for each passed in date (either today or the start and end date for a given range). | ||
* @param today - today's Date object | ||
* @param startDate - the start date of a given range | ||
* @param endDate - the end date of a given range | ||
* @returns the date representing the middle of the day for the passed in dates | ||
*/ | ||
const getMiddleOfDayDates = (today: Date, startDate: number, endDate: number): Record<string, Date> => { | ||
const todayMiddleOfDayDate = createDateFromUnixTimestamp(middleOfDayInSeconds(today.getTime() / 1000)); | ||
const startOfIntervalDate = createDateFromUnixTimestamp(middleOfDayInSeconds(startDate)); | ||
const endOfIntervalDate = createDateFromUnixTimestamp(middleOfDayInSeconds(endDate)); | ||
|
||
return { | ||
startOfIntervalDate, | ||
endOfIntervalDate, | ||
todayMiddleOfDayDate, | ||
}; | ||
}; | ||
|
||
/** | ||
* Calculates the relative offset value for the 'Today' label on the timeline. | ||
* @param today - today's Date object | ||
* @param startDate - the start date of the timeline | ||
* @param endDate - the end date of the timeline | ||
* @returns the relative offset value for the 'Today' label on the timeline | ||
*/ | ||
export const getTimelineBarArrowOffset = (today: Date, startDate: number, endDate: number): number => { | ||
const { startOfIntervalDate, endOfIntervalDate, todayMiddleOfDayDate } = getMiddleOfDayDates(today, startDate, endDate); | ||
const numberOfDaysInInterval = getDifferenceInDays(startOfIntervalDate, endOfIntervalDate); | ||
const numberOfDaysFromStartToToday = getDifferenceInDays(startOfIntervalDate, todayMiddleOfDayDate); | ||
const arrowOffset = (numberOfDaysFromStartToToday / numberOfDaysInInterval) * 100; | ||
|
||
return arrowOffset; | ||
}; | ||
|
||
/** | ||
* Calculates the amount of relative width a timeline bar part covers. | ||
* @param daysInBarPart - the amount of days in a timeline bar part | ||
* @param totalDays - the total amount of days in a timeline | ||
* @returns the relative width of a timeline bar part | ||
*/ | ||
export const getTimelineBarPartWidth = (daysInBarPart: ReturnType<typeof getDifferenceInDays>, totalDays: number) => (daysInBarPart / totalDays) * 100; | ||
|
||
/** | ||
* Calculates the start and end date of a given timeline range. | ||
* @param timelineEvents - the timeline events/range to calculate the start and end dates for | ||
* @returns the start and end date of the given timeline range | ||
*/ | ||
export const getTimelineRangeDates = (timelineEvents: SeverityIndicatorTimelineEventConfig[]) => { | ||
const timelineEventDates = timelineEvents | ||
.flatMap((timelineEvent: SeverityIndicatorTimelineEventConfig) => [timelineEvent.start, timelineEvent.end]) | ||
.map((timelineEventDate: number) => { | ||
return createDateFromUnixTimestamp(timelineEventDate).getTime(); | ||
}); | ||
|
||
return { | ||
startDate: Math.min(...timelineEventDates), | ||
endDate: Math.max(...timelineEventDates), | ||
}; | ||
}; |
28 changes: 0 additions & 28 deletions
28
...onents/severity-indicator-tile/components/timeline/logic/get-timeline-bar-arrow-offset.ts
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
.../components/severity-indicator-tile/components/timeline/logic/get-timeline-range-dates.ts
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.