@@ -54,25 +54,57 @@ export default function Home(): React.JSX.Element {
5454 queryFn : ( ) =>
5555 fetch ( `${ siteConfig . url } /api/deployments` ) . then ( async ( response ) => {
5656 const resp = await utils . unwrapJson ( response ) ;
57- if ( Array . isArray ( resp ) ) {
58- resp . length = 5 ;
59- }
60- return resp ;
57+ return Array . isArray ( resp ) ? resp . slice ( 0 , 5 ) : [ ] ;
6158 } ) ,
6259 refetchInterval : 60 * 1000 ,
6360 } ) ;
6461
65- const versionMetadataKeys = deploymentsQuery . data ?. reduce (
66- ( acc , deployment ) => {
67- for ( const key of Object . keys ( deployment . versionMetadata ) ) {
68- acc . add ( key ) ;
62+ const preferredOrder = [
63+ 'commitHash' ,
64+ 'version' ,
65+ 'libVersion' ,
66+ 'libSourceVersion' ,
67+ 'libStateVersion' ,
68+ 'libNetworkVersion' ,
69+ ] ;
70+
71+ const versionMetadataLabels : Record < string , string > = {
72+ version : 'Version' ,
73+ commitHash : 'Commit' ,
74+ libVersion : 'LibVersion' ,
75+ libStateVersion : 'StVer' ,
76+ libSourceVersion : 'LibSrcVer' ,
77+ libNetworkVersion : 'Net' ,
78+ } ;
79+
80+ function formatLocalDateTime ( ms : number ) : string {
81+ return new Date ( ms ) . toLocaleString ( undefined , {
82+ year : 'numeric' ,
83+ month : '2-digit' ,
84+ day : '2-digit' ,
85+ hour : '2-digit' ,
86+ minute : '2-digit' ,
87+ second : '2-digit' ,
88+ } ) ;
89+ }
90+
91+ const versionMetadataKeysSorted = React . useMemo ( ( ) => {
92+ if ( ! Array . isArray ( deploymentsQuery . data ) ) return [ ] ;
93+
94+ const keySet = new Set < string > ( ) ;
95+ for ( const deployment of deploymentsQuery . data ) {
96+ if (
97+ deployment &&
98+ typeof deployment . versionMetadata === 'object' &&
99+ deployment . versionMetadata != null
100+ ) {
101+ for ( const key of Object . keys ( deployment . versionMetadata ) ) {
102+ keySet . add ( key ) ;
103+ }
69104 }
70- return acc ;
71- } ,
72- new Set < string > ( ) ,
73- ) ;
74- const versionMetadataKeysSorted =
75- versionMetadataKeys != null ? [ ...versionMetadataKeys ] . sort ( ) : undefined ;
105+ }
106+ return Array . from ( keySet ) . sort ( ) ;
107+ } , [ deploymentsQuery . data ] ) ;
76108 return (
77109 < Layout
78110 description = "Polykey, a new approach to secrets management."
@@ -142,17 +174,19 @@ export default function Home(): React.JSX.Element {
142174 ) }
143175 < div className = "rounded-2xl bg-[#E4F6F2] p-3" >
144176 < span className = "font-semibold" > Deployments:</ span >
145- < table className = "mt-3 w-full" >
146- < tbody className = "table w-full" >
177+ < table className = "mt-3 w-full table-auto " >
178+ < thead >
147179 < tr >
148180 < th > ID</ th >
149- { ( versionMetadataKeysSorted ?? [ ] ) . map ( ( key ) => (
150- < th key = { key } > { key } </ th >
181+ { preferredOrder . map ( ( key ) => (
182+ < th key = { key } > { versionMetadataLabels [ key ] ?? key } </ th >
151183 ) ) }
152184 < th > Started On</ th >
153185 < th > Finished On</ th >
154186 < th > Progress</ th >
155187 </ tr >
188+ </ thead >
189+ < tbody >
156190 { deploymentsQuery . isLoading ? (
157191 < tr >
158192 < td align = "center" colSpan = { 5 } >
@@ -174,7 +208,7 @@ export default function Home(): React.JSX.Element {
174208 return (
175209 < tr key = { deployment . id } >
176210 < td > { deployment . id } </ td >
177- { ( versionMetadataKeysSorted ?? [ ] ) . map ( ( key ) => {
211+ { preferredOrder . map ( ( key ) => {
178212 const value = deployment . versionMetadata [ key ] ;
179213 if ( value == null ) {
180214 return < td key = { key } > </ td > ;
@@ -195,11 +229,11 @@ export default function Home(): React.JSX.Element {
195229 return < td key = { key } > { value } </ td > ;
196230 }
197231 } ) }
198- < td > { new Date ( deployment . startedOn ) . toISOString ( ) } </ td >
232+ < td > { formatLocalDateTime ( deployment . startedOn ) } </ td >
199233 < td >
200- { deployment . finishedOn == null
201- ? ''
202- : new Date ( deployment . finishedOn ) . toISOString ( ) }
234+ { deployment . finishedOn
235+ ? formatLocalDateTime ( deployment . finishedOn )
236+ : '' }
203237 </ td >
204238 < td className = "text-center" >
205239 < div className = "relative inline-flex items-center justify-center overflow-hidden rounded-full" >
0 commit comments