format files

This commit is contained in:
Hristo Nedelkov 2023-09-29 13:34:59 +03:00
parent c44e39539e
commit eab4eb221e
9 changed files with 48 additions and 51 deletions

View File

@ -20,14 +20,13 @@ type DeviceCPULoadProps = {
load: number[] load: number[]
} }
const DeviceCPULoad = ({ load }: DeviceCPULoadProps) => { const DeviceCPULoad = ({ load }: DeviceCPULoadProps) => {
const [isHovered, setIsHovered] = useState(false); const [isHovered, setIsHovered] = useState(false)
const dataObj = load.map((yValue, index: number) => ({ const dataObj = load.map((yValue, index: number) => ({
x: index + 1, x: index + 1,
y: yValue, y: yValue,
})) }))
const currentLoad = const currentLoad = dataObj.length > 0 ? dataObj[dataObj.length - 1].y : 0
dataObj.length > 0 ? dataObj[dataObj.length - 1].y : 0
const message = currentLoad < 80 ? 'Good' : 'Poor' const message = currentLoad < 80 ? 'Good' : 'Poor'
@ -47,7 +46,7 @@ const DeviceCPULoad = ({ load }: DeviceCPULoadProps) => {
minHeight: '135px', minHeight: '135px',
borderRadius: '16px', borderRadius: '16px',
border: message === 'Poor' ? '1px solid #D92344' : '1px solid #E0E0E0', border: message === 'Poor' ? '1px solid #D92344' : '1px solid #E0E0E0',
backgroundColor: isHovered ? '#f8f6ff' : (message === 'Poor' ? '#fefafa' : '#fff'), backgroundColor: isHovered ? '#f8f6ff' : message === 'Poor' ? '#fefafa' : '#fff',
}} }}
onMouseEnter={() => setIsHovered(true)} onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)} onMouseLeave={() => setIsHovered(false)}

View File

@ -23,15 +23,13 @@ type DeviceMemoryHealthProps = {
maxMemory: number maxMemory: number
} }
const DeviceMemoryHealth = ({ currentMemory, maxMemory }: DeviceMemoryHealthProps) => { const DeviceMemoryHealth = ({ currentMemory, maxMemory }: DeviceMemoryHealthProps) => {
const [isHovered, setIsHovered] = useState(false); const [isHovered, setIsHovered] = useState(false)
const dataObj = currentMemory.map((yValue, index: number) => ({ const dataObj = currentMemory.map((yValue, index: number) => ({
x: index + 1, x: index + 1,
y: yValue, y: yValue,
})) }))
const currentLoad = const currentLoad = dataObj.length > 0 ? dataObj[dataObj.length - 1].y : 0
dataObj.length > 0 ? dataObj[dataObj.length - 1].y : 0
const message = currentLoad < maxMemory ? 'Good' : 'Poor' const message = currentLoad < maxMemory ? 'Good' : 'Poor'
@ -52,7 +50,7 @@ const DeviceMemoryHealth = ({ currentMemory, maxMemory }: DeviceMemoryHealthProp
minHeight: '135px', minHeight: '135px',
borderRadius: '16px', borderRadius: '16px',
border: message === 'Poor' ? '1px solid #D92344' : '1px solid #E0E0E0', border: message === 'Poor' ? '1px solid #D92344' : '1px solid #E0E0E0',
backgroundColor: isHovered ? '#f8f6ff' : (message === 'Poor' ? '#fefafa' : '#fff'), backgroundColor: isHovered ? '#f8f6ff' : message === 'Poor' ? '#fefafa' : '#fff',
}} }}
onMouseEnter={() => setIsHovered(true)} onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)} onMouseLeave={() => setIsHovered(false)}

View File

@ -16,18 +16,18 @@ type Story = StoryObj<typeof meta>
export const GoodStats: Story = { export const GoodStats: Story = {
args: { args: {
latency:[55, 31, 5, 14, 20, 81, 50, 34, 12, 50, 4, 90, 56, 35, 59] latency: [55, 31, 5, 14, 20, 81, 50, 34, 12, 50, 4, 90, 56, 35, 59],
}, },
} }
export const BadStats: Story = { export const BadStats: Story = {
args: { args: {
latency:[55, 31, 5, 14, 20, 81, 50, 34, 12, 50, 4, 90, 56, 35, ] latency: [55, 31, 5, 14, 20, 81, 50, 34, 12, 50, 4, 90, 56, 35],
}, },
} }
export const NoStats: Story = { export const NoStats: Story = {
args: { args: {
latency:[] latency: [],
}, },
} }

View File

