Skip to content

Commit ab3d8b9

Browse files
committed
Added Delete bSeries button to Comparison Bargraph
1 parent 9382c4d commit ab3d8b9

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

src/app/actions/actions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export const save = (tabsObj) => ({
55
type: types.SAVE,
66
payload: tabsObj,
77
});
8-
8+
export const deleteSeries = () =>({
9+
type: types.DELETE_SERIES,
10+
})
911
export const toggleMode = (mode) => ({
1012
type: types.TOGGLE_MODE,
1113
payload: mode,

src/app/components/BarGraphComparison.tsx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @ts-nocheck
2-
import React, { useEffect } from 'react';
2+
import React, { useEffect, useForceUpdate } from 'react';
33
import { BarStack } from '@visx/shape';
44
import { SeriesPoint } from '@visx/shape/lib/types';
55
import { Group } from '@visx/group';
@@ -19,7 +19,8 @@ import FormHelperText from '@material-ui/core/FormHelperText';
1919
import snapshots from './snapshots';
2020
import { onHover, onHoverExit } from '../actions/actions';
2121
import { useStoreContext } from '../store';
22-
// import { save } from '../actions/actions';
22+
import { deleteSeries } from '../actions/actions';
23+
2324
/* TYPESCRIPT */
2425
interface data {
2526
snapshotId?: string;
@@ -192,6 +193,19 @@ const BarGraphComparison = (props) => {
192193
});
193194
return data.barStack;
194195
}
196+
const animateButton = function (e) {
197+
e.preventDefault;
198+
e.target.classList.add('animate');
199+
e.target.innerHTML = 'Deleted!';
200+
setTimeout(function () {
201+
e.target.innerHTML = 'Clear Series';
202+
e.target.classList.remove('animate');
203+
}, 1000);
204+
};
205+
const classname = document.getElementsByClassName('delete-button');
206+
for (let i = 0; i < classname.length; i++) {
207+
classname[i].addEventListener('click', animateButton, false);
208+
}
195209
//console.log('set x on current bar', setXpointsCurrentTab());
196210
return (
197211
<div>
@@ -201,7 +215,15 @@ const BarGraphComparison = (props) => {
201215
Snapshot ID: {currentIndex + 1}{' '}
202216
</div>
203217

204-
<div className='dropdown-and-save-series-container'>
218+
<div className='dropdown-and-delete-series-container'>
219+
<button
220+
className='delete-button'
221+
onClick={(e) => {
222+
dispatch(deleteSeries());
223+
}}
224+
>
225+
Clear Series
226+
</button>
205227
<FormControl variant='outlined' className={classes.formControl}>
206228
<Select
207229
style={{ color: 'white' }}

src/app/constants/actionTypes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export const SLIDER_ZERO = 'SLIDER_ZERO';
1616
export const ON_HOVER = 'ON_HOVER';
1717
export const ON_HOVER_EXIT = 'ON_HOVER_EXIT';
1818
export const SAVE = 'SAVE';
19+
export const DELETE_SERIES = 'DELETE_SERIES';

src/app/reducers/mainReducer.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,32 @@ export default (state, action) =>
2929
}
3030
}
3131
};
32-
32+
3333
switch (action.type) {
3434
case types.SAVE: {
3535
const data = JSON.stringify(action.payload);
3636
localStorage.setItem(`${action.payload.currentTab}`, data);
3737
break;
3838
}
39+
case types.DELETE_SERIES: {
40+
//localStorage.deleteSeries
41+
console.log('we are in the delete series reducer');
42+
const allStorage = () => {
43+
const keys = Object.keys(localStorage);
44+
let i = keys.length;
45+
while (i--) {
46+
localStorage.removeItem(keys[i]);
47+
}
48+
//return values;
49+
};
50+
allStorage();
3951

52+
Object.keys(tabs).forEach((tab) => {
53+
tabs[tab] = {
54+
...tabs[tab],
55+
};
56+
});
57+
}
4058
case types.ON_HOVER_EXIT: {
4159
port.postMessage({
4260
action: 'onHoverExit',

src/app/styles/components/_buttons.scss

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,31 @@
1919
position: absolute;
2020
right: 2.5rem;
2121

22-
&.animate {
22+
&.animate {
2323
background: rgb(41, 164, 41);
2424
}
25+
}
26+
.delete-button {
27+
padding: 3px;
28+
outline: transparent;
29+
color: white;
30+
display: flex;
31+
justify-content: center;
32+
align-items: center;
33+
border-style: solid;
34+
border-color: transparent;
35+
border-radius: 3px;
36+
cursor: pointer;
37+
line-height: 1.5em;
38+
font: 300 14px 'Roboto', sans-serif;
39+
font-size: $button-text-size;
40+
width: 120px;
41+
background: $red-color-gradient;
42+
height: 30px;
2543

44+
&.animate {
45+
background: rgb(41, 164, 41);
46+
}
2647
}
2748

2849
.empty-button {
@@ -253,7 +274,7 @@
253274
.snapshotId-header {
254275
font-size: 1rem;
255276
}
256-
.dropdown-and-save-series-container {
277+
.dropdown-and-delete-series-container {
257278
display: flex;
258279
align-items: center;
259280
}

0 commit comments

Comments
 (0)