Skip to content

Commit e9e8b88

Browse files
committed
always pass rawData from file and data
1 parent 436e6c4 commit e9e8b88

16 files changed

+185
-50
lines changed

src/Components/Actions/ExportHarButton.jsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import Button from '../Common/Button';
66
import Styles from './IconButton.styles.scss';
77
import IconDownload from '../../icons/IconDownload';
88
import Tooltip from '../Common/Tooltip/Tooltip';
9+
import { EMPTY_NETWORK_HAR } from '../../constants';
910

1011
const ExportHarButton = ({ rawData }) => {
1112
const downloadHar = () => {
12-
const formattedHar = JSON.stringify(rawData, null, 4);
13+
const formattedHar = JSON.stringify(rawData, null, 2);
1314

1415
FileSaver.saveAs(new Blob([formattedHar]), 'network.har');
1516
};
@@ -27,11 +28,11 @@ const ExportHarButton = ({ rawData }) => {
2728
};
2829

2930
ExportHarButton.propTypes = {
30-
rawData: PropTypes.string,
31+
rawData: PropTypes.object,
3132
};
3233

3334
ExportHarButton.defaultProps = {
34-
rawData: '',
35+
rawData: EMPTY_NETWORK_HAR,
3536
};
3637

3738
export default ExportHarButton;

src/Containers/FilterContainer.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ const FilterContainer = () => {
2424
<div className={Styles['filter-row']}>
2525
<StatusFilter />
2626
<Search {...state.get('search')} />
27-
{showPauseResume && <PauseResumeButton {...state.get('rawData')} />}
27+
{showPauseResume && <PauseResumeButton />}
2828
<ResetButton />
29-
{showExportHar && <ExportHarButton />}
29+
{showExportHar && <ExportHarButton rawData={state.get('rawData')} />}
3030
{showImportHar && <ImportHAR />}
3131
</div>
3232

src/constants.js

+12
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,15 @@ export const PAYLOAD_CAPTIONS = Object.freeze({
264264
false: 'parsed',
265265
}),
266266
});
267+
268+
export const EMPTY_NETWORK_HAR = Object.freeze({
269+
log: {
270+
version: '',
271+
creator: {
272+
name: '',
273+
version: '',
274+
},
275+
entries: [],
276+
pages: [],
277+
},
278+
});

src/state/network/NetworkProvider.jsx

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ const NetworkProvider = (props) => {
2424
} = props;
2525

