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

* Improve PartialHighlighter error handling

(cherry picked from commit 05bb451a1d)

Co-authored-by: Connor Lindsey <cblindsey3@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2021-09-28 09:45:15 -06:00
committed by GitHub
co-authored by Connor Lindsey
parent 2e86425ed9
commit d38782bc94
2 changed files with 8 additions and 1 deletions
@@ -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);
});
});
@@ -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;
}