-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Expressions] [Lens] Implement a loading state and error state in the…
… ExpressionRenderer (#48841) * Add loading indicator to Lens workspace panel * [Expressions] [Lens] Handle loading and errors in ExpressionRenderer * Using loading$ observable and improve tests * Using CSS and to handle layout of expression renderer Added TODO for using chart loader when area is completely empty * Improve error handling and simplify code * Fix cleanup behavior * Fix double render and prevent error cases in xy chart * Fix context for use in dashboards * Remove className from expression rendere component * Improve handling of additional interpreter args * More layout fixes - Hide chart if Empty not Loading - Fix relative positioning for progress bar since className is no longer passed (super hacky)
- Loading branch information
Wylie Conlon
authored
Oct 25, 2019
1 parent
9bd8f74
commit ed07fb4
Showing
26 changed files
with
832 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Import the EUI global scope so we can use EUI constants | ||
@import 'src/legacy/ui/public/styles/_styling_constants'; | ||
|
||
/* Expressions plugin styles */ | ||
|
||
// Prefix all styles with "exp" to avoid conflicts. | ||
// Examples | ||
// expChart | ||
// expChart__legend | ||
// expChart__legend--small | ||
// expChart__legend-isLoading | ||
|
||
@import './np_ready/public/index'; |
20 changes: 20 additions & 0 deletions
20
src/legacy/core_plugins/expressions/public/np_ready/public/_expression_renderer.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.expExpressionRenderer { | ||
position: relative; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.expExpressionRenderer__expression { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
|
||
.expExpressionRenderer-isEmpty, | ||
.expExpressionRenderer-hasError { | ||
.expExpressionRenderer__expression { | ||
display: none; | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/legacy/core_plugins/expressions/public/np_ready/public/_index.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import './expression_renderer'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/legacy/core_plugins/expressions/public/np_ready/public/expression_renderer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { Subject } from 'rxjs'; | ||
import { share } from 'rxjs/operators'; | ||
import { ExpressionRendererImplementation } from './expression_renderer'; | ||
import { ExpressionLoader } from './loader'; | ||
import { mount } from 'enzyme'; | ||
import { EuiProgress } from '@elastic/eui'; | ||
|
||
jest.mock('./loader', () => { | ||
return { | ||
ExpressionLoader: jest.fn().mockImplementation(() => { | ||
return {}; | ||
}), | ||
loader: jest.fn(), | ||
}; | ||
}); | ||
|
||
describe('ExpressionRenderer', () => { | ||
it('starts to load, resolves, and goes back to loading', () => { | ||
const dataSubject = new Subject(); | ||
const data$ = dataSubject.asObservable().pipe(share()); | ||
const renderSubject = new Subject(); | ||
const render$ = renderSubject.asObservable().pipe(share()); | ||
const loadingSubject = new Subject(); | ||
const loading$ = loadingSubject.asObservable().pipe(share()); | ||
|
||
(ExpressionLoader as jest.Mock).mockImplementation(() => { | ||
return { | ||
render$, | ||
data$, | ||
loading$, | ||
update: jest.fn(), | ||
}; | ||
}); | ||
|
||
const instance = mount(<ExpressionRendererImplementation expression="" />); | ||
|
||
loadingSubject.next(); | ||
instance.update(); | ||
|
||
expect(instance.find(EuiProgress)).toHaveLength(1); | ||
|
||
renderSubject.next(1); | ||
|
||
instance.update(); | ||
|
||
expect(instance.find(EuiProgress)).toHaveLength(0); | ||
|
||
instance.setProps({ expression: 'something new' }); | ||
loadingSubject.next(); | ||
instance.update(); | ||
|
||
expect(instance.find(EuiProgress)).toHaveLength(1); | ||
|
||
renderSubject.next(1); | ||
instance.update(); | ||
|
||
expect(instance.find(EuiProgress)).toHaveLength(0); | ||
}); | ||
|
||
it('should display an error message when the expression fails', () => { | ||
const dataSubject = new Subject(); | ||
const data$ = dataSubject.asObservable().pipe(share()); | ||
const renderSubject = new Subject(); | ||
const render$ = renderSubject.asObservable().pipe(share()); | ||
const loadingSubject = new Subject(); | ||
const loading$ = loadingSubject.asObservable().pipe(share()); | ||
|
||
(ExpressionLoader as jest.Mock).mockImplementation(() => { | ||
return { | ||
render$, | ||
data$, | ||
loading$, | ||
update: jest.fn(), | ||
}; | ||
}); | ||
|
||
const instance = mount(<ExpressionRendererImplementation expression="" />); | ||
|
||
dataSubject.next('good data'); | ||
renderSubject.next({ | ||
type: 'error', | ||
error: { message: 'render error' }, | ||
}); | ||
instance.update(); | ||
|
||
expect(instance.find(EuiProgress)).toHaveLength(0); | ||
expect(instance.find('[data-test-subj="expression-renderer-error"]')).toHaveLength(1); | ||
}); | ||
|
||
it('should display a custom error message if the user provides one', () => { | ||
const dataSubject = new Subject(); | ||
const data$ = dataSubject.asObservable().pipe(share()); | ||
const renderSubject = new Subject(); | ||
const render$ = renderSubject.asObservable().pipe(share()); | ||
const loadingSubject = new Subject(); | ||
const loading$ = loadingSubject.asObservable().pipe(share()); | ||
|
||
(ExpressionLoader as jest.Mock).mockImplementation(() => { | ||
return { | ||
render$, | ||
data$, | ||
loading$, | ||
update: jest.fn(), | ||
}; | ||
}); | ||
|
||
const renderErrorFn = jest.fn().mockReturnValue(null); | ||
|
||
const instance = mount( | ||
<ExpressionRendererImplementation expression="" renderError={renderErrorFn} /> | ||
); | ||
|
||
renderSubject.next({ | ||
type: 'error', | ||
error: { message: 'render error' }, | ||
}); | ||
instance.update(); | ||
|
||
expect(renderErrorFn).toHaveBeenCalledWith('render error'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.