1+ import { useState } from 'react'
12import {
23 Button ,
34 Card ,
@@ -6,42 +7,81 @@ import {
67 Typography ,
78 useTheme ,
89} from '@mui/material'
10+ import { LoadingButton } from '@mui/lab'
911import SaveAltOutlinedIcon from '@mui/icons-material/SaveAltOutlined'
1012import AddIcon from '@mui/icons-material/Add'
11- import { useExportPulses , useGetSources } from '../../../api/pulse.api'
13+ import dayjs from 'dayjs'
14+
15+ import {
16+ useExportPulses ,
17+ useGetSourcesWithMinutes ,
18+ } from '../../../api/pulse.api'
1219import {
1320 SourceDetails ,
1421 supportedSources ,
1522} from '../../../utils/supportedSources'
16- import { useState } from 'react'
1723import SourcesEmpty from './Sources.empty'
1824import SourcesError from './Sources.error'
1925import SourcesLoading from './Sources.loading'
20- import { LoadingButton } from '@mui/lab'
2126import AddSources from './AddSources'
2227import { getTimeSince } from '../../../utils/time'
28+ import { minutesToHours } from '../Time/utils'
29+ import { SourceTimeChart } from './SourceTimeChart'
2330
2431interface SourceRowProps {
2532 source : SourceDetails
2633 lastActive : string
34+ minutes : number
2735}
2836
29- const SourceRow = ( { source, lastActive } : SourceRowProps ) => {
37+ const SourceRow = ( { source, lastActive, minutes } : SourceRowProps ) => {
38+ const theme = useTheme ( )
39+ const compareTime = 90
40+
3041 return (
31- < Stack direction = "row" alignItems = "center" justifyContent = "space-between" >
32- < Stack direction = "row" alignItems = "center" spacing = { 1 } >
42+ < Stack
43+ direction = "row"
44+ alignItems = "center"
45+ justifyContent = "space-between"
46+ width = "100%"
47+ >
48+ < Stack direction = "row" alignItems = "center" spacing = { 1 } width = "100%" >
3349 < img
3450 alt = { source . displayName + ' Logo' }
3551 src = { source . logo }
3652 style = { { height : '32px' , width : '32px' } }
3753 />
38- < Stack direction = "column" >
54+ < Stack direction = "column" width = "100%" >
3955 < Typography variant = "body2" fontWeight = { 700 } >
4056 { source . displayName }
4157 </ Typography >
42- < Typography variant = "body2" fontWeight = { 400 } >
43- { `Last pulse ${ getTimeSince ( lastActive ) } ` }
44- </ Typography >
58+ { minutes > 0 && (
59+ < SourceTimeChart
60+ time = { minutesToHours ( minutes ) }
61+ progress = { Math . floor ( ( minutes / compareTime ) * 100 ) }
62+ color = { theme . palette . graphColors . blue }
63+ />
64+ ) }
65+ < Stack direction = "row" justifyContent = "space-between" >
66+ { minutes === 0 && lastActive && (
67+ < Typography
68+ variant = "body2"
69+ fontWeight = { 400 }
70+ color = { theme . palette . grey [ 300 ] }
71+ >
72+ { `Last pulse ${ getTimeSince ( lastActive ) } ` }
73+ </ Typography >
74+ ) }
75+ { minutes === 0 && (
76+ < Typography
77+ variant = "body1"
78+ fontWeight = { 400 }
79+ color = { theme . palette . grey [ 300 ] }
80+ >
81+ 0m
82+ </ Typography >
83+ ) }
84+ </ Stack >
4585 </ Stack >
4686 </ Stack >
4787 </ Stack >
@@ -50,11 +90,15 @@ const SourceRow = ({ source, lastActive }: SourceRowProps) => {
5090
5191const Sources = ( ) => {
5292 const {
53- data : connectedSources ,
93+ data : sourcesWithMinutes ,
5494 isPending,
5595 isEmpty,
5696 isError,
57- } = useGetSources ( )
97+ } = useGetSourcesWithMinutes (
98+ dayjs ( ) . startOf ( 'day' ) . toISOString ( ) ,
99+ dayjs ( ) . endOf ( 'day' ) . toISOString ( ) ,
100+ )
101+
58102 const { exportPulses } = useExportPulses ( )
59103 const [ exportingPulses , setExportingPulses ] = useState ( false )
60104 const [ addSourcesOpen , setAddSourcesOpen ] = useState ( false )
@@ -78,7 +122,7 @@ const Sources = () => {
78122
79123 return (
80124 < >
81- < Card sx = { { boxShadow : 'none' , borderRadius : 0 , minWidth : 262 , flex : 1 } } >
125+ < Card sx = { { boxShadow : 'none' , borderRadius : 0 , minWidth : 335 , flex : 1 } } >
82126 < CardContent sx = { { padding : '24px' , height : '100%' , display : 'flex' } } >
83127 < Stack direction = "column" justifyContent = { 'space-between' } flex = { 1 } >
84128 < div >
@@ -106,9 +150,10 @@ const Sources = () => {
106150 </ Button >
107151 </ Stack >
108152 < Stack direction = "column" marginTop = "24px" gap = { 3 } >
109- { connectedSources . map ( ( source , index ) => {
153+ { sourcesWithMinutes . map ( ( source , index ) => {
110154 const sourceDetails = supportedSources . find (
111- ( supportedSource ) => supportedSource . name === source . name ,
155+ ( supportedSource ) =>
156+ supportedSource . name . includes ( source . name ) ,
112157 )
113158
114159 if ( sourceDetails ) {
@@ -117,6 +162,7 @@ const Sources = () => {
117162 key = { index }
118163 source = { sourceDetails }
119164 lastActive = { source . lastActive }
165+ minutes = { source . minutes }
120166 />
121167 )
122168 }
0 commit comments