Skip to content

Commit

Permalink
Merge pull request #32 from Amsterdam/improvement/123183-add-form-var…
Browse files Browse the repository at this point in the history
…iables-to-event-history

123183 Added form values to event history
  • Loading branch information
remyvdwereld authored Aug 12, 2024
2 parents 74b0867 + 395113e commit 4ee1de5
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/__external__/CaseEvent.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
type EventType = "CASE" | "GENERIC_TASK"

type Value = Record<string, Value> | string

type CaseEvent = {
id: number
event_values: Record<string, string>
event_variables: Record<string, string>
event_variables: Record<string, Value>
date_created: string // date-time
type: EventType
emitter_id: number
Expand Down
17 changes: 9 additions & 8 deletions src/app/components/TimelineEvents/TimelineEvent.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from "react"
import { DescriptionList } from "@amsterdam/design-system-react"
import { getEventValueName } from "./dictionaries"
import { isValidDate, formatDate } from "app/utils/dates"
import { styled } from "styled-components"
import { useValues } from "./useValues"


type Props = {
Expand All @@ -12,7 +11,7 @@ type Props = {
const Wrapper = styled.div`
margin-left: 25px;
padding: 25px;
background-color: rgba(0, 0, 0, 0.08);;
background-color: rgba(0, 0, 0, 0.08);
border: 0.5px solid #d4d2d2;
border-radius: 4px;
box-shadow:
Expand All @@ -21,17 +20,19 @@ const Wrapper = styled.div`
0px 12px 48px 16px rgba(0, 0, 0, 0.03);
`


export const TimelineEvent: React.FC<Props> = ({ event }) => {
const { event_values } = event
const data = useValues(event)
return (
<Wrapper>
<DescriptionList>
{ Object.entries(event_values).map(([key, value], index) => (
{data.map((item, index) => (
<React.Fragment key={ `event_values-${ index }` }>
<DescriptionList.Term>
{ getEventValueName(key) }
</DescriptionList.Term><DescriptionList.Details>
{ isValidDate(value) ? formatDate(value, true) : value }
{ item.key }
</DescriptionList.Term>
<DescriptionList.Details>
{ item.value }
</DescriptionList.Details>
</React.Fragment>
))}
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/TimelineEvents/dictionaries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const getEventTitle = (event: CaseEvent): string => {

export const EVENT_VALUES: Record<string, string> = {
"date_added": "Datum",
"author": "Medewerker",
"author": "Uitvoerder",
"description": "Toelichting"
}

Expand Down
36 changes: 36 additions & 0 deletions src/app/components/TimelineEvents/useValues.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { isValidDate, formatDate } from "app/utils/dates"
import { EVENT_TYPES, getEventValueName } from "./dictionaries"


type Value = {
key: string
value: string | number
}

export const useValues = (event: CaseEvent) => {
const { event_values, event_variables } = event
const values: Value[] = []

// Map event_values
Object.entries(event_values).forEach(([key, value]) => {
// Don't return the description of a GENERIC_TASK because this field is used as event title.
if (event.type === EVENT_TYPES["GENERIC_TASK"] && key === "description") {
return
}
// Translate the key and the value to readable dutch.
const label = getEventValueName(key)
const keyValue = isValidDate(value) ? formatDate(value, true) : value
values.push({ key: label, value: keyValue })
})

// Map event_variables if a form has been submitted.
// There must be data (event_variables) and it cannot be a generic boolean (completed)
if (event_variables && !event_variables?.completed) {
Object.entries(event_variables).forEach(([, value]) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
values.push({ key: value?.label, value: value?.value })
})
}

return values
}

0 comments on commit 4ee1de5

Please sign in to comment.