@@ -15,7 +15,6 @@ import { Item, ItemField, ItemsList } from "./components/ItemsList";
15
15
import { useWorkspaceSessions } from "./data/insights/list-workspace-sessions-query" ;
16
16
import { WorkspaceSessionGroup } from "./insights/WorkspaceSessionGroup" ;
17
17
import { gitpodHostUrl } from "./service/service" ;
18
- import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from "@podkit/select/Select" ;
19
18
import dayjs from "dayjs" ;
20
19
import { Timestamp } from "@bufbuild/protobuf" ;
21
20
import { LoadingButton } from "@podkit/buttons/LoadingButton" ;
@@ -26,16 +25,11 @@ import { useToast } from "./components/toasts/Toasts";
26
25
import { useTemporaryState } from "./hooks/use-temporary-value" ;
27
26
import { DownloadIcon } from "lucide-react" ;
28
27
import { Button } from "@podkit/buttons/Button" ;
28
+ import { DropdownMenu , DropdownMenuTrigger , DropdownMenuContent , DropdownMenuItem } from "@podkit/dropdown/DropDown" ;
29
+ import { useInstallationConfiguration } from "./data/installation/default-workspace-image-query" ;
29
30
30
31
export const Insights = ( ) => {
31
- const [ prebuildsFilter , setPrebuildsFilter ] = useState < "week" | "month" | "year" > ( "week" ) ;
32
- const [ upperBound , lowerBound ] = useMemo ( ( ) => {
33
- const from = dayjs ( ) . subtract ( 1 , prebuildsFilter ) . startOf ( "day" ) ;
34
-
35
- const fromTimestamp = Timestamp . fromDate ( from . toDate ( ) ) ;
36
- const toTimestamp = Timestamp . fromDate ( new Date ( ) ) ;
37
- return [ fromTimestamp , toTimestamp ] ;
38
- } , [ prebuildsFilter ] ) ;
32
+ const toDate = useMemo ( ( ) => Timestamp . fromDate ( new Date ( ) ) , [ ] ) ;
39
33
const {
40
34
data,
41
35
error : errorMessage ,
@@ -44,9 +38,11 @@ export const Insights = () => {
44
38
hasNextPage,
45
39
fetchNextPage,
46
40
} = useWorkspaceSessions ( {
47
- from : upperBound ,
48
- to : lowerBound ,
41
+ from : Timestamp . fromDate ( new Date ( 0 ) ) ,
42
+ to : toDate ,
49
43
} ) ;
44
+ const { data : installationConfig } = useInstallationConfiguration ( ) ;
45
+ const isDedicatedInstallation = ! ! installationConfig ?. isDedicatedInstallation ;
50
46
51
47
const hasMoreThanOnePage = ( data ?. pages . length ?? 0 ) > 1 ;
52
48
const sessions = useMemo ( ( ) => data ?. pages . flatMap ( ( p ) => p ) ?? [ ] , [ data ] ) ;
@@ -59,21 +55,11 @@ export const Insights = () => {
59
55
< div className = "app-container pt-5 pb-8" >
60
56
< div
61
57
className = { classNames (
62
- "flex flex-col items-start space-y-3 justify-between " ,
58
+ "flex flex-col items-start space-y-3 justify-end " ,
63
59
"md:flex-row md:items-center md:space-x-4 md:space-y-0" ,
64
60
) }
65
61
>
66
- < Select value = { prebuildsFilter } onValueChange = { ( v ) => setPrebuildsFilter ( v as any ) } >
67
- < SelectTrigger className = "w-[180px]" >
68
- < SelectValue placeholder = "Select time range" />
69
- </ SelectTrigger >
70
- < SelectContent >
71
- < SelectItem value = "week" > Last 7 days</ SelectItem >
72
- < SelectItem value = "month" > Last 30 days</ SelectItem >
73
- < SelectItem value = "year" > Last 365 days</ SelectItem >
74
- </ SelectContent >
75
- </ Select >
76
- < DownloadUsage from = { upperBound } to = { lowerBound } />
62
+ < DownloadUsage to = { toDate } />
77
63
</ div >
78
64
79
65
< div
@@ -108,7 +94,7 @@ export const Insights = () => {
108
94
109
95
{ isLoading && (
110
96
< div className = "flex items-center justify-center w-full space-x-2 text-pk-content-primary text-sm pt-16 pb-40" >
111
- < LoadingState />
97
+ < LoadingState delay = { false } />
112
98
< span > Loading usage...</ span >
113
99
</ div >
114
100
) }
@@ -135,7 +121,7 @@ export const Insights = () => {
135
121
{ " " }
136
122
workspaces
137
123
</ a > { " " }
138
- in the last 30 days or checked your other organizations?
124
+ recently { ! isDedicatedInstallation && " or checked your other organizations" } ?
139
125
</ Subheading >
140
126
</ div >
141
127
) }
@@ -164,39 +150,51 @@ export const Insights = () => {
164
150
} ;
165
151
166
152
type DownloadUsageProps = {
167
- from : Timestamp ;
168
153
to : Timestamp ;
169
154
} ;
170
- export const DownloadUsage = ( { from , to } : DownloadUsageProps ) => {
155
+ export const DownloadUsage = ( { to } : DownloadUsageProps ) => {
171
156
const { data : org } = useCurrentOrg ( ) ;
172
157
const { toast } = useToast ( ) ;
173
158
// When we start the download, we disable the button for a short time
174
159
const [ downloadDisabled , setDownloadDisabled ] = useTemporaryState ( false , 1000 ) ;
175
160
176
- const handleDownload = useCallback ( async ( ) => {
177
- if ( ! org ) {
178
- return ;
179
- }
180
-
181
- setDownloadDisabled ( true ) ;
182
- toast (
183
- < DownloadInsightsToast
184
- organizationName = { org ?. slug ?? org ?. id }
185
- organizationId = { org . id }
186
- from = { from }
187
- to = { to }
188
- /> ,
189
- {
190
- autoHide : false ,
191
- } ,
192
- ) ;
193
- } , [ org , setDownloadDisabled , toast , from , to ] ) ;
161
+ const handleDownload = useCallback (
162
+ async ( { daysInPast } : { daysInPast : number } ) => {
163
+ if ( ! org ) {
164
+ return ;
165
+ }
166
+ const from = Timestamp . fromDate ( dayjs ( ) . subtract ( daysInPast , "day" ) . toDate ( ) ) ;
167
+
168
+ setDownloadDisabled ( true ) ;
169
+ toast (
170
+ < DownloadInsightsToast
171
+ organizationName = { org ?. slug ?? org ?. id }
172
+ organizationId = { org . id }
173
+ from = { from }
174
+ to = { to }
175
+ /> ,
176
+ {
177
+ autoHide : false ,
178
+ } ,
179
+ ) ;
180
+ } ,
181
+ [ org , setDownloadDisabled , to , toast ] ,
182
+ ) ;
194
183
195
184
return (
196
- < Button variant = "secondary" onClick = { handleDownload } className = "gap-1" disabled = { downloadDisabled } >
197
- < DownloadIcon strokeWidth = { 3 } className = "w-4" />
198
- < span > Export as CSV</ span >
199
- </ Button >
185
+ < DropdownMenu >
186
+ < DropdownMenuTrigger asChild >
187
+ < Button variant = "secondary" className = "gap-1" disabled = { downloadDisabled } >
188
+ < DownloadIcon strokeWidth = { 3 } className = "w-4" />
189
+ < span > Export as CSV</ span >
190
+ </ Button >
191
+ </ DropdownMenuTrigger >
192
+ < DropdownMenuContent >
193
+ < DropdownMenuItem onClick = { ( ) => handleDownload ( { daysInPast : 7 } ) } > Last 7 days</ DropdownMenuItem >
194
+ < DropdownMenuItem onClick = { ( ) => handleDownload ( { daysInPast : 30 } ) } > Last 30 days</ DropdownMenuItem >
195
+ < DropdownMenuItem onClick = { ( ) => handleDownload ( { daysInPast : 365 } ) } > Last 365 days</ DropdownMenuItem >
196
+ </ DropdownMenuContent >
197
+ </ DropdownMenu >
200
198
) ;
201
199
} ;
202
200
0 commit comments