Skip to content

Commit 70338da

Browse files
authored
Merge pull request #436 from signals-dev/tagOverride
override similar shapes tags
2 parents 830d84f + 2f7d1bd commit 70338da

File tree

6 files changed

+136
-42
lines changed

6 files changed

+136
-42
lines changed

client/src/components/Timeseries/FocusChart/FocusChart.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as d3 from 'd3';
44
import { getIsSimilarShapesActive, getSimilarShapesCoords } from 'src/model/selectors/similarShapes';
55
import { RootState } from '../../../model/types';
66
import { FocusChartConstants, colorSchemes } from './Constants';
7-
// import EventDetails from './EventDetails';
7+
import EventDetails from './EventDetails';
88
import AddEvent from './FocusChartEvents/AddEvent';
99
import ShowErrors from './ShowErrors';
1010
import { setTimeseriesPeriod, setActiveEventAction } from '../../../model/actions/datarun';
@@ -185,10 +185,11 @@ export class FocusChart extends Component<Props, State> {
185185
const shapeWidth = Math.max(xCoord(timeSeries[end][0]) - xCoord(timeSeries[start][0]));
186186
const shapeHeight = height - 3.5 * CHART_MARGIN;
187187
const translateShape = xCoord(timeSeries[start][0]);
188-
188+
const tagColor = colorSchemes[shape.tag] || colorSchemes.Untagged;
189189
return (
190190
<g className="similar-shape" key={start}>
191191
<rect className="evt-area" width={shapeWidth} height={shapeHeight} y={0} x={translateShape} />
192+
<rect className="evt-comment" width={shapeWidth} height="10" y={0} x={translateShape} fill={tagColor} />
192193
</g>
193194
);
194195
}

