|
1 | 1 | // SPDX-License-Identifier: Apache-2.0 |
2 | 2 |
|
3 | | -import { Box } from '@material-ui/core' |
| 3 | +import { Box, Button } from '@material-ui/core' |
4 | 4 | import MqEmpty from '../core/empty/MqEmpty' |
5 | 5 | import MqJson from '../core/code/MqJson' |
| 6 | +import MqText from '../core/text/MqText' |
6 | 7 | import React, { FunctionComponent } from 'react' |
| 8 | +import { fileSize } from '../../helpers' |
| 9 | +import { LineageDataset } from '../lineage/types' |
| 10 | +import { saveAs } from 'file-saver' |
7 | 11 |
|
8 | 12 | interface DatasetColumnLineageProps { |
9 | 13 | columnLineage: object |
| 14 | + lineageDataset: LineageDataset |
10 | 15 | } |
11 | 16 |
|
12 | 17 | const DatasetColumnLineage: FunctionComponent<DatasetColumnLineageProps> = props => { |
13 | | - const { columnLineage } = props |
| 18 | + const { columnLineage, lineageDataset } = props |
| 19 | + |
| 20 | + const handleDownloadPayload = (data: object) => { |
| 21 | + const title = `${lineageDataset.name}-${lineageDataset.namespace}-columnLineage` |
| 22 | + const blob = new Blob([JSON.stringify(data)], { type: 'application/json' }) |
| 23 | + saveAs(blob, `${title}.json`) |
| 24 | + } |
14 | 25 |
|
15 | 26 | return ( |
16 | | - <Box> |
| 27 | + <> |
17 | 28 | {columnLineage |
18 | 29 | ? ( |
19 | | - <Box mt={2}> |
20 | | - <MqJson code={columnLineage} /> |
21 | | - </Box> |
| 30 | + <> |
| 31 | + {fileSize(JSON.stringify(columnLineage)).kiloBytes > 500 ? ( |
| 32 | + <Box p={2}> |
| 33 | + <MqEmpty title={'Payload is too big for render'}> |
| 34 | + <div> |
| 35 | + <MqText subdued> |
| 36 | + Please click on button and download payload as file |
| 37 | + </MqText> |
| 38 | + <br /> |
| 39 | + <Button |
| 40 | + variant='outlined' |
| 41 | + color='primary' |
| 42 | + onClick={() => handleDownloadPayload(columnLineage)} |
| 43 | + > |
| 44 | + Download payload |
| 45 | + </Button> |
| 46 | + </div> |
| 47 | + </MqEmpty> |
| 48 | + </Box> |
| 49 | + ) : ( |
| 50 | + <MqJson |
| 51 | + code={columnLineage} |
| 52 | + wrapLongLines={true} |
| 53 | + showLineNumbers={true} |
| 54 | + /> |
| 55 | + )} |
| 56 | + </> |
22 | 57 | ) |
23 | 58 | : ( |
24 | 59 | <MqEmpty title={'No column lineage'} body={'Column lineage not available for the specified dataset.'} /> |
25 | 60 | ) |
26 | 61 | } |
27 | | - </Box> |
| 62 | + </> |
28 | 63 | ) |
29 | 64 | } |
30 | 65 |
|
|
0 commit comments