@ -16,21 +16,21 @@ type ChartData = {
data: DataPoint[] data: DataPoint[]
} }
type DeviceNetworkHealthProps = { type DeviceNetworkHealthProps = {
latency: number[]; latency: number[]
}; }
const DeviceNetworkHealth = ({ latency }: DeviceNetworkHealthProps) => { const DeviceNetworkHealth = ({ latency }: DeviceNetworkHealthProps) => {
const [isHovered, setIsHovered] = useState(false); const [isHovered, setIsHovered] = useState(false)
const THRESHOLD = 60; const THRESHOLD = 60
const GOOD_COLOR = '#8DC6BC'; const GOOD_COLOR = '#8DC6BC'
const POOR_COLOR_LATENCY = '#D92344'; const POOR_COLOR_LATENCY = '#D92344'
const processLatency = (latency: number[], id: string) => { const processLatency = (latency: number[], id: string) => {
const dataObj = latency.map((yValue, index: number) => ({ x: index + 1, y: yValue })); const dataObj = latency.map((yValue, index: number) => ({ x: index + 1, y: yValue }))
const currentLatency = dataObj.length > 0 ? dataObj[dataObj.length - 1].y : 0; const currentLatency = dataObj.length > 0 ? dataObj[dataObj.length - 1].y : 0
const message = currentLatency < THRESHOLD ? 'Good' : 'Poor'; const message = currentLatency < THRESHOLD ? 'Good' : 'Poor'
const color = message === 'Good' ? GOOD_COLOR : POOR_COLOR_LATENCY; const color = message === 'Good' ? GOOD_COLOR : POOR_COLOR_LATENCY
return { return {
id, id,
@ -38,12 +38,12 @@ const DeviceNetworkHealth = ({ latency }: DeviceNetworkHealthProps) => {
data: dataObj, data: dataObj,
currentLatency, currentLatency,
message, message,
}; }
}; }
const processedLatency = processLatency(latency, 'latency'); const processedLatency = processLatency(latency, 'latency')
const chartData: ChartData[] = [processedLatency]; const chartData: ChartData[] = [processedLatency]
return ( return (
<ShadowBox <ShadowBox
@ -53,7 +53,11 @@ const DeviceNetworkHealth = ({ latency }: DeviceNetworkHealthProps) => {
minHeight: '135px', minHeight: '135px',
borderRadius: '16px', borderRadius: '16px',
border: processedLatency.message === 'Poor' ? '1px solid #D92344' : '1px solid #E0E0E0', border: processedLatency.message === 'Poor' ? '1px solid #D92344' : '1px solid #E0E0E0',
backgroundColor: isHovered ? '#f8f6ff' : (processedLatency.message === 'Poor' ? '#fefafa' : '#fff'), backgroundColor: isHovered
? '#f8f6ff'
: processedLatency.message === 'Poor'
? '#fefafa'
: '#fff',
}} }}
onMouseEnter={() => setIsHovered(true)} onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)} onMouseLeave={() => setIsHovered(false)}
@ -81,7 +85,13 @@ const DeviceNetworkHealth = ({ latency }: DeviceNetworkHealthProps) => {
<Separator borderColor={'#e3e3e3'} /> <Separator borderColor={'#e3e3e3'} />
<XStack space={'$4'} style={{ padding: '0.65rem 1rem' }}> <XStack space={'$4'} style={{ padding: '0.65rem 1rem' }}>
<IconText <IconText
icon={processedLatency.message === 'Good' ? <CheckCircleIcon size={16} /> : <IncorrectIcon size={16} />} icon={
processedLatency.message === 'Good' ? (
<CheckCircleIcon size={16} />
) : (
<IncorrectIcon size={16} />
)
}
weight={'semibold'} weight={'semibold'}
> >
{processedLatency.message} {processedLatency.message}
@ -93,7 +103,7 @@ const DeviceNetworkHealth = ({ latency }: DeviceNetworkHealthProps) => {
)} )}
</XStack> </XStack>
</YStack> </YStack>
</ShadowBox > </ShadowBox>
) )
} }

View File

