Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip HTML tags from item labels #67

Merged
merged 2 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/components/ui/ControlPanel/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useContext, useEffect, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { TextField } from '@mui/material';
import { useDebounce } from 'use-debounce';
import HTMLReactParser from 'html-react-parser';
import parse from 'autosuggest-highlight/parse';
import _sortBy from 'lodash/sortBy';
import _isUndefined from 'lodash/isUndefined';
Expand Down Expand Up @@ -41,14 +40,13 @@ const Find = observer(() => {
const itemList = () => _sortBy(visualizationStore.items, ['label', 'id'])
.filter(item => item.label.toLowerCase().indexOf(uiStore.itemFilterText.toLowerCase()) !== -1)
.map((item, i) => {
const label = HTMLReactParser(item.label);
const matchPosition = label.toLowerCase().indexOf(uiStore.itemFilterText.toLowerCase());
const labelParts = parse(label, [[matchPosition, matchPosition + uiStore.itemFilterText.length]]);
const matchPosition = item.label.toLowerCase().indexOf(uiStore.itemFilterText.toLowerCase());
const labelParts = parse(item.label, [[matchPosition, matchPosition + uiStore.itemFilterText.length]]);
return (
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
<p
className={s.listItem}
key={`${label}-${String(i)}`}
key={`${item.label}-${String(i)}`}
onClick={() => changeClickedItem(item)}
>
{
Expand Down
7 changes: 3 additions & 4 deletions src/store/visualization/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-bitwise */
import HTMLReactParser from 'html-react-parser';
import { makeAutoObservable } from 'mobx';
import { scaleLinear, scaleOrdinal } from 'd3-scale';
import { extent, sum } from 'd3-array';
Expand Down Expand Up @@ -27,6 +26,7 @@ import { ItemStatus, LinkStatus, VisualizationStatus, calcDistance } from 'utils
import {
getLabelValue, getClusterKeys, getWeightKeys, getScoreKeys, getColorScheme, getNiceMinValue, getNiceMaxValue
} from 'utils/helpers';
import { cleanPlainText } from 'utils/helpers2';

export default class State {
constructor(state = {}) {
Expand Down Expand Up @@ -191,7 +191,7 @@ export default class State {
item._status = ItemStatus.DEFAULT;

item.id = _isNaN(_toNumber(item.id)) ? item.id : _toNumber(item.id);
item.label = getLabelValue(item);
item.label = cleanPlainText(getLabelValue(item));
item._normalizedScore = undefined;
});

Expand Down Expand Up @@ -567,8 +567,7 @@ export default class State {
item._fontSize = this.pixelRatio * (scale * labelMinFontSize + labelFontSizeScalingConstant * item._normalizedWeight ** itemSizeVariation);
if (this.labelCanvasContext) {
this.labelCanvasContext.font = `${item._fontSize}px ${fontFamily}`;
const label = HTMLReactParser(item.label);
item._labelText = (label || '').slice(0, maxLabelLength) || '';
item._labelText = (item.label || '').slice(0, maxLabelLength) || '';
item._labelTextWidth = this.labelCanvasContext.measureText(item._labelText).width;
}
});
Expand Down
Loading