Skip to content

Commit ccac11d

Browse files
authored
Merge pull request #1218 from nyaruka/warnings
Add support to the simulator to display warnings
2 parents c7b7ddc + 6b14088 commit ccac11d

File tree

4 files changed

+65
-7
lines changed

4 files changed

+65
-7
lines changed

src/components/simulator/LogEvent.module.scss

+19-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
transform: scale(0.2);
66
opacity: 0;
77
}
8+
89
to {
910
transform: scale(1);
1011
opacity: 1;
@@ -20,6 +21,7 @@
2021
.msg_text {
2122
padding: 8px 15px;
2223
}
24+
2325
.ivr_msg,
2426
.send_msg {
2527
border-radius: 10px;
@@ -50,6 +52,16 @@
5052
}
5153
}
5254

55+
.warning {
56+
float: inherit;
57+
color: $yellow;
58+
font-size: 11px;
59+
border: none;
60+
text-align: center;
61+
padding: 10px 15px;
62+
border-radius: 11px;
63+
}
64+
5365
.error {
5466
float: inherit;
5567
color: $red;
@@ -72,6 +84,7 @@
7284
.email {
7385
text-decoration: underline;
7486
cursor: pointer;
87+
7588
&:hover {
7689
color: #999;
7790
}
@@ -81,6 +94,7 @@
8194
word-break: break-all;
8295
text-decoration: underline;
8396
cursor: pointer;
97+
8498
&:hover {
8599
color: #999;
86100
}
@@ -145,12 +159,14 @@
145159
white-space: -pre-wrap;
146160
white-space: -o-pre-wrap;
147161
word-wrap: break-word;
162+
148163
::first-line {
149164
font-family: 'Roboto', sans-serif;
150165
font-size: 16px;
151166
font-weight: 400;
152167
line-height: 34px;
153168
}
169+
154170
.response {
155171
padding-top: 20px;
156172
}
@@ -182,11 +198,13 @@
182198
width: 100%;
183199
font-size: 90%;
184200
color: #bbb;
201+
185202
td {
186203
padding: 0 5px;
187204
}
205+
188206
td:last-child {
189207
text-align: right;
190208
font-size: 90%;
191209
}
192-
}
210+
}

src/components/simulator/LogEvent.test.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ describe(LogEvent.name, () => {
101101
...commonEventProps
102102
});
103103
});
104+
it('should render warning event', () => {
105+
testEventRender({
106+
type: 'warning',
107+
text: "I'm an warning",
108+
...commonEventProps
109+
});
110+
});
104111
it('should render error event', () => {
105112
testEventRender({
106113
type: 'error',

src/components/simulator/LogEvent.tsx

+20-6
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ const getStyleForDirection = (direction: Direction): string => {
101101
return direction === Direction.MO ? styles.msg_received : styles.send_msg;
102102
};
103103

104+
const renderWarning = (warning: string): JSX.Element => {
105+
return (
106+
<div className={styles.warning}>
107+
<span>Warning: {warning}</span>
108+
</div>
109+
);
110+
};
111+
104112
const renderError = (error: string): JSX.Element => {
105113
return (
106114
<div className={styles.error}>
@@ -109,6 +117,10 @@ const renderError = (error: string): JSX.Element => {
109117
);
110118
};
111119

120+
const renderInfoStyles = (allStyles: any[]): string => {
121+
return allStyles.join(' ');
122+
};
123+
112124
const renderInfo = (info: string, extraStyles?: any[]): JSX.Element => {
113125
// localized text can have html entities, so this isn't as dangerous as it looks
114126
const infoStyle = [styles.info];
@@ -120,9 +132,6 @@ const renderInfo = (info: string, extraStyles?: any[]): JSX.Element => {
120132
</div>
121133
);
122134
};
123-
const renderInfoStyles = (allStyles: any[]): string => {
124-
return allStyles.join(' ');
125-
};
126135

127136
const renderAttachment = (attachment: string): JSX.Element => {
128137
const idx = attachment.indexOf(':');
@@ -381,6 +390,8 @@ export default class LogEvent extends React.Component<EventProps, LogEventState>
381390
return renderMessage(this.props.msg.text, this.props.msg.attachments, Direction.MT);
382391
case 'ivr_created':
383392
return renderMessage(this.props.msg.text, this.props.msg.attachments, Direction.MT);
393+
case 'warning':
394+
return renderWarning(this.props.text);
384395
case 'error':
385396
return renderError(this.props.text);
386397
case 'failure':
@@ -391,7 +402,7 @@ export default class LogEvent extends React.Component<EventProps, LogEventState>
391402
return this.renderGroupsChanged();
392403
case 'contact_urns_changed':
393404
return renderInfo('Added a URN for the contact');
394-
case 'contact_field_changed':
405+
case 'contact_field_changed': {
395406
const value = this.getValue(this.props.value);
396407
if (value !== '') {
397408
return renderInfo(
@@ -407,6 +418,7 @@ export default class LogEvent extends React.Component<EventProps, LogEventState>
407418
})
408419
);
409420
}
421+
}
410422
case 'run_result_changed':
411423
return renderInfo(
412424
i18n.t('simulator.run_result_changed', 'Set result "[[field]]" to "[[value]]"', {
@@ -423,9 +435,10 @@ export default class LogEvent extends React.Component<EventProps, LogEventState>
423435
case 'email_created':
424436
case 'email_sent':
425437
return this.renderEmailSent();
426-
case 'broadcast_created':
438+
case 'broadcast_created': {
427439
const translation = this.props.translations[this.props.base_language];
428440
return renderMessage(translation.text, translation.attachments, Direction.MT);
441+
}
429442
case 'resthook_called':
430443
return renderInfo(
431444
i18n.t('simulator.resthook_called', 'Triggered flow event "[[resthook]]"', {
@@ -475,7 +488,7 @@ export default class LogEvent extends React.Component<EventProps, LogEventState>
475488
topic: this.props.ticket.topic.name
476489
})
477490
);
478-
case 'airtime_transferred':
491+
case 'airtime_transferred': {
479492
const event = this.props as AirtimeTransferEvent;
480493
return (
481494
<>
@@ -494,6 +507,7 @@ export default class LogEvent extends React.Component<EventProps, LogEventState>
494507
)}
495508
</>
496509
);
510+
}
497511
}
498512

499513
// should only get here if we are get an unexpected event

src/components/simulator/__snapshots__/LogEvent.test.tsx.snap

+19
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,22 @@ exports[`LogEvent should render ticket_opened event 1`] = `
406406
</div>
407407
</body>
408408
`;
409+
410+
exports[`LogEvent should render warning event 1`] = `
411+
<body>
412+
<div>
413+
<div
414+
class="evt"
415+
>
416+
<div
417+
class="warning"
418+
>
419+
<span>
420+
Warning:
421+
I'm an warning
422+
</span>
423+
</div>
424+
</div>
425+
</div>
426+
</body>
427+
`;

0 commit comments

Comments
 (0)