1
- import { Button , Dropdown , Empty , Image , message , Modal , Tag , Tooltip , Typography } from 'antd' ;
1
+ import { Button , Dropdown , Empty , Image , message , Modal , Tag , Tooltip , Typography , Checkbox } from 'antd' ;
2
2
import React from 'react' ;
3
3
import styled from 'styled-components' ;
4
- import { DeleteOutlined , DownOutlined , MoreOutlined , RightOutlined , StopOutlined } from '@ant-design/icons' ;
4
+ import {
5
+ DeleteOutlined ,
6
+ DownOutlined ,
7
+ MoreOutlined ,
8
+ RightOutlined ,
9
+ StopOutlined ,
10
+ AuditOutlined ,
11
+ } from '@ant-design/icons' ;
12
+ import { Link } from 'react-router-dom' ;
5
13
import { DatasetAssertionDescription } from './DatasetAssertionDescription' ;
6
14
import { StyledTable } from '../../../components/styled/StyledTable' ;
7
15
import { DatasetAssertionDetails } from './DatasetAssertionDetails' ;
8
- import { Assertion , AssertionRunStatus } from '../../../../../../types.generated' ;
16
+ import { Assertion , AssertionRunStatus , DataContract , EntityType } from '../../../../../../types.generated' ;
9
17
import { getResultColor , getResultIcon , getResultText } from './assertionUtils' ;
10
18
import { useDeleteAssertionMutation } from '../../../../../../graphql/assertion.generated' ;
11
19
import { capitalizeFirstLetterOnly } from '../../../../../shared/textUtil' ;
12
20
import AssertionMenu from './AssertionMenu' ;
21
+ import { REDESIGN_COLORS } from '../../../constants' ;
22
+ import { useEntityRegistry } from '../../../../../useEntityRegistry' ;
23
+ import { isAssertionPartOfContract } from './contract/utils' ;
24
+ import { useEntityData } from '../../../EntityContext' ;
13
25
14
26
const ResultContainer = styled . div `
15
27
display: flex;
@@ -35,9 +47,26 @@ const StyledMoreOutlined = styled(MoreOutlined)`
35
47
font-size: 18px;
36
48
` ;
37
49
50
+ const AssertionSelectCheckbox = styled ( Checkbox ) `
51
+ margin-right: 12px;
52
+ ` ;
53
+
54
+ const DataContractLogo = styled ( AuditOutlined ) `
55
+ margin-left: 8px;
56
+ font-size: 16px;
57
+ color: ${ REDESIGN_COLORS . BLUE } ;
58
+ ` ;
59
+
38
60
type Props = {
39
61
assertions : Array < Assertion > ;
40
62
onDelete ?: ( urn : string ) => void ;
63
+ contract ?: DataContract ;
64
+ // required for enabling menu/actions
65
+ showMenu ?: boolean ;
66
+ onSelect ?: ( assertionUrn : string ) => void ;
67
+ // required for enabling selection logic
68
+ showSelect ?: boolean ;
69
+ selectedUrns ?: string [ ] ;
41
70
} ;
42
71
43
72
/**
@@ -46,8 +75,18 @@ type Props = {
46
75
*
47
76
* Currently this component supports rendering Dataset Assertions only.
48
77
*/
49
- export const DatasetAssertionsList = ( { assertions, onDelete } : Props ) => {
78
+ export const DatasetAssertionsList = ( {
79
+ assertions,
80
+ onDelete,
81
+ showMenu = true ,
82
+ showSelect,
83
+ onSelect,
84
+ selectedUrns,
85
+ contract,
86
+ } : Props ) => {
87
+ const entityData = useEntityData ( ) ;
50
88
const [ deleteAssertionMutation ] = useDeleteAssertionMutation ( ) ;
89
+ const entityRegistry = useEntityRegistry ( ) ;
51
90
52
91
const deleteAssertion = async ( urn : string ) => {
53
92
try {
@@ -102,9 +141,19 @@ export const DatasetAssertionsList = ({ assertions, onDelete }: Props) => {
102
141
const resultColor = ( record . lastExecResult && getResultColor ( record . lastExecResult ) ) || 'default' ;
103
142
const resultText = ( record . lastExecResult && getResultText ( record . lastExecResult ) ) || 'No Evaluations' ;
104
143
const resultIcon = ( record . lastExecResult && getResultIcon ( record . lastExecResult ) ) || < StopOutlined /> ;
144
+ const selected = selectedUrns ?. some ( ( selectedUrn ) => selectedUrn === record . urn ) ;
145
+ const isPartOfContract = contract && isAssertionPartOfContract ( record , contract ) ;
146
+
105
147
const { description } = record ;
106
148
return (
107
149
< ResultContainer >
150
+ { showSelect ? (
151
+ < AssertionSelectCheckbox
152
+ checked = { selected }
153
+ onClick = { ( e ) => e . stopPropagation ( ) }
154
+ onChange = { ( ) => onSelect ?.( record . urn as string ) }
155
+ />
156
+ ) : undefined }
108
157
< div >
109
158
< Tooltip title = { ( localTime && `Last evaluated on ${ localTime } ` ) || 'No Evaluations' } >
110
159
< Tag style = { { borderColor : resultColor } } >
@@ -117,6 +166,34 @@ export const DatasetAssertionsList = ({ assertions, onDelete }: Props) => {
117
166
description = { description }
118
167
assertionInfo = { record . datasetAssertionInfo }
119
168
/>
169
+ { ( isPartOfContract && entityData ?. urn && (
170
+ < Tooltip
171
+ title = {
172
+ < >
173
+ Part of Data Contract{ ' ' }
174
+ < Link
175
+ to = { `${ entityRegistry . getEntityUrl (
176
+ EntityType . Dataset ,
177
+ entityData . urn ,
178
+ ) } /Validation/Data Contract`}
179
+ style = { { color : REDESIGN_COLORS . BLUE } }
180
+ >
181
+ view
182
+ </ Link >
183
+ </ >
184
+ }
185
+ >
186
+ < Link
187
+ to = { `${ entityRegistry . getEntityUrl (
188
+ EntityType . Dataset ,
189
+ entityData . urn ,
190
+ ) } /Validation/Data Contract`}
191
+ >
192
+ < DataContractLogo />
193
+ </ Link >
194
+ </ Tooltip >
195
+ ) ) ||
196
+ undefined }
120
197
</ ResultContainer >
121
198
) ;
122
199
} ,
@@ -126,35 +203,40 @@ export const DatasetAssertionsList = ({ assertions, onDelete }: Props) => {
126
203
dataIndex : '' ,
127
204
key : '' ,
128
205
render : ( _ , record : any ) => (
129
- < ActionButtonContainer >
130
- < Tooltip
131
- title = {
132
- record . platform . properties ?. displayName || capitalizeFirstLetterOnly ( record . platform . name )
133
- }
134
- >
135
- < PlatformContainer >
136
- { ( record . platform . properties ?. logoUrl && (
137
- < Image
138
- preview = { false }
139
- height = { 20 }
140
- width = { 20 }
141
- src = { record . platform . properties ?. logoUrl }
142
- />
143
- ) ) || (
144
- < Typography . Text >
145
- { record . platform . properties ?. displayName ||
146
- capitalizeFirstLetterOnly ( record . platform . name ) }
147
- </ Typography . Text >
148
- ) }
149
- </ PlatformContainer >
150
- </ Tooltip >
151
- < Button onClick = { ( ) => onDeleteAssertion ( record . urn ) } type = "text" shape = "circle" danger >
152
- < DeleteOutlined />
153
- </ Button >
154
- < Dropdown overlay = { < AssertionMenu urn = { record . urn } /> } trigger = { [ 'click' ] } >
155
- < StyledMoreOutlined />
156
- </ Dropdown >
157
- </ ActionButtonContainer >
206
+ < >
207
+ { showMenu && (
208
+ < ActionButtonContainer >
209
+ < Tooltip
210
+ title = {
211
+ record . platform . properties ?. displayName ||
212
+ capitalizeFirstLetterOnly ( record . platform . name )
213
+ }
214
+ >
215
+ < PlatformContainer >
216
+ { ( record . platform . properties ?. logoUrl && (
217
+ < Image
218
+ preview = { false }
219
+ height = { 20 }
220
+ width = { 20 }
221
+ src = { record . platform . properties ?. logoUrl }
222
+ />
223
+ ) ) || (
224
+ < Typography . Text >
225
+ { record . platform . properties ?. displayName ||
226
+ capitalizeFirstLetterOnly ( record . platform . name ) }
227
+ </ Typography . Text >
228
+ ) }
229
+ </ PlatformContainer >
230
+ </ Tooltip >
231
+ < Button onClick = { ( ) => onDeleteAssertion ( record . urn ) } type = "text" shape = "circle" danger >
232
+ < DeleteOutlined />
233
+ </ Button >
234
+ < Dropdown overlay = { < AssertionMenu urn = { record . urn } /> } trigger = { [ 'click' ] } >
235
+ < StyledMoreOutlined />
236
+ </ Dropdown >
237
+ </ ActionButtonContainer >
238
+ ) }
239
+ </ >
158
240
) ,
159
241
} ,
160
242
] ;
@@ -168,18 +250,36 @@ export const DatasetAssertionsList = ({ assertions, onDelete }: Props) => {
168
250
locale = { {
169
251
emptyText : < Empty description = "No Assertions Found :(" image = { Empty . PRESENTED_IMAGE_SIMPLE } /> ,
170
252
} }
171
- expandable = { {
172
- defaultExpandAllRows : false ,
173
- expandRowByClick : true ,
174
- expandedRowRender : ( record ) => {
175
- return < DatasetAssertionDetails urn = { record . urn } lastEvaluatedAtMillis = { record . lastExecTime } /> ;
176
- } ,
177
- expandIcon : ( { expanded, onExpand, record } : any ) =>
178
- expanded ? (
179
- < DownOutlined style = { { fontSize : 8 } } onClick = { ( e ) => onExpand ( record , e ) } />
180
- ) : (
181
- < RightOutlined style = { { fontSize : 8 } } onClick = { ( e ) => onExpand ( record , e ) } />
182
- ) ,
253
+ expandable = {
254
+ showSelect
255
+ ? { }
256
+ : {
257
+ defaultExpandAllRows : false ,
258
+ expandRowByClick : true ,
259
+ expandedRowRender : ( record ) => {
260
+ return (
261
+ < DatasetAssertionDetails
262
+ urn = { record . urn }
263
+ lastEvaluatedAtMillis = { record . lastExecTime }
264
+ />
265
+ ) ;
266
+ } ,
267
+ expandIcon : ( { expanded, onExpand, record } : any ) =>
268
+ expanded ? (
269
+ < DownOutlined style = { { fontSize : 8 } } onClick = { ( e ) => onExpand ( record , e ) } />
270
+ ) : (
271
+ < RightOutlined style = { { fontSize : 8 } } onClick = { ( e ) => onExpand ( record , e ) } />
272
+ ) ,
273
+ }
274
+ }
275
+ onRow = { ( record ) => {
276
+ return {
277
+ onClick : ( _ ) => {
278
+ if ( showSelect ) {
279
+ onSelect ?.( record . urn as string ) ;
280
+ }
281
+ } ,
282
+ } ;
183
283
} }
184
284
showHeader = { false }
185
285
pagination = { false }
0 commit comments