-
Notifications
You must be signed in to change notification settings - Fork 295
/
RunInfo.tsx
97 lines (84 loc) · 2.25 KB
/
RunInfo.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2018-2023 contributors to the Marquez project
// SPDX-License-Identifier: Apache-2.0
import * as Redux from 'redux'
import { Box } from '@mui/material'
import { IState } from '../../store/reducers'
import { Run } from '../../types/api'
import { connect } from 'react-redux'
import { fetchJobFacets, resetFacets } from '../../store/actionCreators'
import MqCode from '../core/code/MqCode'
import MqJsonView from '../core/json-view/MqJsonView'
import MqText from '../core/text/MqText'
import React, { FunctionComponent, useEffect } from 'react'
export interface DispatchProps {
fetchJobFacets: typeof fetchJobFacets
resetFacets: typeof resetFacets
}
interface JobFacets {
[key: string]: object
}
export interface JobFacetsProps {
jobFacets: JobFacets
}
export interface SqlFacet {
query: string
}
export interface SourceCodeFacet {
language: string
sourceCode: string
_producer: string
_schemaURL: string
}
type RunInfoProps = {
run: Run
} & JobFacetsProps &
DispatchProps
const RunInfo: FunctionComponent<RunInfoProps> = (props) => {
const { run, jobFacets, fetchJobFacets, resetFacets } = props
const i18next = require('i18next')
useEffect(() => {
fetchJobFacets(run.id)
}, [])
// unmounting
useEffect(
() => () => {
resetFacets()
},
[]
)
return (
<Box>
{<MqCode code={(jobFacets?.sql as SqlFacet)?.query} language={'sql'} />}
{
<MqCode
code={(jobFacets.sourceCode as SourceCodeFacet)?.sourceCode}
language={(jobFacets.sourceCode as SourceCodeFacet)?.language}
/>
}
{run.facets && (
<Box mt={2}>
<Box mb={1}>
<MqText subheading>{i18next.t('jobs.runinfo_subhead')}</MqText>
</Box>
<MqJsonView
data={run.facets}
aria-label={i18next.t('jobs.facets_subhead_aria')}
aria-required='true'
/>
</Box>
)}
</Box>
)
}
const mapStateToProps = (state: IState) => ({
jobFacets: state.facets.result,
})
const mapDispatchToProps = (dispatch: Redux.Dispatch) =>
Redux.bindActionCreators(
{
fetchJobFacets: fetchJobFacets,
resetFacets: resetFacets,
},
dispatch
)
export default connect(mapStateToProps, mapDispatchToProps)(RunInfo)