Skip to content

Commit 7f5982b

Browse files
committed
refactor: clean up and format components
1 parent 0c01e97 commit 7f5982b

File tree

3 files changed

+31
-42
lines changed

3 files changed

+31
-42
lines changed

thingconnect.pulse.client/src/components/common/ComboboxSelect.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ type Option = {
77
value: string;
88
};
99

10-
export interface ComboboxProps extends Omit<ComponentProps<typeof Combobox.Root>, 'onChange' | 'children' | 'value' | 'collection'
11-
> {
10+
export interface ComboboxProps
11+
extends Omit<
12+
ComponentProps<typeof Combobox.Root>,
13+
'onChange' | 'children' | 'value' | 'collection'
14+
> {
1215
items: Option[];
1316
selectedValue?: string;
1417
onChange: (value: string) => void;
@@ -26,11 +29,8 @@ export function ComboboxSelect({
2629
defaultToFirst = false,
2730
...rest
2831
}: ComboboxProps) {
29-
30-
const itemsWithAll = useMemo(() => {
31-
return items.length > 0 && !defaultToFirst
32-
? [{ label: 'All', value: '' }, ...items]
33-
: items;
32+
const itemsWithAll = useMemo(() => {
33+
return items.length > 0 && !defaultToFirst ? [{ label: 'All', value: '' }, ...items] : items;
3434
}, [items, defaultToFirst]);
3535

3636
const { contains } = useFilter({ sensitivity: 'base' });
@@ -70,11 +70,9 @@ export function ComboboxSelect({
7070
{...rest}
7171
>
7272
<Combobox.Control>
73-
<Combobox.Input
74-
placeholder={placeholder || 'Select an option'}
75-
value={
76-
collection.items.find((item) => item.value === selectedValue)?.label || ''
77-
}
73+
<Combobox.Input
74+
placeholder={placeholder || 'Select an option'}
75+
value={collection.items.find(item => item.value === selectedValue)?.label || ''}
7876
/>
7977
<Combobox.IndicatorGroup>
8078
<Combobox.ClearTrigger
@@ -111,4 +109,4 @@ export function ComboboxSelect({
111109
</Combobox.Root>
112110
</Skeleton>
113111
);
114-
}
112+
}

thingconnect.pulse.client/src/components/common/EndpointSelect.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,20 @@ export function EndpointSelect({
1414
placeholder = 'Select endpoint...',
1515
setName,
1616
defaultToFirst = false,
17-
...rest
17+
...rest
1818
}: EndpointSelectProps) {
19-
2019
// Live endpoints
21-
const {
22-
data: liveData,
23-
isLoading,
24-
} = useQuery({
20+
const { data: liveData, isLoading } = useQuery({
2521
queryKey: ['live-status'],
2622
queryFn: () => StatusService.getLiveStatus({ pageSize: 100 }),
2723
staleTime: 30000,
2824
});
2925

3026
const selectedEndpointName = useMemo(() => {
31-
return liveData?.items?.find(item => item.endpoint.id === selectedValue)?.endpoint?.name || 'Unknown Endpoint';
27+
return (
28+
liveData?.items?.find(item => item.endpoint.id === selectedValue)?.endpoint?.name ||
29+
'Unknown Endpoint'
30+
);
3231
}, [liveData, selectedValue]);
3332

3433
useEffect(() => {
@@ -39,10 +38,12 @@ export function EndpointSelect({
3938

4039
return (
4140
<ComboboxSelect
42-
items={liveData?.items.map(item => ({
43-
label: item.endpoint.name,
44-
value: item.endpoint.id,
45-
})) || []}
41+
items={
42+
liveData?.items.map(item => ({
43+
label: item.endpoint.name,
44+
value: item.endpoint.id,
45+
})) || []
46+
}
4647
selectedValue={selectedValue}
4748
onChange={onChange}
4849
isLoading={isLoading}
@@ -51,4 +52,4 @@ export function EndpointSelect({
5152
{...rest}
5253
/>
5354
);
54-
}
55+
}

thingconnect.pulse.client/src/pages/History.tsx

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,7 @@ import { useState, useEffect } from 'react';
22
import { useSearchParams } from 'react-router-dom';
33
import { useAnalytics } from '@/hooks/useAnalytics';
44
import { useQuery } from '@tanstack/react-query';
5-
import {
6-
Text,
7-
HStack,
8-
Button,
9-
Card,
10-
IconButton,
11-
VStack,
12-
Tabs,
13-
} from '@chakra-ui/react';
5+
import { Text, HStack, Button, Card, IconButton, VStack, Tabs } from '@chakra-ui/react';
146
import { Download, TrendingUp, AlertCircle, RefreshCw } from 'lucide-react';
157
import { Page } from '@/components/layout/Page';
168
import { PageSection } from '@/components/layout/PageSection';
@@ -25,7 +17,6 @@ import { HistoryService } from '@/api/services/history.service';
2517
import { Tooltip } from '@/components/ui/tooltip';
2618
import { AvailabilityStats } from '@/components/AvailabilityStats';
2719
import { EndpointSelect } from '@/components/common/EndpointSelect';
28-
// import { EndpointCombobox } from '@/components/common/ComboboxSelect';
2920

3021
export default function History() {
3122
const analytics = useAnalytics();
@@ -50,8 +41,11 @@ export default function History() {
5041
analytics.trackPageView('History', {
5142
view_type: 'history_analysis',
5243
has_endpoint_filter: !!selectedEndpoint,
53-
date_range_days: Math.ceil((new Date(dateRange.to).getTime() - new Date(dateRange.from).getTime()) / (1000 * 60 * 60 * 24)),
54-
bucket_granularity: bucket
44+
date_range_days: Math.ceil(
45+
(new Date(dateRange.to).getTime() - new Date(dateRange.from).getTime()) /
46+
(1000 * 60 * 60 * 24)
47+
),
48+
bucket_granularity: bucket,
5549
});
5650
}, []);
5751

@@ -176,11 +170,7 @@ export default function History() {
176170
</PageSection>
177171
{/* History Data */}
178172
<PageSection title='Performance Summary' testId='availability-stats'>
179-
<AvailabilityStats
180-
data={historyData}
181-
bucket={bucket}
182-
isLoading={isHistoryDataLoading }
183-
/>
173+
<AvailabilityStats data={historyData} bucket={bucket} isLoading={isHistoryDataLoading} />
184174
</PageSection>
185175
<Tabs.Root
186176
defaultValue='chart'

0 commit comments

Comments
 (0)