Skip to content

Commit 4cdd7bf

Browse files
committed
Add better sizing of errors, use Inter font family
1 parent b6b421e commit 4cdd7bf

File tree

8 files changed

+116
-73
lines changed

8 files changed

+116
-73
lines changed

dash/dash-renderer/src/DashRenderer.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ import AppProvider from './AppProvider.react';
55

66
class DashRenderer {
77
constructor(hooks) {
8+
// TODO: move this to a more appropriate place?
9+
const head = document.head;
10+
const link1 = document.createElement('link');
11+
link1.rel = 'preconnect';
12+
link1.href = 'https://fonts.googleapis.com';
13+
head.appendChild(link1);
14+
15+
const link2 = document.createElement('link');
16+
link2.rel = 'preconnect';
17+
link2.href = 'https://fonts.gstatic.com';
18+
link2.crossorigin = true;
19+
head.appendChild(link2);
20+
21+
const link3 = document.createElement('link');
22+
link3.href =
23+
'https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap';
24+
link3.rel = 'stylesheet';
25+
head.appendChild(link3);
26+
827
// render Dash Renderer upon initialising!
928
const container = document.getElementById('react-entry-point');
1029

dash/dash-renderer/src/components/core/Toolbar.css

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,12 @@
66
text-align: center;
77
z-index: 9999;
88
background-color: rgba(255, 255, 255, 0.9);
9-
109
}
11-
._dash-undo-redo>div {
10+
._dash-undo-redo > div {
1211
position: relative;
1312
}
1413
._dash-undo-redo-link {
15-
color: #0074D9;
14+
color: #0074d9;
1615
cursor: pointer;
1716
margin-left: 10px;
1817
margin-right: 10px;

dash/dash-renderer/src/components/error/CallbackGraph/CallbackGraphContainer.css

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.dash-callback-dag--container {
22
border-radius: 4px;
3-
position: fixed;
4-
bottom: 165px;
5-
right: 16px;
3+
position: absolute;
4+
bottom: calc(100% + 4px);
5+
right: 0;
66
width: 80vw;
77
height: calc(100vh - 180px);
88
overflow: auto;
@@ -25,9 +25,9 @@
2525
max-height: 50%;
2626
overflow: auto;
2727
box-sizing: border-box;
28-
background: rgba(255,255,255,0.9);
28+
background: rgba(255, 255, 255, 0.9);
2929
border: 2px solid #ccc;
30-
font-family: "Arial", sans-serif;
30+
font-family: 'Arial', sans-serif;
3131
}
3232

3333
.dash-callback-dag--message {
@@ -37,7 +37,7 @@
3737
align-items: center;
3838
height: 100%;
3939
line-height: 2em;
40-
font-family: "Arial", sans-serif;
40+
font-family: 'Arial', sans-serif;
4141
}
4242

4343
.dash-callback-dag--layoutSelector {

dash/dash-renderer/src/components/error/FrontEnd/FrontEndError.css

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,27 @@
66
position: absolute;
77
right: 0;
88
top: 0;
9-
color: #B9C2CE;
9+
color: #b9c2ce;
1010
font-size: 20px;
1111
cursor: pointer;
12-
margin-right: 10px
12+
margin-right: 10px;
1313
}
1414

1515
.dash-debug-menu__upgrade-button {
16-
background-color: #A159FF0D;
17-
border: 1px solid #864AD433;
18-
color: #7F4BC4;
16+
background-color: #a159ff0d;
17+
border: 1px solid #864ad433;
18+
color: #7f4bc4;
1919
margin-left: 10px;
2020
}
2121

2222
.dash-debug-menu__upgrade-button:hover {
23-
background-color: #864AD433;
23+
background-color: #864ad433;
2424
}
2525

26-
.dash-fe-error__icon-x:hover
27-
{
28-
color:#a1a9b5;
26+
.dash-fe-error__icon-x:hover {
27+
color: #a1a9b5;
2928
}
3029

31-
3230
.dash-fe-errors {
3331
min-width: 386px;
3432
max-width: 650px;
@@ -58,7 +56,7 @@
5856
.dash-debug-menu__error-count {
5957
font-size: 12px;
6058
color: #fff;
61-
background-color: #C73A3A;
59+
background-color: #c73a3a;
6260
padding: 3px 5px;
6361
border-radius: 3px;
6462
margin: 0 5px;
@@ -131,7 +129,7 @@
131129
.dash-fe-error__curved-bottom {
132130
border-radius-bottom-left: 4px;
133131
border-radius-bottom-right: 4px;
134-
background-color: #FFEFEF;
132+
background-color: #ffefef;
135133
}
136134

137135
.dash-be-error__st {
@@ -152,7 +150,6 @@
152150
white-space: pre-wrap;
153151
}
154152

155-
156153
.dash-error-menu {
157154
max-width: 50%;
158155
max-height: 60%;
@@ -197,15 +194,17 @@
197194
margin-bottom: 7px;
198195
background-color: white;
199196
overflow: auto;
200-
z-index: 1100; /* above the plotly.js toolbar and Bootstrap components */
201-
box-shadow: 0 0 15px 6px #0000000D;
197+
z-index: 1100; /* above the plotly.js toolbar and Bootstrap components */
198+
box-shadow: 0 0 15px 6px #0000000d;
202199
}
203200

204201
.dash-error-card__topbar {
205202
width: 100%;
206203
height: 32px;
207204
display: flex;
208-
justify-content: center;
205+
justify-content: flex-start;
206+
font-family: Inter;
207+
font-size: 14px;
209208
align-items: center;
210209
position: relative;
211210
}
@@ -221,8 +220,10 @@
221220
box-sizing: border-box;
222221
background-color: white;
223222
border-radius: 2px;
224-
margin-bottom: 8px;
225-
border: 1px solid #0018661A;
223+
margin-bottom: 15px;
224+
border: 1px solid #0018661a;
225+
font-family: Menlo;
226+
font-size: 12.6px;
226227
}
227228

228229
.dash-fe-error-item {
@@ -231,9 +232,7 @@
231232
display: flex;
232233
justify-content: space-between;
233234
align-items: center;
234-
border: 1px solid #0018661A;
235235
padding: 10px;
236-
margin: 10px 0;
237236
cursor: pointer;
238237
}
239238

dash/dash-renderer/src/components/error/FrontEnd/FrontEndError.react.js

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {connect} from 'react-redux';
22
import './FrontEndError.css';
3-
import {Component} from 'react';
3+
import {Component, useRef, useState, useEffect} from 'react';
44
import CollapseIcon from '../icons/CollapseIcon.svg';
55
import PropTypes from 'prop-types';
66
import '../Percy.css';
@@ -57,17 +57,68 @@ class FrontEndError extends Component {
5757
</div>
5858
);
5959

60-
return collapsed ? (
61-
<>{errorHeader}</>
62-
) : (
60+
return (
6361
<div className={cardClasses}>
6462
{errorHeader}
65-
<ErrorContent error={e.error} />
63+
{!collapsed && <ErrorContent error={e.error} />}
6664
</div>
6765
);
6866
}
6967
}
7068

69+
function BackendError({error, base}) {
70+
const iframeRef = useRef(null);
71+
const [height, setHeight] = useState('500px'); // Default height
72+
73+
useEffect(() => {
74+
const handleMessage = event => {
75+
if (
76+
event.data &&
77+
typeof event.data === 'object' &&
78+
event.data.type === 'IFRAME_HEIGHT'
79+
) {
80+
setHeight(`${event.data.height}px`);
81+
}
82+
};
83+
84+
window.addEventListener('message', handleMessage);
85+
return () => window.removeEventListener('message', handleMessage);
86+
}, []);
87+
88+
return (
89+
<iframe
90+
ref={iframeRef}
91+
srcDoc={error.html
92+
.replace(
93+
'</head>',
94+
`<style type="text/css">${werkzeugCss}</style>
95+
<script>
96+
function sendHeight() {
97+
const height = document.body.scrollHeight;
98+
window.parent.postMessage({ type: "IFRAME_HEIGHT", height }, "*");
99+
}
100+
101+
window.addEventListener("load", sendHeight);
102+
window.addEventListener("resize", sendHeight);
103+
window.addEventListener("click", sendHeight);
104+
</script></head>`
105+
)
106+
.replace('="?__debugger__', `="${base}?__debugger__`)}
107+
style={{
108+
/*
109+
* 67px of padding and margin between this
110+
* iframe and the parent container.
111+
* 67 was determined manually in the
112+
* browser's dev tools.
113+
*/
114+
width: 'calc(600px - 67px)',
115+
border: 'none',
116+
height: height
117+
}}
118+
/>
119+
);
120+
}
121+
71122
const MAX_MESSAGE_LENGTH = 40;
72123
/* eslint-disable no-inline-comments */
73124
function UnconnectedErrorContent({error, base}) {
@@ -114,31 +165,10 @@ function UnconnectedErrorContent({error, base}) {
114165
<div className='dash-be-error__st'>
115166
<div className='dash-backend-error'>
116167
{/* Embed werkzeug debugger in an iframe to prevent
117-
CSS leaking - werkzeug HTML includes a bunch
118-
of CSS on base html elements like `<body/>`
119-
*/}
120-
121-
<iframe
122-
srcDoc={error.html
123-
.replace(
124-
'</head>',
125-
`<style type="text/css">${werkzeugCss}</style></head>`
126-
)
127-
.replace(
128-
'="?__debugger__',
129-
`="${base}?__debugger__`
130-
)}
131-
style={{
132-
/*
133-
* 67px of padding and margin between this
134-
* iframe and the parent container.
135-
* 67 was determined manually in the
136-
* browser's dev tools.
137-
*/
138-
width: 'calc(600px - 67px)',
139-
border: 'none'
140-
}}
141-
/>
168+
CSS leaking - werkzeug HTML includes a bunch
169+
of CSS on base html elements like `<body/>`
170+
*/}
171+
<BackendError error={error} base={base} />
142172
</div>
143173
</div>
144174
) : (

dash/dash-renderer/src/components/error/GlobalErrorOverlay.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
max-height: calc(100vh - 50px);
4242
margin: 10px;
4343
overflow: auto;
44-
z-index: 1100; /* above the plotly.js toolbar and Bootstrap components */
44+
z-index: 1100; /* above the plotly.js toolbar and Bootstrap components */
4545
}
4646

4747
.dash-error-card__topbar {

dash/dash-renderer/src/components/error/menu/DebugMenu.css

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
z-index: 10000;
3535
border-radius: 5px;
3636
padding: 5px;
37-
background-color: #F5F6FA;
37+
background-color: #f5f6fa;
3838
box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.25),
3939
0px 1px 3px rgba(162, 177, 198, 0.32);
4040
}
@@ -54,7 +54,7 @@
5454
flex-direction: column;
5555
background-color: white;
5656
border-radius: 3px;
57-
border: 1px solid #0018661A;
57+
border: 1px solid #0018661a;
5858
padding: 11px;
5959
box-shadow: 0px 0px 14px 5px #00000012;
6060
z-index: 1200;
@@ -75,7 +75,7 @@
7575
border: none;
7676
padding: 2px 5px;
7777
white-space: nowrap;
78-
color: #7F4BC4;
78+
color: #7f4bc4;
7979
font-size: 10pt;
8080
text-decoration: none;
8181
font-family: none;
@@ -84,7 +84,7 @@
8484
}
8585

8686
.dash-debug-menu__upgrade-tooltip:after {
87-
content: " ";
87+
content: ' ';
8888
position: absolute;
8989
top: 100%;
9090
left: 50%;
@@ -110,13 +110,13 @@
110110
width: 1.5px;
111111
height: 26px;
112112
margin: 0px 13px;
113-
background-color: #0015594D;
113+
background-color: #0015594d;
114114
}
115115

116116
.dash-debug-menu__button {
117117
background: none;
118118
border: none;
119-
box-shadow: 0 1px #D3DAE6;
119+
box-shadow: 0 1px #d3dae6;
120120
display: flex;
121121
justify-content: center;
122122
align-items: center;
@@ -129,8 +129,8 @@
129129
}
130130

131131
.dash-debug-menu__button.dash-debug-menu__button--selected {
132-
color: #7F4BC4;
133-
box-shadow: 0 2px #0071C2;
132+
color: #7f4bc4;
133+
box-shadow: 0 2px #0071c2;
134134
}
135135
.dash-debug-menu__button.dash-debug-menu__button--selected:hover {
136136
color: #5806c4;

dash/dash-renderer/src/components/error/werkzeugcss.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
export default `
55
body {
66
margin: 0px;
7-
margin-top: 10px;
8-
}
9-
10-
.error-container {
11-
font-family: Roboto;
7+
overflow: hidden;
128
}
139
1410
.traceback {

0 commit comments

Comments
 (0)