2626
const [state, dispatch] = useReducer(reducer, initialState);
27-
const callbacks = { onPause, onResume, onReset };
27+
const callbacks = {
28+
onPause,
29+
onResume,
30+
onReset,
31+
};
2832
const value = useMemo(() => [state, dispatch, callbacks], [state]);
2933
const selectedReqIndex = value[0].get('selectedReqIndex');
3034
const requestData = value[0].get('data');
@@ -35,10 +39,7 @@ const NetworkProvider = (props) => {
3539
// Update data onChange of network data
3640
useEffect(() => {
3741
if (data && data.log && data.log.entries) {
38-
updateData(dispatch)({
39-
entries: data.log.entries,
40-
pages: data.log.pages,
41-
});
42+
updateData(dispatch)(data);
4243
}
4344
}, [data]);
4445

src/state/network/actions.js

+15-8
Original file line numberDiff line numberDiff line change
@@ -28,39 +28,46 @@ export const updateTypeFilter = (dispatch) => (payload) => dispatch({
2828
});
2929

3030
export const fetchFileRequest = (dispatch) => (payload) => dispatch({
31-
type: types.FETCH_FILE.REQUEST, payload,
31+
type: types.FETCH_FILE.REQUEST,
32+
payload,
3233
});
3334

3435
export const fetchFileSuccess = (dispatch) => (payload) => dispatch({
35-
type: types.FETCH_FILE.SUCCESS, payload,
36+
type: types.FETCH_FILE.SUCCESS,
37+
payload,
3638
});
3739

3840
export const fetchFileFailure = (dispatch) => (payload) => dispatch({
39-
type: types.FETCH_FILE.FAILURE, payload,
41+
type: types.FETCH_FILE.FAILURE,
42+
payload,
4043
});
4144

4245
export const updateErrorMessage = (dispatch) => (payload) => dispatch({
43-
type: types.UPDATE_ERROR_MESSAGE, payload,
46+
type: types.UPDATE_ERROR_MESSAGE,
47+
payload,
4448
});
4549

4650
export const updateScrollToIndex = (dispatch) => (payload) => dispatch({
47-
type: types.UPDATE_SCROLL_TO_INDEX, payload,
51+
type: types.UPDATE_SCROLL_TO_INDEX,
52+
payload,
4853
});
4954

5055
export const selectRequest = (dispatch) => (payload) => dispatch({
51-
type: types.SELECT_REQUEST, payload,
56+
type: types.SELECT_REQUEST,
57+
payload,
5258
});
5359

5460
export const resetState = (dispatch) => (payload) => dispatch({
55-
type: types.RESET, payload,
61+
type: types.RESET,
62+
payload,
5663
});
5764

5865
export const fetchFile = (dispatch) => (file, options = { withCredentials: true }) => {
5966
fetchFileRequest(dispatch)();
6067
axios.get(file, options)
6168
.then(({ data }) => {
6269
if (data && data.log) {
63-
updateData(dispatch)(data.log);
70+
updateData(dispatch)(data);
6471
}
6572
fetchFileSuccess(dispatch)();
6673
})

src/state/network/reducer.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { Map, List } from 'immutable';
22

33
import { filterData, sortBy, prepareViewerData, calculateTimings, getSummary } from './../../utils';
44
import * as types from './types';
5-
import { DEFAULT_STATUS_FILTER } from '../../constants';
5+
import { DEFAULT_STATUS_FILTER, EMPTY_NETWORK_HAR } from '../../constants';
66

77
const initialState = new Map({
8-
rawData: null,
8+
rawData: EMPTY_NETWORK_HAR,
99
data: new List(),
1010
actualData: new List(),
1111
totalNetworkTime: null,
@@ -46,12 +46,12 @@ const reducer = (state = initialState, {
4646
totalTransferredSize,
4747
totalUncompressedSize,
4848
finishTime,
49-
} = prepareViewerData(payload.entries);
49+
} = prepareViewerData(payload.log.entries);
5050
const filteredData = filterData({
5151
data,
5252
statusFilter: state.get('statusFilter'),
5353
typeFilter: state.get('typeFilter'),
54-
search: payload,
54+
search: state.get('search'),
5555
});
5656
const sortedData = new List(sortBy(filteredData, sort.key, sort.isAcs));
5757
newState
@@ -65,7 +65,7 @@ const reducer = (state = initialState, {
6565
totalTransferredSize,
6666
totalUncompressedSize,
6767
finishTime,
68-
timings: calculateTimings(payload.pages),
68+
timings: calculateTimings(payload.log.pages),
6969
finish: finishTime,
7070
}));
7171
});

tests/__tests__/Components/Filters/__snapshots__/Search.spec.jsx.snap

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ exports[`Search renders without crashing 1`] = `
3030
"name": null,
3131
"value": null,
3232
},
33-
"rawData": null,
33+
"rawData": Object {
34+
"log": Object {
35+
"creator": Object {
36+
"name": "",
37+
"version": "",
38+
},
39+
"entries": Array [],
40+
"pages": Array [],
41+
"version": "",
42+
},
43+
},
3444
"totalNetworkTime": null,
3545
"actualData": Immutable.List [],
3646
"dataSummary": Immutable.Map {},

tests/__tests__/Components/Import/__snapshots__/ImportHar.spec.jsx.snap

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ exports[`ImportHAR renders without crashing 1`] = `
3030
"name": null,
3131
"value": null,
3232
},
33-
"rawData": null,
33+
"rawData": Object {
34+
"log": Object {
35+
"creator": Object {
36+
"name": "",
37+
"version": "",
38+
},
39+
"entries": Array [],
40+
"pages": Array [],
41+
"version": "",
42+
},
43+
},
3444
"totalNetworkTime": null,
3545
"actualData": Immutable.List [],
3646
"dataSummary": Immutable.Map {},

