Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Tostti committed Dec 13, 2024
1 parent be67522 commit dd28d16
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
*/

import React from 'react';
import {
EuiFlexItem,
EuiButtonEmpty,
EuiIconTip
} from '@elastic/eui';
import { EuiFlexItem, EuiButtonEmpty, EuiIconTip } from '@elastic/eui';
import exportCsv from '../../../../react-services/wz-csv';
import { getToasts } from '../../../../kibana-services';
import { getToasts } from '../../../../kibana-services';
import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrator/types';
import { UI_LOGGER_LEVELS } from '../../../../../common/constants';
import { getErrorOrchestrator } from '../../../../react-services/common-services';

export function ExportTableCsv({ endpoint, totalItems, filters, title, maxRows }) {

export function ExportTableCsv({
endpoint,
totalItems,
filters,
title,
maxRows,
}) {
const showToast = (color, title, time) => {
getToasts().add({
color: color,
Expand All @@ -34,15 +35,12 @@ export function ExportTableCsv({ endpoint, totalItems, filters, title, maxRows }

const downloadCsv = async () => {
try {
const formatedFilters = Object.entries(filters).map(([name, value]) => ({name, value}));
const formatedFilters = Object.entries(filters).map(([name, value]) => ({
name,
value,
}));
showToast('success', 'Your download should begin automatically...', 3000);
await exportCsv(
endpoint,
[
...formatedFilters
],
`${(title).toLowerCase()}`
);
await exportCsv(endpoint, [...formatedFilters], `${title.toLowerCase()}`);
} catch (error) {
const options = {
context: `${ExportTableCsv.name}.downloadCsv`,
Expand All @@ -56,25 +54,36 @@ export function ExportTableCsv({ endpoint, totalItems, filters, title, maxRows }
};
getErrorOrchestrator().handleError(options);
}
}
};

return <EuiFlexItem grow={false}>
<EuiButtonEmpty isDisabled={(totalItems == 0)} iconType="importAction" onClick={() => downloadCsv()}>
Export formatted
{totalItems > maxRows&&<> <EuiIconTip
content={`The exported CSV will be limited to the first ${maxRows} lines. You can change this limit in Dashboard management > App Settings`}
size='m'
color='primary'
type='iInCircle'
/></>}
</EuiButtonEmpty>
return (
<EuiFlexItem grow={false}>
<EuiButtonEmpty
isDisabled={totalItems == 0}
iconType='importAction'
onClick={() => downloadCsv()}
>
Export formatted
{totalItems > maxRows && (
<>
{' '}
<EuiIconTip
content={`The exported CSV will be limited to the first ${maxRows} lines. You can change this limit in Dashboard management > App Settings`}
size='m'
color='primary'
type='iInCircle'
/>
</>
)}
</EuiButtonEmpty>
</EuiFlexItem>
);
}

// Set default props
ExportTableCsv.defaultProps = {
endpoint:'/',
totalItems:0,
filters: [],
title:""
};
endpoint: '/',
totalItems: 0,
filters: [],
title: '',
};
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ export function TableWzAPI({
}
maxRows={maxRows}
/>

</>
)}
{/* Render optional post custom action button */}
Expand Down

0 comments on commit dd28d16

Please sign in to comment.