client/src/components/Timeseries/Sidebar/SidebarComponents/SimilarShapes/SimilarShapes.jsx

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getSimilarShapesAction,
88
saveSimilarShapesAction,
99
resetSimilarShapesAction,
10+
shapesTagsOverrideAction,
1011
} from 'src/model/actions/similarShapes';
1112
import { getCurrentEventDetails, getDatarunDetails, getIsEditingEventRange } from 'src/model/selectors/datarun';
1213
import {
@@ -16,6 +17,7 @@ import {
1617
} from 'src/model/selectors/similarShapes';
1718
import { timestampToDate } from 'src/components/Timeseries/AggregationLevels/AggregationChart/Utils';
1819
import { setActiveEventAction } from 'src/model/actions/datarun';
20+
import Dropdown from 'src/components/Common/Dropdown';
1921

2022
const shapesLanding = () => (
2123
<div className="shapes-landing">
@@ -140,41 +142,44 @@ class SimilarShapes extends Component {
140142
}
141143

142144
if (currentEvent === null) {
143-
return shapesLanding();
145+
return null;
144146
}
145147

146-
return (
147-
<div>
148-
<div className="shape-options" />
149-
{similarShapes.map((currentShape) => {
150-
const { startTime, stopTime, similarity, eventInterval } = this.getShapeDetails(currentShape);
151-
return (
152-
<div className="shape-details" key={currentShape.start}>
153-
<ul className="info">
154-
<li>
155-
<span>Start:</span>
156-
{startTime}
157-
</li>
158-
<li>
159-
<span>End:</span>
160-
{stopTime}
161-
</li>
162-
<li>
163-
<span>Similarity:</span>
164-
<span>{similarity}%</span>
165-
</li>
166-
</ul>
167-
<div className="drawing">
168-
<svg width="210" height="122" className="shape-chart">
169-
<path d={this.drawLine(eventInterval)} />
170-
<path d={this.getCurrentEventShape()} className="current-event-shape" />
171-
</svg>
172-
</div>
173-
</div>
174-
);
175-
})}
176-
</div>
177-
);
148+
return similarShapes.map((currentShape) => {
149+
const { startTime, stopTime, similarity, eventInterval } = this.getShapeDetails(currentShape);
150+
return (
151+
<div className="shape-details" key={currentShape.start}>
152+
<table className="info">
153+
<tbody>
154+
<tr>
155+
<th>Start:</th>
156+
<td>{startTime}</td>
157+
</tr>
158+
<tr>
159+
<th>End:</th>
160+
<td>{stopTime}</td>
161+
</tr>
162+
<tr>
163+
<th>Similarity:</th>
164+
<td>{similarity}%</td>
165+
</tr>
166+
<tr>
167+
<th>Tag</th>
168+
<td>
169+
<Dropdown />
170+
</td>
171+
</tr>
172+
</tbody>
173+
</table>
174+
<div className="drawing">
175+
<svg width="134" height="127" className="shape-chart">
176+
<path d={this.drawLine(eventInterval)} />
177+
<path d={this.getCurrentEventShape()} className="current-event-shape" />
178+
</svg>
179+
</div>
180+
</div>
181+
);
182+
});
178183
}
179184

180185
renderEventData() {
@@ -234,6 +239,25 @@ class SimilarShapes extends Component {
234239
setActiveEvent(null);
235240
}
236241

242+
shapeTagOverride() {
243+
const { overrideAllTags } = this.props;
244+
return (
245+
<div className="shape-form overwrite">
246+
<div className="form-row">
247+
<div className="form-wrapper ">
248+
<p>Override all segments tags</p>
249+
<p className="recent">5 most similar segments</p>
250+
</div>
251+
<div className="form-wrapper">
252+
<div className="shape-options">
253+
<Dropdown onChange={(tag) => overrideAllTags(tag.value)} />
254+
</div>
255+
</div>
256+
</div>
257+
</div>
258+
);
259+
}
260+
237261
renderSearchControls() {
238262
const { currentEvent, getSimilarShapes, similarShapes, isSimilarShapesLoading, isEditingEventRange } = this.props;
239263
const isSearchDisabled =
@@ -243,7 +267,7 @@ class SimilarShapes extends Component {
243267
}
244268

245269
if (similarShapes.length) {
246-
return null;
270+
return this.shapeTagOverride();
247271
}
248272

249273
return (
@@ -311,5 +335,6 @@ export default connect(
311335
saveShapes: () => dispatch(saveSimilarShapesAction()),
312336
setActiveEvent: (eventID) => dispatch(setActiveEventAction(eventID)),
313337
resetSimilarShapes: () => dispatch(resetSimilarShapesAction()),
338+
overrideAllTags: (tag) => dispatch(shapesTagsOverrideAction(tag)),
314339
}),
315340
)(SimilarShapes);

client/src/components/Timeseries/Sidebar/SidebarComponents/SimilarShapes/SimilarShapes.scss

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@
130130
}
131131
}
132132

