11import { ScaleDataGrid , ScaleIconActionCheckmark , ScaleIconActionMenu , ScaleMenuFlyoutItem , ScaleMenuFlyoutList } from "@telekom/scale-components-react" ;
2+ import dayjs from "dayjs" ;
3+ import { chain } from "lodash" ;
24import { useEffect , useRef , useState } from "react" ;
35import { Helmet } from "react-helmet" ;
6+ import { EventStatus } from "~/Components/Event/Enums" ;
47import { Dic } from "~/Helpers/Entities" ;
5- import reviewsHistoryMock from "./reviewsHistoryMock.json " ;
8+ import { useStatus } from "~/Services/Status " ;
69
710const PAGE_SIZE_KEY = "reviewsPageSize" ;
811const PAGE_SIZE_OPTIONS = [ 10 , 20 , 50 ] ;
@@ -13,22 +16,15 @@ const PAGE_SIZE_OPTIONS = [10, 20, 50];
1316 * @version 0.3.0
1417 */
1518export function Reviews ( ) {
19+ const { DB } = useStatus ( ) ;
1620 const gridRef = useRef < HTMLScaleDataGridElement > ( null ) ;
1721
1822 const [ pageSize , setPageSize ] = useState < number > ( ( ) => {
1923 const stored = localStorage . getItem ( PAGE_SIZE_KEY ) ;
2024 return stored ? parseInt ( stored , 10 ) : 10 ;
2125 } ) ;
2226
23- interface ReviewItem {
24- id : number ;
25- planStartCET : string ;
26- planEndCET : string ;
27- region : string ;
28- service : string ;
29- }
30-
31- const historyItems = reviewsHistoryMock as ReviewItem [ ] ;
27+ const pendingEvents = DB . Events . filter ( ( x ) => x . Status === EventStatus . PendingReview ) ;
3228
3329 useEffect ( ( ) => {
3430 if ( ! gridRef . current ) {
@@ -46,23 +42,41 @@ export function Reviews() {
4642 { type : "actions" , label : "Detail" } ,
4743 ] ;
4844
49- const events = historyItems . map ( ( item ) => [
50- item . id ,
51- item . planStartCET ,
52- item . planEndCET ,
53- item . region ,
54- item . service ,
55- [
56- {
57- label : "↗" ,
58- variant : "secondary" ,
59- href : `/Event/${ item . id } `
60- }
61- ]
62- ] ) ;
45+ const events = chain ( pendingEvents )
46+ . map ( ( x ) => {
47+ const rs = Array . from ( x . RegionServices ) ;
48+
49+ const services = chain ( rs )
50+ . map ( s => s . Service . Name )
51+ . uniq ( )
52+ . value ( ) ;
53+
54+ const regions = chain ( rs )
55+ . map ( r => r . Region . Name )
56+ . uniq ( )
57+ . value ( ) ;
58+
59+ return [
60+ x . Id ,
61+ dayjs ( x . Start ) . tz ( Dic . TZ ) . format ( Dic . Time ) ,
62+ x . End ? dayjs ( x . End ) . tz ( Dic . TZ ) . format ( Dic . Time ) : "-" ,
63+ regions . join ( ", " ) ,
64+ services . length > 2
65+ ? `${ services . slice ( 0 , 2 ) . join ( ", " ) } +${ services . length - 2 } `
66+ : services . join ( ", " ) ,
67+ [
68+ {
69+ label : "↗" ,
70+ variant : "secondary" ,
71+ href : `/Event/${ x . Id } `
72+ }
73+ ]
74+ ] ;
75+ } )
76+ . value ( ) ;
6377
6478 grid . rows = events ;
65- } , [ gridRef . current , historyItems ] ) ;
79+ } , [ gridRef . current , pendingEvents ] ) ;
6680
6781 return (
6882 < >
0 commit comments