From 8be5cc8f6549d6e26ed613037a3ab288bc3b9baf Mon Sep 17 00:00:00 2001 From: Matt Oestreich Date: Fri, 22 Jan 2021 15:52:55 -0600 Subject: [PATCH] update exporters --- __tests__/MTableFilterRow.test.js | 1 - exporters/csv.js | 24 ++++++------- exporters/pdf.js | 49 +++++++++++++-------------- src/components/MTableToolbar/index.js | 1 - src/components/m-table-body-row.js | 1 - 5 files changed, 36 insertions(+), 40 deletions(-) diff --git a/__tests__/MTableFilterRow.test.js b/__tests__/MTableFilterRow.test.js index 2d500cab..3ccb3254 100644 --- a/__tests__/MTableFilterRow.test.js +++ b/__tests__/MTableFilterRow.test.js @@ -50,7 +50,6 @@ describe('MTableFilterRow Tests', () => { ); const els = Array.from(wrapper.find('#m--table--filter--row')) || []; const el = els[0]; - console.log(el.find('#m--table--filter--row')); expect(TABLE_REF.current.dataManager.filtered).toBe(true); }); }); diff --git a/exporters/csv.js b/exporters/csv.js index f5c3ee39..047f6c39 100644 --- a/exporters/csv.js +++ b/exporters/csv.js @@ -1,19 +1,19 @@ +import { CsvBuilder } from 'filefy'; + export default function ExportCsv( columns, data, filename = 'data', delimiter = ',' ) { - import('filefy') - .then(({ CsvBuilder }) => { - const builder = new CsvBuilder(filename + '.csv'); - builder - .setDelimeter(delimiter) - .setColumns(columns.map((col) => col.title)) - .addRows(Array.from(data)) - .exportFile(); - }) - .catch((err) => { - console.error(`exporting csv : unable to import 'filefy' : ${err}`); - }); + try { + const builder = new CsvBuilder(filename + '.csv'); + builder + .setDelimeter(delimiter) + .setColumns(columns.map((col) => col.title)) + .addRows(Array.from(data)) + .exportFile(); + } catch (err) { + console.err(`err in ExportCsv : ${err}`); + } } diff --git a/exporters/pdf.js b/exporters/pdf.js index c4293ae5..c276ca6f 100644 --- a/exporters/pdf.js +++ b/exporters/pdf.js @@ -1,27 +1,26 @@ +import 'jspdf-autotable'; + export default function ExportPdf(columns, data, filename = 'data') { - import('jspdf-autotable') - .then(() => { - const JSpdf = - typeof window !== 'undefined' ? require('jspdf').jsPDF : null; - if (JSpdf !== null) { - const content = { - startY: 50, - head: [columns.map((col) => col.title)], - body: data - }; - const unit = 'pt'; - const size = 'A4'; - const orientation = 'landscape'; - const doc = new JSpdf(orientation, unit, size); - doc.setFontSize(15); - doc.text(filename, 40, 40); - doc.autoTable(content); - doc.save(filename + '.pdf'); - } - }) - .catch((err) => { - console.error( - `exporting pdf : unable to import 'jspdf-autotable' : ${err}` - ); - }); + try { + const JSpdf = typeof window !== 'undefined' ? require('jspdf').jsPDF : null; + if (JSpdf !== null) { + const content = { + startY: 50, + head: [columns.map((col) => col.title)], + body: data + }; + const unit = 'pt'; + const size = 'A4'; + const orientation = 'landscape'; + const doc = new JSpdf(orientation, unit, size); + doc.setFontSize(15); + doc.text(filename, 40, 40); + doc.autoTable(content); + doc.save(filename + '.pdf'); + } + } catch (err) { + console.error( + `exporting pdf : unable to import 'jspdf-autotable' : ${err}` + ); + } } diff --git a/src/components/MTableToolbar/index.js b/src/components/MTableToolbar/index.js index cfadedda..7e4506ce 100644 --- a/src/components/MTableToolbar/index.js +++ b/src/components/MTableToolbar/index.js @@ -99,7 +99,6 @@ export function MTableToolbar(props) { } function renderDefaultActions() { - console.log('renderDefaultActions', { props }); const localization = { ...MTableToolbar.defaultProps.localization, ...props.localization diff --git a/src/components/m-table-body-row.js b/src/components/m-table-body-row.js index 77637a54..983e317d 100644 --- a/src/components/m-table-body-row.js +++ b/src/components/m-table-body-row.js @@ -56,7 +56,6 @@ export default class MTableBodyRow extends React.Component { } const key = `cell-${this.props.data.tableData.id}-${columnDef.tableData.id}`; - console.log(`rendering cell ${key}`, { props: this.props }); return (