@ -9,15 +9,15 @@ interface DeviceStorageHealthProps {
storage: number storage: number
maxStorage: number maxStorage: number
} }
const GOOD_COLOR = '#8DC6BC'; const GOOD_COLOR = '#8DC6BC'
const POOR_COLOR = '#E95460'; const POOR_COLOR = '#E95460'
const DeviceStorageHealth = ({ storage, maxStorage }: DeviceStorageHealthProps) => { const DeviceStorageHealth = ({ storage, maxStorage }: DeviceStorageHealthProps) => {
const [isHovered, setIsHovered] = useState(false); const [isHovered, setIsHovered] = useState(false)
const message = storage < maxStorage ? 'Good' : 'Poor'; const message = storage < maxStorage ? 'Good' : 'Poor'
const free = maxStorage - storage; const free = maxStorage - storage
const utilization = (storage / (maxStorage || 1)) * 100; const utilization = (storage / (maxStorage || 1)) * 100
const data = (free: number) => { const data = (free: number) => {
return [ return [
@ -33,7 +33,7 @@ const DeviceStorageHealth = ({ storage, maxStorage }: DeviceStorageHealthProps)
value: free, value: free,
color: '#E7EAEE', color: '#E7EAEE',
}, },
]; ]
} }
return ( return (
<Shadow <Shadow
@ -43,7 +43,7 @@ const DeviceStorageHealth = ({ storage, maxStorage }: DeviceStorageHealthProps)
minHeight: '135px', minHeight: '135px',
borderRadius: '16px', borderRadius: '16px',
border: message === 'Poor' ? '1px solid #D92344' : '1px solid #E0E0E0', border: message === 'Poor' ? '1px solid #D92344' : '1px solid #E0E0E0',
backgroundColor: isHovered ? '#f8f6ff' : (message === 'Poor' ? '#fefafa' : '#fff'), backgroundColor: isHovered ? '#f8f6ff' : message === 'Poor' ? '#fefafa' : '#fff',
}} }}
onMouseEnter={() => setIsHovered(true)} onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)} onMouseLeave={() => setIsHovered(false)}
@ -64,7 +64,7 @@ const DeviceStorageHealth = ({ storage, maxStorage }: DeviceStorageHealthProps)
height: '4.75rem', height: '4.75rem',
}} }}
> >
<StandardGauge data={data(free)} isInteractive={false}/> <StandardGauge data={data(free)} isInteractive={false} />
</Stack> </Stack>
<YStack space={'$3'}> <YStack space={'$3'}>
<Text size={15} weight={'semibold'}> <Text size={15} weight={'semibold'}>

View File

@ -31,7 +31,6 @@ const StandartLineChart = ({ data, isInteractive }: StandartLineChartProps) => {
stacked: true, stacked: true,
reverse: false, reverse: false,
}} }}
axisTop={null} axisTop={null}
axisRight={null} axisRight={null}
axisBottom={null} axisBottom={null}

View File

@ -45,10 +45,7 @@ const DeviceHealthCheck = () => {
currentMemory={deviceHealthState.memory} currentMemory={deviceHealthState.memory}
maxMemory={deviceHealthState.maxMemory} maxMemory={deviceHealthState.maxMemory}
/> />
<DeviceNetworkHealth <DeviceNetworkHealth latency={deviceHealthState.latency} />
latency={deviceHealthState.latency}
/>
</XStack> </XStack>
<HealthInfoSection <HealthInfoSection
usedStorage={120} usedStorage={120}

View File

@ -33,7 +33,7 @@ const GenerateId = ({ isAwaitingPairing }: GenerateIdProps) => {
icon={<CompleteIdIcon size={20} />} icon={<CompleteIdIcon size={20} />}
onPress={generateIdHandler} onPress={generateIdHandler}
> >
Regenerate ID Regenerate ID
</Button> </Button>
</XStack> </XStack>
<YStack space={'$2'}> <YStack space={'$2'}>

View File

@ -7,7 +7,6 @@ interface DeviceHealthState {
memory: number[] memory: number[]
maxMemory: number maxMemory: number
latency: number[] latency: number[]
} }
const initialState: DeviceHealthState = { const initialState: DeviceHealthState = {
@ -17,7 +16,6 @@ const initialState: DeviceHealthState = {
memory: [15, 31, 5, 14, 20, 81, 50, 34, 12, 123, 4, 90, 56, 35, 90], memory: [15, 31, 5, 14, 20, 81, 50, 34, 12, 123, 4, 90, 56, 35, 90],
maxMemory: 120, maxMemory: 120,
latency: [55, 31, 5, 14, 20, 81, 50, 34, 12, 50, 4, 90, 56, 35, 59], latency: [55, 31, 5, 14, 20, 81, 50, 34, 12, 50, 4, 90, 56, 35, 59],
} }
const deviceHealthSlice = createSlice({ const deviceHealthSlice = createSlice({
@ -41,12 +39,8 @@ const deviceHealthSlice = createSlice({
state.memory = action.payload.memory state.memory = action.payload.memory
state.maxMemory = action.payload.maxMemory state.maxMemory = action.payload.maxMemory
}, },
setNetworkHealth: ( setNetworkHealth: (state: DeviceHealthState, action: PayloadAction<{ latency: number[] }>) => {
state: DeviceHealthState,
action: PayloadAction<{ latency: number[] }>,
) => {
state.latency = action.payload.latency state.latency = action.payload.latency
}, },
}, },
}) })