forked from amundsen-io/amundsen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ae1fbcd
commit 769b1bb
Showing
8 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
frontend/amundsen_application/static/images/icons/ExportMetadata.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
93 changes: 93 additions & 0 deletions
93
...end/amundsen_application/static/js/components/ExportMetadata/ExportMetadataIcon/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright Contributors to the Amundsen project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import * as React from 'react'; | ||
import { bindActionCreators } from 'redux'; | ||
import { connect } from 'react-redux'; | ||
|
||
import { logClick } from 'utils/analytics'; | ||
|
||
import { ResourceType, TableMetadata } from 'interfaces'; | ||
|
||
import { exportEnabled } from 'config/config-utils'; | ||
|
||
import './styles.scss'; | ||
|
||
import Papa from 'papaparse'; | ||
|
||
interface StateFromProps { | ||
tableData: TableMetadata; | ||
} | ||
|
||
export type ExportMetadataIconProps = StateFromProps; | ||
|
||
export class ExportMetadataIcon extends React.Component<ExportMetadataIconProps> { | ||
|
||
triggerDownload = (csv, filename) => { | ||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' }); | ||
const link = document.createElement('a'); | ||
link.href = URL.createObjectURL(blob); | ||
link.setAttribute('download', filename); | ||
document.body.appendChild(link); | ||
link.click(); | ||
document.body.removeChild(link); | ||
}; | ||
|
||
handleClick = (e: React.MouseEvent<HTMLElement>) => { | ||
e.stopPropagation(); | ||
e.preventDefault(); | ||
|
||
const { tableData } = this.props; | ||
|
||
const exportedMetadata: Record<string, any>[] = []; | ||
|
||
if (tableData) { | ||
|
||
tableData.columns.forEach(column => { | ||
let rowData: Record<string, any> = {}; | ||
rowData['column_key'] = column.key; | ||
rowData['column_name'] = column.name; | ||
rowData['column_data_type'] = column.col_type; | ||
rowData['column_description'] = column.description; | ||
let column_badges: string[] = []; | ||
column.badges.forEach(badge => { | ||
if (badge.badge_name) { | ||
column_badges.push(badge.badge_name); | ||
} | ||
}); | ||
rowData['column_badges'] = column_badges; | ||
|
||
exportedMetadata.push(rowData); | ||
}); | ||
|
||
const csv = Papa.unparse(exportedMetadata); | ||
this.triggerDownload(csv, `export_metadata.${tableData.database}.${tableData.cluster}.${tableData.schema}.${tableData.name}.csv`); | ||
} | ||
|
||
|
||
logClick(e, { | ||
label: 'Export Metadata', | ||
target_id: `export-metadata-button`, | ||
}); | ||
}; | ||
|
||
render() { | ||
const { tableData } = this.props; | ||
|
||
return ( | ||
<div | ||
className={'export-metadata-icon'} | ||
onClick={this.handleClick} | ||
> | ||
<img | ||
className={ | ||
'icon icon-export-metadata' | ||
} | ||
alt="" | ||
/> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default ExportMetadataIcon; |
30 changes: 30 additions & 0 deletions
30
...d/amundsen_application/static/js/components/ExportMetadata/ExportMetadataIcon/styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
@import 'variables'; | ||
|
||
.export-metadata-icon { | ||
border-radius: 50%; | ||
cursor: pointer; | ||
display: inline-block; | ||
height: 32px; | ||
margin-left: 4px; | ||
padding: 4px; | ||
vertical-align: top; | ||
width: 32px; | ||
|
||
&:hover, | ||
&:focus { | ||
background-color: $body-bg-tertiary; | ||
} | ||
|
||
.icon { | ||
margin: 0; | ||
|
||
&.icon-export-metadata { | ||
&, | ||
&:hover, | ||
&:focus { | ||
background-color: $stroke !important; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters