Skip to content

Commit

Permalink
Update Export file name
Browse files Browse the repository at this point in the history
  • Loading branch information
vietredweb committed Dec 26, 2023
1 parent 941a59c commit c229c42
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 8 deletions.
29 changes: 24 additions & 5 deletions packages/aesirx-bi-app/src/components/ExportButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,33 @@ import { Col, Dropdown, Form, Row } from 'react-bootstrap';
import { CSVLink } from 'react-csv';
import { Translation } from 'react-i18next';
import ReactToPrint from 'react-to-print';
import { useBiViewModel } from 'store/BiStore/BiViewModelContextProvider';
import { downloadExcel } from 'utils';

function ExportButton({ data, tableExport, t, i18n, componentRef, classWrapper = false }) {
function ExportButton({
data,
tableExport,
t,
i18n,
componentRef,
classWrapper = false,
sectionName = '',
}) {
const [exportFile, setExportFile] = useState({
format: 'pdf',
type: 'page',
});
const biStore = useBiViewModel();

const handleChange = (state) => {
setExportFile(state);
};
const isSameday =
biStore?.biListViewModel?.dateFilter?.date_start ===
biStore?.biListViewModel?.dateFilter?.date_end;
const nameFile = `${biStore?.biListViewModel?.activeDomain}_${sectionName}_${
biStore?.biListViewModel?.dateFilter?.date_start
}${!isSameday ? `_${biStore?.biListViewModel?.dateFilter?.date_end}` : ''}`;
return (
<div className={`${classWrapper ? '' : 'printButton'} me-2`}>
<Dropdown align="end">
Expand Down Expand Up @@ -135,7 +151,7 @@ function ExportButton({ data, tableExport, t, i18n, componentRef, classWrapper =
<CSVLink
data={tableExport?.find((o) => o?.name === exportFile?.name)?.data}
className="btn btn-light text-nowrap py-13 lh-sm rounded-1"
filename="data.csv"
filename={`${nameFile}.csv`}
>
Export
</CSVLink>
Expand All @@ -146,7 +162,7 @@ function ExportButton({ data, tableExport, t, i18n, componentRef, classWrapper =
<CSVLink
data={data}
className="btn btn-light text-nowrap py-13 lh-sm rounded-1"
filename="data.csv"
filename={`${nameFile}.csv`}
>
Export
</CSVLink>
Expand All @@ -161,7 +177,10 @@ function ExportButton({ data, tableExport, t, i18n, componentRef, classWrapper =
<button
className="btn btn-light text-nowrap py-13 lh-sm rounded-1"
onClick={() =>
downloadExcel(tableExport?.find((o) => o?.name === exportFile?.name)?.data)
downloadExcel(
tableExport?.find((o) => o?.name === exportFile?.name)?.data,
`${nameFile}`
)
}
>
Export
Expand All @@ -172,7 +191,7 @@ function ExportButton({ data, tableExport, t, i18n, componentRef, classWrapper =
) : data?.length ? (
<button
className="btn btn-light text-nowrap py-13 lh-sm rounded-1"
onClick={() => downloadExcel(data)}
onClick={() => downloadExcel(data, `${nameFile}`)}
>
Export
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const ConsentsPage = observer(
i18n={this.props.i18n}
t={this.props.t}
componentRef={this.componentRef}
sectionName={'consent'}
/>

<ComponentToPrint
Expand Down
1 change: 1 addition & 0 deletions packages/aesirx-bi-app/src/containers/Dashboard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const DashboardContainer = observer(
i18n={this.props.i18n}
t={this.props.t}
componentRef={this.componentRef}
sectionName={'dashboard'}
/>
<ComponentToPrint ref={(el) => (this.componentRef = el)} />
</DashboardViewModelContextProvider>
Expand Down
1 change: 1 addition & 0 deletions packages/aesirx-bi-app/src/containers/EventsPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ const EventsPage = observer(
t={this.props.t}
componentRef={this.componentRef}
classWrapper={true}
sectionName={'event'}
/>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const CountryContainer = observer(
i18n={this.props.i18n}
t={this.props.t}
componentRef={this.componentRef}
sectionName={'location'}
/>
<ComponentToPrint ref={(el) => (this.componentRef = el)} />
</CountryViewModelContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const UTMTrackingPage = observer(
i18n={this.props.i18n}
t={this.props.t}
componentRef={this.componentRef}
sectionName={'utm-tracking'}
/>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class PageModel {
toPagesTableTop = () => {
const headerTable = [
'txt_page',
'txt_page_views',
'txt_visitors',
'txt_unique_page_views',
'txt_bounce_rate',
'txt_page_session',
Expand Down
3 changes: 3 additions & 0 deletions packages/aesirx-bi-app/src/containers/VisitorsPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ const VisitorsContainer = observer(
i18n={this.props.i18n}
t={this.props.t}
componentRef={this.componentRef}
sectionName={
matchVisitor?.isExact || integrationLink === 'visitors' ? 'visitors' : 'behavior'
}
/>

<ComponentToPrint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const WoocommercePage = observer(
i18n={this.props.i18n}
t={this.props.t}
componentRef={this.componentRef}
sectionName={'woocommerce'}
/>
)}

Expand Down
4 changes: 2 additions & 2 deletions packages/aesirx-bi-app/src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as XLSX from 'xlsx';
const downloadExcel = (data) => {
const downloadExcel = (data, nameFile) => {
const worksheet = XLSX.utils.json_to_sheet(data);
const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
XLSX.writeFile(workbook, 'DataSheet.xlsx');
XLSX.writeFile(workbook, `${nameFile}.xlsx`);
};
export { downloadExcel };

0 comments on commit c229c42

Please sign in to comment.