@@ -28,6 +28,8 @@ import { cn } from "~/utils/cn";
2828import { Button } from "../../primitives/Buttons" ;
2929import { filterIcon } from "./RunFilters" ;
3030import { Paragraph } from "~/components/primitives/Paragraph" ;
31+ import { ShortcutDefinition } from "~/hooks/useShortcutKeys" ;
32+ import { SpanPresenter } from "~/presenters/v3/SpanPresenter.server" ;
3133
3234export type DisplayableEnvironment = Pick < RuntimeEnvironment , "type" | "id" > & {
3335 userName ?: string ;
@@ -140,11 +142,13 @@ export const timeFilters = ({
140142 from,
141143 to,
142144 defaultPeriod = DEFAULT_PERIOD ,
145+ labelName = "Created" ,
143146} : {
144147 period ?: string ;
145148 from ?: string | number ;
146149 to ?: string | number ;
147150 defaultPeriod ?: string ;
151+ labelName ?: string ;
148152} ) : {
149153 period ?: string ;
150154 from ?: Date ;
@@ -155,7 +159,11 @@ export const timeFilters = ({
155159 valueLabel : ReactNode ;
156160} => {
157161 if ( period ) {
158- return { period, isDefault : period === defaultPeriod , ...timeFilterRenderValues ( { period } ) } ;
162+ return {
163+ period,
164+ isDefault : period === defaultPeriod ,
165+ ...timeFilterRenderValues ( { period, labelName } ) ,
166+ } ;
159167 }
160168
161169 if ( from && to ) {
@@ -165,7 +173,7 @@ export const timeFilters = ({
165173 from : fromDate ,
166174 to : toDate ,
167175 isDefault : false ,
168- ...timeFilterRenderValues ( { from : fromDate , to : toDate } ) ,
176+ ...timeFilterRenderValues ( { from : fromDate , to : toDate , labelName } ) ,
169177 } ;
170178 }
171179
@@ -175,7 +183,7 @@ export const timeFilters = ({
175183 return {
176184 from : fromDate ,
177185 isDefault : false ,
178- ...timeFilterRenderValues ( { from : fromDate } ) ,
186+ ...timeFilterRenderValues ( { from : fromDate , labelName } ) ,
179187 } ;
180188 }
181189
@@ -185,14 +193,14 @@ export const timeFilters = ({
185193 return {
186194 to : toDate ,
187195 isDefault : false ,
188- ...timeFilterRenderValues ( { to : toDate } ) ,
196+ ...timeFilterRenderValues ( { to : toDate , labelName } ) ,
189197 } ;
190198 }
191199
192200 return {
193201 period : defaultPeriod ,
194202 isDefault : true ,
195- ...timeFilterRenderValues ( { period : defaultPeriod } ) ,
203+ ...timeFilterRenderValues ( { period : defaultPeriod , labelName } ) ,
196204 } ;
197205} ;
198206
@@ -201,11 +209,13 @@ export function timeFilterRenderValues({
201209 to,
202210 period,
203211 defaultPeriod = DEFAULT_PERIOD ,
212+ labelName = "Created" ,
204213} : {
205214 from ?: Date ;
206215 to ?: Date ;
207216 period ?: string ;
208217 defaultPeriod ?: string ;
218+ labelName ?: string ;
209219} ) {
210220 const rangeType : TimeRangeType = from && to ? "range" : from ? "from" : to ? "to" : "period" ;
211221
@@ -252,26 +262,30 @@ export function timeFilterRenderValues({
252262
253263 let label =
254264 rangeType === "range" || rangeType === "period"
255- ? "Created"
265+ ? labelName
256266 : rangeType === "from"
257- ? "Created after"
258- : "Created before" ;
267+ ? ` ${ labelName } after`
268+ : ` ${ labelName } before` ;
259269
260270 return { label, valueLabel, rangeType } ;
261271}
262272
263273export interface TimeFilterProps {
264274 defaultPeriod ?: string ;
275+ /** Label name used in the filter display, defaults to "Created" */
276+ labelName ?: string ;
277+ applyShortcut ?: ShortcutDefinition | undefined ;
265278}
266279
267- export function TimeFilter ( { defaultPeriod } : TimeFilterProps = { } ) {
280+ export function TimeFilter ( { defaultPeriod, labelName = "Created" , applyShortcut } : TimeFilterProps = { } ) {
268281 const { value, del } = useSearchParams ( ) ;
269282
270283 const { period, from, to, label, valueLabel } = timeFilters ( {
271284 period : value ( "period" ) ,
272285 from : value ( "from" ) ,
273286 to : value ( "to" ) ,
274287 defaultPeriod,
288+ labelName,
275289 } ) ;
276290
277291 return (
@@ -293,6 +307,8 @@ export function TimeFilter({ defaultPeriod }: TimeFilterProps = {}) {
293307 from = { from }
294308 to = { to }
295309 defaultPeriod = { defaultPeriod }
310+ labelName = { labelName }
311+ applyShortcut = { applyShortcut }
296312 />
297313 ) }
298314 </ FilterMenuProvider >
@@ -316,12 +332,16 @@ export function TimeDropdown({
316332 from,
317333 to,
318334 defaultPeriod = DEFAULT_PERIOD ,
335+ labelName = "Created" ,
336+ applyShortcut,
319337} : {
320338 trigger : ReactNode ;
321339 period ?: string ;
322340 from ?: Date ;
323341 to ?: Date ;
324342 defaultPeriod ?: string ;
343+ labelName ?: string ;
344+ applyShortcut ?: ShortcutDefinition | undefined ;
325345} ) {
326346 const [ open , setOpen ] = useState < boolean | undefined > ( ) ;
327347 const { replace } = useSearchParams ( ) ;
@@ -449,7 +469,7 @@ export function TimeDropdown({
449469 activeSection === "duration" && "text-indigo-500"
450470 ) }
451471 >
452- Runs created in the last
472+ { labelName } in the last
453473 </ Label >
454474 < div className = "grid grid-cols-4 gap-2" >
455475 { /* Custom duration row */ }
@@ -751,7 +771,7 @@ export function TimeDropdown({
751771 </ Button >
752772 < Button
753773 variant = "primary/small"
754- shortcut = { {
774+ shortcut = { applyShortcut ? applyShortcut : {
755775 modifiers : [ "mod" ] ,
756776 key : "Enter" ,
757777 enabledOnInputElements : true ,
0 commit comments