11import { Typography } from 'antd' ;
22import React from 'react' ;
3+ import { useTranslation } from 'react-i18next' ;
34import { VerticalTimeline , VerticalTimelineElement } from 'react-vertical-timeline-component' ;
45import 'react-vertical-timeline-component/style.min.css' ;
56import styled , { useTheme } from 'styled-components' ;
67
78import { useEntityData } from '@app/entity/shared/EntityContext' ;
89
910import { useGetTimelineQuery } from '@graphql/timeline.generated' ;
10- import { ChangeCategoryType } from '@types' ;
11+ import { ChangeCategoryType , ChangeOperationType } from '@types' ;
1112
1213import TimelineIcon from '@images/timeline-icon.svg?react' ;
1314
1415const PLACEHOLDER_SUBTITLE = 'subtitle' ;
1516const PLACEHOLDER_DESC = 'description' ;
1617
18+ const TIMELINE_LAYOUT = '1-column-left' ;
19+
20+ const CONTENT_STYLE : React . CSSProperties = {
21+ boxShadow : 'none' ,
22+ padding : 0 ,
23+ } ;
24+
25+ const ICON_STYLE : React . CSSProperties = {
26+ height : '10px' ,
27+ width : '10px' ,
28+ boxShadow : 'none' ,
29+ position : 'absolute' ,
30+ top : '30%' ,
31+ left : 0 ,
32+ } ;
33+
1734const TimeLine = styled ( VerticalTimeline ) `
1835 svg {
1936 height: 10px;
@@ -40,9 +57,23 @@ const Event = styled(Typography.Text)`
4057` ;
4158
4259export const SchemaTimelineSection = ( ) => {
60+ const { t } = useTranslation ( 'entity.profile.timeline' ) ;
4361 const theme = useTheme ( ) ;
4462 const { urn } = useEntityData ( ) ;
4563
64+ const getChangeTitle = ( operation : ChangeOperationType | null | undefined , fieldPath ?: string | null ) : string => {
65+ switch ( operation ) {
66+ case ChangeOperationType . Add :
67+ return t ( 'changeAdded' , { fieldPath } ) ;
68+ case ChangeOperationType . Modify :
69+ return t ( 'changeModified' , { fieldPath } ) ;
70+ case ChangeOperationType . Remove :
71+ return t ( 'changeRemoved' , { fieldPath } ) ;
72+ default :
73+ return '' ;
74+ }
75+ } ;
76+
4677 const timelineResult = useGetTimelineQuery ( {
4778 // also pass in the changeCategories
4879 variables : { input : { urn, changeCategories : [ ChangeCategoryType . TechnicalSchema ] } } ,
@@ -54,12 +85,11 @@ export const SchemaTimelineSection = () => {
5485 transactions ?. forEach ( ( transaction ) => {
5586 const time = new Date ( transaction . timestampMillis ) . toDateString ( ) ;
5687 transaction . changes ?. forEach ( ( change ) => {
88+ const fieldPath = change . parameters ?. find ( ( parameter ) => parameter . key === 'fieldPath' ) ?. value ;
5789 const entry = {
5890 // operation: change.operation,
5991 // description: change.description,
60- title : `${
61- change . parameters ?. find ( ( parameter ) => parameter . key === 'fieldPath' ) ?. value
62- } was ${ change . operation ?. toLowerCase ( ) } ed.`,
92+ title : getChangeTitle ( change . operation , fieldPath ) ,
6393 subtitle : PLACEHOLDER_SUBTITLE ,
6494 desc : PLACEHOLDER_DESC ,
6595 time,
@@ -69,31 +99,21 @@ export const SchemaTimelineSection = () => {
6999 } ) ;
70100
71101 return (
72- < TimeLine layout = "1-column-left" lineColor = { theme . colors . border } animate = { false } >
73- { timelineHistory . map ( ( t ) => {
102+ < TimeLine layout = { TIMELINE_LAYOUT } lineColor = { theme . colors . border } animate = { false } >
103+ { timelineHistory . map ( ( entry ) => {
74104 return (
75105 < VerticalTimelineElement
76- key = { t . title }
77- contentStyle = { {
78- boxShadow : 'none' ,
79- padding : 0 ,
80- } }
81- date = { t . date }
106+ key = { entry . title }
107+ contentStyle = { CONTENT_STYLE }
108+ date = { entry . date }
82109 icon = { < TimelineIcon /> }
83- iconStyle = { {
84- height : '10px' ,
85- width : '10px' ,
86- boxShadow : 'none' ,
87- position : 'absolute' ,
88- top : '30%' ,
89- left : 0 ,
90- } }
110+ iconStyle = { ICON_STYLE }
91111 >
92- { t . title && (
112+ { entry . title && (
93113 < >
94- < DateText > { t . time } </ DateText >
114+ < DateText > { entry . time } </ DateText >
95115 < div >
96- < Event > { t . title } </ Event >
116+ < Event > { entry . title } </ Event >
97117 </ div >
98118 </ >
99119 ) }
0 commit comments