tests/__tests__/Containers/__snapshots__/FilterContainer.spec.jsx.snap

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ exports[`FilterContainer renders without crashing 1`] = `
3030
"name": null,
3131
"value": null,
3232
},
33-
"rawData": null,
33+
"rawData": Object {
34+
"log": Object {
35+
"creator": Object {
36+
"name": "",
37+
"version": "",
38+
},
39+
"entries": Array [],
40+
"pages": Array [],
41+
"version": "",
42+
},
43+
},
3444
"totalNetworkTime": null,
3545
"actualData": Immutable.List [],
3646
"dataSummary": Immutable.Map {},

tests/__tests__/Containers/__snapshots__/MainContainer.spec.jsx.snap

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ exports[`MainContainer renders without crashing 1`] = `
3030
"name": null,
3131
"value": null,
3232
},
33-
"rawData": null,
33+
"rawData": Object {
34+
"log": Object {
35+
"creator": Object {
36+
"name": "",
37+
"version": "",
38+
},
39+
"entries": Array [],
40+
"pages": Array [],
41+
"version": "",
42+
},
43+
},
3444
"totalNetworkTime": null,
3545
"actualData": Immutable.List [],
3646
"dataSummary": Immutable.Map {},

tests/__tests__/Containers/__snapshots__/NetworkTableContainer.spec.jsx.snap

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ exports[`NetworkTableContainer renders without crashing 1`] = `
3030
"name": null,
3131
"value": null,
3232
},
33-
"rawData": null,
33+
"rawData": Object {
34+
"log": Object {
35+
"creator": Object {
36+
"name": "",
37+
"version": "",
38+
},
39+
"entries": Array [],
40+
"pages": Array [],
41+
"version": "",
42+
},
43+
},
3444
"totalNetworkTime": null,
3545
"actualData": Immutable.List [],
3646
"dataSummary": Immutable.Map {},

tests/__tests__/Containers/__snapshots__/ReqDetailContainer.spec.jsx.snap

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ exports[`ReqDetailContainer renders without crashing 1`] = `
3030
"name": null,
3131
"value": null,
3232
},
33-
"rawData": null,
33+
"rawData": Object {
34+
"log": Object {
35+
"creator": Object {
36+
"name": "",
37+
"version": "",
38+
},
39+
"entries": Array [],
40+
"pages": Array [],
41+
"version": "",
42+
},
43+
},
3444
"totalNetworkTime": null,
3545
"actualData": Immutable.List [],
3646
"dataSummary": Immutable.Map {},

tests/__tests__/Containers/__snapshots__/TimelineContainer.spec.jsx.snap

+11-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ exports[`TimelineContainer renders without crashing 1`] = `
3030
"name": null,
3131
"value": null,
3232
},
33-
"rawData": null,
33+
"rawData": Object {
34+
"log": Object {
35+
"creator": Object {
36+
"name": "",
37+
"version": "",
38+
},
39+
"entries": Array [],
40+
"pages": Array [],
41+
"version": "",
42+
},
43+
},
3444
"totalNetworkTime": null,
3545
"actualData": Immutable.List [],
3646
"dataSummary": Immutable.Map {},

tests/__tests__/__snapshots__/NetworkViewer.spec.jsx.snap

+11-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,17 @@ exports[`renders without crashing 1`] = `
3636
"name": null,
3737
"value": null,
3838
},
39-
"rawData": null,
39+
"rawData": Object {
40+
"log": Object {
41+
"creator": Object {
42+
"name": "",
43+
"version": "",
44+
},
45+
"entries": Array [],
46+
"pages": Array [],
47+
"version": "",
48+
},
49+
},
4050
"totalNetworkTime": null,
4151
"actualData": Immutable.List [],
4252
"dataSummary": Immutable.Map {},

tests/__tests__/state/__snapshots__/NetworkProvider.spec.jsx.snap

+22-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ exports[`NetworkProvider renders without crashing 1`] = `
3030
"name": null,
3131
"value": null,
3232
},
33-
"rawData": null,
33+
"rawData": Object {
34+
"log": Object {
35+
"creator": Object {
36+
"name": "",
37+
"version": "",
38+
},
39+
"entries": Array [],
40+
"pages": Array [],
41+
"version": "",
42+
},
43+
},
3444
"totalNetworkTime": null,
3545
"actualData": Immutable.List [],
3646
"dataSummary": Immutable.Map {},
@@ -69,7 +79,17 @@ exports[`NetworkProvider renders without crashing 1`] = `
6979
"name": null,
7080
"value": null,
7181
},
72-
"rawData": null,
82+
"rawData": Object {
83+
"log": Object {
84+
"creator": Object {
85+
"name": "",
86+
"version": "",
87+
},
88+
"entries": Array [],
89+
"pages": Array [],
90+
"version": "",
91+
},
92+
},
7393
"totalNetworkTime": null,
7494
"actualData": Immutable.List [],
7595
"dataSummary": Immutable.Map {},

0 commit comments

Comments
 (0)