Skip to content

Commit

Permalink
Fix export to display results from UI filters
Browse files Browse the repository at this point in the history
  • Loading branch information
RachelElysia committed Oct 9, 2023
1 parent 8f1bb1c commit eba8ddd
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { QueryContext } from "context/query";

import {
generateCSVFilename,
generateCSVQueryReport,
generateCSVQueryResults,
} from "utilities/generate_csv";
import { IQueryReport } from "interfaces/query_report";
import { humanLastSeen } from "utilities/helpers";
Expand Down Expand Up @@ -62,7 +62,7 @@ const QueryReport = ({ queryReport }: IQueryReportProps): JSX.Element => {
const onExportQueryResults = (evt: React.MouseEvent<HTMLButtonElement>) => {
evt.preventDefault();
FileSaver.saveAs(
generateCSVQueryReport(
generateCSVQueryResults(
filteredResults,
generateCSVFilename(
`${lastEditedQueryName || CSV_TITLE} - Query Report`
Expand Down Expand Up @@ -106,14 +106,12 @@ const QueryReport = ({ queryReport }: IQueryReportProps): JSX.Element => {
);
};

console.log("tableHeaders", tableHeaders);
console.log("filteredResults", filteredResults);
const renderTable = () => {
return (
<div className={`${baseClass}__results-table-container`}>
<TableContainer
columns={tableHeaders}
data={filteredResults}
data={tableResults(queryReport?.results) || []}
emptyComponent={renderNoResults}
isLoading={false}
isClientSidePagination
Expand All @@ -123,7 +121,7 @@ const QueryReport = ({ queryReport }: IQueryReportProps): JSX.Element => {
isAllPagesSelected={false}
resultsTitle="results"
customControl={() => renderTableButtons()}
// setExportRows={setFilteredResults}
setExportRows={setFilteredResults}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ const QueryResults = ({
tableData: unknown[],
tableType: "errors" | "results"
) => {
console.log("tableHeaders", tableHeaders);
console.log("tableData", tableData);

return (
<div className={`${baseClass}__results-table-container`}>
<TableContainer
Expand Down
28 changes: 3 additions & 25 deletions frontend/utilities/generate_csv/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ICampaignError } from "interfaces/campaign";
import { format } from "date-fns";

const reorderCSVFields = (tableHeaders: string[]) => {
console.log("tableHeaders", tableHeaders);
const result = tableHeaders.filter((field) => field !== "host_display_name");
result.unshift("host_display_name");

Expand All @@ -15,28 +14,7 @@ export const generateCSVFilename = (descriptor: string) => {
return `${descriptor} (${format(new Date(), "MM-dd-yy hh-mm-ss")}).csv`;
};

// Query report
export const generateCSVQueryReport = (
rows: Row[],
filename: string,
tableHeaders: Column[] | string[]
) => {
return new global.window.File(
[
convertToCSV({
objArray: rows,
fieldSortFunc: reorderCSVFields,
tableHeaders,
}),
],
filename,
{
type: "text/csv",
}
);
};

// Query results and query errors
// Live query results, live query errors, and query report
export const generateCSVQueryResults = (
rows: Row[],
filename: string,
Expand All @@ -57,7 +35,7 @@ export const generateCSVQueryResults = (
);
};

// Policy results only
// Live policy results only
export const generateCSVPolicyResults = (
rows: { host: string; status: string }[],
filename: string
Expand All @@ -67,7 +45,7 @@ export const generateCSVPolicyResults = (
});
};

// Policy errors only
// Live policy errors only
export const generateCSVPolicyErrors = (
rows: ICampaignError[],
filename: string
Expand Down

0 comments on commit eba8ddd

Please sign in to comment.