Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

u #46

Merged
merged 1 commit into from
Oct 14, 2024
Merged

u #46

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions frontend/amundsen_application/static/css/_icons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ width: $icon-size;
mask-image: url('../images/icons/Alert-Triangle.svg');
}

&.icon-export-metadata {
-webkit-mask-image: url('../images/icons/ExportMetadata.svg');
mask-image: url('../images/icons/ExportMetadata.svg');
}

&.icon-bookmark {
-webkit-mask-image: url('../images/icons/Favorite.svg');
mask-image: url('../images/icons/Favorite.svg');
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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;
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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ const configDefault: AppConfig = {
bookmarks: {
enabled: true,
},
export: {
enabled: true,
},
navLinks: [
{
href: '/announcements',
Expand Down
10 changes: 10 additions & 0 deletions frontend/amundsen_application/static/js/config/config-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface AppConfig {
logoTitle: string;
footerContentHtml: string;
bookmarks: BookmarksFeaturesConfig;
export: ExportFeaturesConfig;
mailClientFeatures: MailClientFeaturesConfig;
navAppSuite: VisualLinkConfig[] | null;
navLinks: LinkConfig[];
Expand Down Expand Up @@ -398,6 +399,15 @@ interface BookmarksFeaturesConfig {
enabled: boolean;
}

/**
* ExportFeaturesConfig - Enable/disable UI features related to the export
*
* enabled - Enables the export feature
*/
interface ExportFeaturesConfig {
enabled: boolean;
}

/**
* TableProfileConfig - Customize the "Table Profile" section of the "Table Details" page.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,13 @@ export function bookmarksEnabled(): boolean {
return AppConfig.bookmarks.enabled;
}

/**
* Returns whether or not export features should be enabled
*/
export function exportEnabled(): boolean {
return AppConfig.export.enabled;
}

/**
* Returns whether or not dashboard features should be shown
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import ColumnDetailsPanel from 'features/ColumnList/ColumnDetailsPanel';

import { AlertList } from 'components/Alert';
import BookmarkIcon from 'components/Bookmark/BookmarkIcon';
import ExportMetadataIcon from 'components/ExportMetadata/ExportMetadataIcon';
import Breadcrumb from 'features/Breadcrumb';
import EditableSection from 'components/EditableSection';
import EditableText from 'components/EditableText';
Expand Down Expand Up @@ -772,6 +773,9 @@ export class TableDetail extends React.Component<
bookmarkKey={data.key}
resourceType={ResourceType.table}
/>
<ExportMetadataIcon
tableData={data}
/>
<div className="header-details">
<TableHeaderBullets
database={data.database}
Expand Down
Loading