133+
.shape-form {
134+
&.overwrite {
135+
.form-row {
136+
padding-bottom: 0;
137+
p.recent {
138+
padding-top: 20px;
139+
color: rgba(#fff, 0.4);
140+
}
141+
}
142+
}
143+
}
144+
133145
.submit {
134146
width: 65%;
135147
float: right;
@@ -159,7 +171,7 @@
159171
}
160172

161173
.shapes-results {
162-
max-height: 45vh;
174+
max-height: 35vh;
163175
overflow-y: auto;
164176
margin-bottom: 10px;
165177
}
@@ -198,7 +210,31 @@
198210
}
199211
}
200212
}
213+
214+
table {
215+
td,
216+
th {
217+
padding-bottom: 7px;
218+
}
219+
220+
tr {
221+
&:last-child {
222+
td,
223+
th {
224+
padding-bottom: 0px;
225+
}
226+
}
227+
}
228+
229+
th {
230+
text-align: left;
231+
font-weight: normal;
232+
color: #b5b5b5;
233+
padding-right: 20px;
234+
}
235+
}
201236
}
237+
202238
.shape-chart {
203239
path {
204240
fill: transparent;
@@ -222,7 +258,7 @@
222258
left: 1px;
223259
right: 1px;
224260
margin: 0 auto;
225-
bottom: 2px;
261+
bottom: 1px;
226262
button {
227263
color: #fff;
228264
text-transform: uppercase;

client/src/model/actions/similarShapes.ts

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { TOGGLE_SIMILAR_SHAPES_MODAL, FETCH_SIMILAR_SHAPES, UPDATE_DATARUN_EVENTS } from '../types';
1+
import {
2+
TOGGLE_SIMILAR_SHAPES_MODAL,
3+
FETCH_SIMILAR_SHAPES,
4+
UPDATE_DATARUN_EVENTS,
5+
UPDATE_SIMILAR_SHAPES,
6+
UPDATE_EVENT_DETAILS,
7+
} from '../types';
28
import { getCurrentEventDetails, getDatarunDetails } from '../selectors/datarun';
39
import API from '../utils/api';
4-
import { getSimilarShapesCoords } from '../selectors/similarShapes';
10+
import { getSimilarShapesCoords, getSimilarShapesFound } from '../selectors/similarShapes';
511
import { getSelectedExperimentData } from '../selectors/experiment';
12+
import { saveEventDetailsAction } from './datarun';
613

714
export function toggleSimilarShapesAction(modalState) {
815
return async function (dispatch) {
@@ -49,8 +56,8 @@ function saveNewShape(currentShape) {
4956
const shapePayload = {
5057
start_time: timeSeries[start][0] / 1000,
5158
stop_time: timeSeries[end][0] / 1000,
52-
score: '0.00', // @TODO - add this data and the one below
53-
tag: 'Untagged',
59+
score: '0.00', // @TODO - add this data
60+
tag: currentShape.tag || 'Untagged',
5461
datarun_id: dataRun.id,
5562
};
5663

@@ -72,5 +79,24 @@ export function saveSimilarShapesAction() {
7279
// @TODO - backend should provide a single endpoint, single API call instead of 5
7380
const currentShapes = getSimilarShapesCoords(getState());
7481
currentShapes.map((current) => dispatch(saveNewShape(current)));
82+
dispatch(saveEventDetailsAction());
83+
};
84+
}
85+
86+
export function shapesTagsOverrideAction(tag) {
87+
return function (dispatch, getState) {
88+
const currentShapes = getSimilarShapesFound(getState());
89+
const updatedShapes = currentShapes.map((current) => ({ ...current, tag }));
90+
const currentEvent = getCurrentEventDetails(getState());
91+
92+
dispatch({
93+
type: UPDATE_EVENT_DETAILS,
94+
eventDetails: { ...currentEvent, tag },
95+
});
96+
97+
dispatch({
98+
type: UPDATE_SIMILAR_SHAPES,
99+
shapes: updatedShapes,
100+
});
75101
};
76102
}

client/src/model/reducers/similarShapes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ function RESET_SIMILAR_SHAPES(nextState) {
2323
nextState.similarShapes = [];
2424
}
2525

26+
function UPDATE_SIMILAR_SHAPES(nextState, { shapes }) {
27+
nextState.similarShapes = shapes;
28+
}
29+
2630
export default createReducer(initialState, {
2731
TOGGLE_SIMILAR_SHAPES_MODAL,
2832
FETCH_SIMILAR_SHAPES_SUCCESS,
2933
FETCH_SIMILAR_SHAPES_REQUEST,
3034
RESET_SIMILAR_SHAPES,
35+
UPDATE_SIMILAR_SHAPES,
3136
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export const TOGGLE_SIMILAR_SHAPES_MODAL = 'TOGGLE_SIMILAR_SHAPES_MODAL';
22
export const FETCH_SIMILAR_SHAPES = 'FETCH_SIMILAR_SHAPES';
3+
export const UPDATE_SIMILAR_SHAPES = 'UPDATE_SIMILAR_SHAPES';

0 commit comments

Comments
 (0)