Skip to content

Commit

Permalink
Adding csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
rb-x committed Sep 21, 2023
1 parent b9f0bed commit 39a8ce6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
27 changes: 7 additions & 20 deletions src/pages/popup/components/misc/Checklists/OWSTG.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { useEffect } from 'react';
import { Button, Card, Checkbox, Col, Divider, Form, Input, Layout, Modal, Popconfirm, Progress, Radio, Row, Select, Space, Statistic, Table, Tag, Tooltip, Typography, message } from 'antd';
import createOWSTGStore, { initializeChecklist } from './stores/MethodologyStore';
import { AtomicTest, Pentest, Substep, TestCaseStatus, Quote } from "./ChecklistInterfaces"
import tabStateStore from './stores/TabStateStore';
const { TextArea } = Input;
import { useHotkeys } from 'react-hotkeys-hook';
import { UserOutlined, BugOutlined, HourglassOutlined, SearchOutlined } from '@ant-design/icons';
import { FloatButton } from 'antd';
import { Dropdown } from 'antd';
import { BugOutlined, HourglassOutlined, SearchOutlined, UserOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { Button, Card, Col, Divider, Dropdown, FloatButton, Input, Layout, Progress, Row, Select, Space, Statistic, Table, Typography, message } from 'antd';
import { BsFiletypeJson } from 'react-icons/bs';
import { TbCsv } from 'react-icons/tb';
import { MdHttp } from 'react-icons/md';
import type { MenuProps } from 'antd';
import { Record, String, Array, Number, Union, Literal, Static } from 'runtypes';
import quotes from '../../../assets/data/Quotes/Quotes.json';
import { AtomicTest, Quote, TestCaseStatus } from "./ChecklistInterfaces";
import createOWSTGStore from './stores/MethodologyStore';
const { TextArea } = Input;
const { Header, Content } = Layout;


Expand All @@ -24,7 +17,7 @@ const OWSTG = ({ id }: { id: string }) => {

// Handler for this Tab's state
const useStore = createOWSTGStore(id);
const { stateFlattenedChecklists, handleStatusChange, handleObservationsChange, handleFileUpload } = useStore();
const { stateFlattenedChecklists, handleStatusChange, handleObservationsChange, handleFileUpload, handleCSVExport } = useStore();


const currentTabStateExportAsJSON = () => {
Expand All @@ -46,12 +39,6 @@ const OWSTG = ({ id }: { id: string }) => {
ImportURI = "3"
};



const handleCSVExport = () => {
console.log("Exporting as CSV");
}

const handleMenuClick: MenuProps['onClick'] = (e) => {
switch (e.key) {
case Actions.ImportLocalFile:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type State = {
handleStatusChange: (id: string, newStatus: ImportedTestCaseStatus) => void;
handleObservationsChange: (id: string, newObservations: string) => void;
handleFileUpload: () => void;
handleCSVExport: () => void;
};

export const initializeChecklist = (checklists: any) => {
Expand Down Expand Up @@ -94,6 +95,19 @@ const createOWSTGStore = (id: string) =>
};
input.click();
},
handleCSVExport: () => {
const data = get().stateFlattenedChecklists.map(({ id, description, reference, testCaseStatus, observations }) => ({
id,
description,
reference,
testCaseStatus,
observations
}));

const csv = Papa.unparse(data);
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
saveAs(blob, `htool_${new Date().toISOString()}_${new Date().getTime()}.csv`);
},
}),
{
name: `methodology-tab-state-${id}`, // unique name
Expand Down

0 comments on commit 39a8ce6

Please sign in to comment.