grafana-ui: Improve PartialHighlighter error handling (#39685)

* Improve PartialHighlighter error handling
This commit is contained in:
Connor Lindsey 2021-09-28 09:07:58 -06:00 committed by GitHub
parent fffcee7c1f
commit 05bb451a1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -45,4 +45,11 @@ describe('PartialHighlighter component', () => {
assertPart(main.childAt(1), false, ' ipsum dolor sit ');
assertPart(main.childAt(2), true, 'amet');
});
it('returns null if highlightParts is empty', () => {
const component = mount(
<PartialHighlighter text="Lorem ipsum dolor sit amet" highlightClassName="highlight" highlightParts={[]} />
);
expect(component.html()).toBe(null);
});
});

View File

@ -29,7 +29,7 @@ function getStartIndices(parts: HighlightPart[], length: number): number[] {
export const PartialHighlighter: React.FC<Props> = (props: Props) => {
let { highlightParts, text, highlightClassName } = props;
if (!highlightParts) {
if (!highlightParts?.length) {
return null;
}