1
+ import { useState } from "react" ;
2
+
1
3
import { type JobSummary } from "@squonk/data-manager-client" ;
2
4
3
- import { Alert , Chip , LinearProgress , Link , Typography } from "@mui/material" ;
5
+ import { Alert , Chip , LinearProgress , Link , MenuItem , TextField , Typography } from "@mui/material" ;
4
6
import dynamic from "next/dynamic" ;
7
+ import semver from "semver" ;
5
8
6
9
import { BaseCard } from "../../BaseCard" ;
7
10
import { Chips } from "../../Chips" ;
8
11
import { type InstancesListProps } from "../InstancesList" ;
9
12
import { RunJobButton , type RunJobButtonProps } from "./RunJobButton" ;
10
13
14
+ const compareJobs = ( a : JobSummary , b : JobSummary ) => {
15
+ return - semver . compare ( a . version , b . version ) ;
16
+ } ;
17
+
18
+
11
19
const InstancesList = dynamic < InstancesListProps > (
12
20
( ) => import ( "../InstancesList" ) . then ( ( mod ) => mod . InstancesList ) ,
13
21
{ loading : ( ) => < LinearProgress /> } ,
14
22
) ;
15
23
16
24
export interface ApplicationCardProps extends Pick < RunJobButtonProps , "projectId" > {
17
25
/**
18
- * the job to be instantiated
26
+ * the list of jobs (different versions) to be instantiated
19
27
*/
20
- job : JobSummary ;
28
+ job : JobSummary [ ] ;
21
29
/**
22
30
* Whether to disable the button
23
31
*/
@@ -28,16 +36,37 @@ export interface ApplicationCardProps extends Pick<RunJobButtonProps, "projectId
28
36
* MuiCard that displays a summary of a job with actions to create new instances and view
29
37
* existing instances.
30
38
*/
31
- export const JobCard = ( { projectId, job, disabled = false } : ApplicationCardProps ) => {
39
+ export const JobCard = ( { projectId, job : jobs , disabled = false } : ApplicationCardProps ) => {
40
+ jobs . sort ( compareJobs ) ;
41
+ const [ selectedJobId , setSelectedJobId ] = useState ( jobs [ 0 ] ?. id || "" ) ;
42
+ const job = jobs . find ( j => j . id === selectedJobId ) as JobSummary ;
43
+
32
44
return (
33
45
< BaseCard
34
46
actions = { ( { setExpanded } ) => (
35
- < RunJobButton
36
- disabled = { job . disabled || disabled }
37
- jobId = { job . id }
38
- projectId = { projectId }
39
- onLaunch = { ( ) => setExpanded ( true ) }
40
- />
47
+ < >
48
+ < TextField
49
+ select
50
+ disabled = { jobs . length === 1 }
51
+ label = "Version"
52
+ size = "small"
53
+ sx = { { minWidth : 120 } }
54
+ value = { selectedJobId }
55
+ onChange = { ( e ) => setSelectedJobId ( e . target . value ) }
56
+ >
57
+ { jobs . map ( ( jobVersion ) => (
58
+ < MenuItem key = { jobVersion . id } value = { jobVersion . id } >
59
+ { jobVersion . version }
60
+ </ MenuItem >
61
+ ) ) }
62
+ </ TextField >
63
+ < RunJobButton
64
+ disabled = { job . disabled || disabled }
65
+ jobId = { job . id }
66
+ projectId = { projectId }
67
+ onLaunch = { ( ) => setExpanded ( true ) }
68
+ />
69
+ </ >
41
70
) }
42
71
collapsed = {
43
72
< InstancesList
0 commit comments