Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Feature/cor 1285 sanity thermometer timeline events #4540

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export const TimelineTooltipContent = ({ config, hasMultipleEvents, onNext, onPr
<BoldText>{config.title}</BoldText>
</Box>

<Text variant="label1">{config.description}</Text>
<Text variant="label1">
{replaceVariablesInText(config.description.split('**').join(''), {
DariaKwork marked this conversation as resolved.
Show resolved Hide resolved
label: config.title.toLowerCase(),
})}
</Text>

{currentEstimationLabel && (
<Box textVariant="label1">
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const Home = (props: StaticProps<typeof getStaticProps>) => {
const currentSeverityLevel = thermometer.currentLevel as unknown as SeverityLevels;
const currentSeverityLevelTexts = thermometer.thermometerLevels.find((thermometerLevel) => thermometerLevel.level === currentSeverityLevel);

const thermometerEvents = getThermometerEvents(thermometer.timeline.ThermometerTimelineEvents);
const thermometerEvents = getThermometerEvents(thermometer.timeline.ThermometerTimelineEvents, thermometer.thermometerLevels);

const { startDate, endDate } = getTimelineRangeDates(thermometerEvents);

Expand Down
13 changes: 8 additions & 5 deletions packages/app/src/queries/get-topical-structure-query.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ThermometerTimelineEvent } from './query-types';
import { ThermometerLevel, ThermometerTimelineEvent } from './query-types';
import { SeverityIndicatorTimelineEventConfig } from '~/components/severity-indicator-tile/components/timeline/timeline';
import { SeverityLevel } from '~/components/severity-indicator-tile/types';

export function getTopicalStructureQuery(locale: string) {
const query = `// groq
Expand Down Expand Up @@ -106,12 +107,14 @@ export function getTopicalStructureQuery(locale: string) {
return query;
}

export const getThermometerEvents = (thermometerEvents: ThermometerTimelineEvent[]) => {
export const getThermometerEvents = (thermometerEvents: ThermometerTimelineEvent[], thermometerLevels: ThermometerLevel[]) => {
return thermometerEvents.map<SeverityIndicatorTimelineEventConfig>((thermometerEvent) => {
DariaKwork marked this conversation as resolved.
Show resolved Hide resolved
const levelDetails = thermometerLevels.find((thermometerLevel) => thermometerLevel.level === (thermometerEvent.level as SeverityLevel)) as ThermometerLevel;

return {
title: thermometerEvent.title,
description: thermometerEvent.description,
level: thermometerEvent.level,
title: levelDetails.label,
description: levelDetails.description,
level: levelDetails.level,
start: new Date(thermometerEvent.date).getTime() / 1000,
end: new Date(thermometerEvent.dateEnd).getTime() / 1000,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/queries/query-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface ThermometerTimelineEvent {
dateEnd: number;
}

interface ThermometerLevel {
export interface ThermometerLevel {
level: SeverityLevel;
label: string;
description: string;
Expand Down
6 changes: 2 additions & 4 deletions packages/cms/src/schemas/topical/thermometer-level.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { Rule } from '~/sanity';
import { THERMOMETER_MIN_VALUE, THERMOMETER_MAX_VALUE } from './thermometer';
import { SEVERITY_LEVELS_LIST } from '@corona-dashboard/app/src/components/severity-indicator-tile/constants';
import { REQUIRED, REQUIRED_MIN_MAX } from '../../validation';
import { REQUIRED } from '../../validation';
import { BsFillFileBarGraphFill } from 'react-icons/bs';

export const thermometerLevel = {
Expand All @@ -18,7 +16,7 @@ export const thermometerLevel = {
list: SEVERITY_LEVELS_LIST,
layout: 'dropdown',
},
validation: (rule: Rule) => REQUIRED_MIN_MAX(rule, THERMOMETER_MIN_VALUE, THERMOMETER_MAX_VALUE),
validation: REQUIRED,
},
{
title: 'Stand naam',
Expand Down
26 changes: 7 additions & 19 deletions packages/cms/src/schemas/topical/thermometer-timeline-event.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { SEVERITY_LEVELS_LIST } from '@corona-dashboard/app/src/components/severity-indicator-tile/constants';
import { isDefined } from 'ts-is-present';
import { Rule } from '~/sanity';
import { localeStringValidation } from '../../language/locale-validation';

import { REQUIRED, REQUIRED_MIN_MAX } from '../../validation';

import { THERMOMETER_MIN_VALUE, THERMOMETER_MAX_VALUE } from './thermometer';
import { REQUIRED } from '../../validation';

const DATE_FORMAT = 'YYYY-MM-DD';

Expand All @@ -13,23 +9,15 @@ export const thermometerTimelineEvent = {
type: 'document',
title: 'Thermometer tijdlijn gebeurtenis',
fields: [
{
title: 'Titel',
name: 'title',
type: 'localeString',
validation: localeStringValidation((rule) => rule.required().max(60).error('Titels zijn gelimiteerd tot maximaal 60 tekens')),
},
{
title: 'Omschrijving',
name: 'description',
type: 'localeText',
validation: REQUIRED,
},
{
title: 'Level',
name: 'level',
type: 'number',
validation: (rule: Rule) => REQUIRED_MIN_MAX(rule, THERMOMETER_MIN_VALUE, THERMOMETER_MAX_VALUE),
options: {
list: SEVERITY_LEVELS_LIST,
layout: 'dropdown',
},
validation: REQUIRED,
},
{
title: 'Datum',
Expand Down
1 change: 1 addition & 0 deletions packages/cms/src/schemas/topical/thermometer-timeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const thermometerTimeline = {
},
{
title: 'Tooltip label',
description: 'Extra beschrijving voor in de laatste gebeurtenis in de tijdlijn',
name: 'tooltipCurrentEstimationLabel',
type: 'localeString',
validation: REQUIRED,
Expand Down
8 changes: 2 additions & 6 deletions packages/cms/src/schemas/topical/thermometer.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { Rule } from '~/sanity';
import { SEVERITY_LEVELS_LIST } from '@corona-dashboard/app/src/components/severity-indicator-tile/constants';
import { REQUIRED, REQUIRED_MIN_MAX } from '../../validation';
import { REQUIRED } from '../../validation';
import { KpiIconInput } from '../../components/portable-text/kpi-configuration/kpi-icon-input';

export const THERMOMETER_MIN_VALUE = Math.min(...SEVERITY_LEVELS_LIST);
export const THERMOMETER_MAX_VALUE = Math.max(...SEVERITY_LEVELS_LIST);

export const thermometer = {
type: 'object',
title: 'Thermometer',
Expand Down Expand Up @@ -42,7 +38,7 @@ export const thermometer = {
list: SEVERITY_LEVELS_LIST,
layout: 'dropdown',
},
validation: (rule: Rule) => REQUIRED_MIN_MAX(rule, THERMOMETER_MIN_VALUE, THERMOMETER_MAX_VALUE),
validation: REQUIRED,
},
{
title: 'Standen',
Expand Down