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

#9553: Improving readability of long attribute values in attribute table and table widgets #9701

Merged
merged 8 commits into from
Nov 21, 2023
Prev Previous commit
Next Next commit
#9553: handle test cases for handleLongTextEnhancer
  • Loading branch information
mahmoudadel54 committed Nov 14, 2023
commit 60f3eb55e1c842d0886725c45cc3ffde273f9a8b
2 changes: 1 addition & 1 deletion web/client/components/data/featuregrid/formatters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import NumberFormat from '../../../I18N/Number';
import { dateFormats as defaultDateFormats } from "../../../../utils/FeatureGridUtils";

const BooleanFormatter = ({value} = {}) => !isNil(value) ? <span>{value.toString()}</span> : null;
const StringFormatter = ({value} = {}) => !isNil(value) ? reactStringReplace(value, /(https?:\/\/\S+)/g, (match, i) => (
export const StringFormatter = ({value} = {}) => !isNil(value) ? reactStringReplace(value, /(https?:\/\/\S+)/g, (match, i) => (
<a key={match + i} href={match} target={"_blank"}>{match}</a>
)) : null;
const NumberFormatter = ({value} = {}) => !isNil(value) ? <NumberFormat value={value} numberParams={{maximumFractionDigits: 17}}/> : null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright 2023, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

import expect from 'expect';

import React from 'react';
import ReactDOM from 'react-dom';
import { handleLongTextEnhancer } from '../handleLongTextEnhancer';
import { StringFormatter } from '../../../data/featuregrid/formatters';

describe("handleLongTextEnhancer enhancer", () => {
beforeEach((done) => {
document.body.innerHTML = '<div id="container"></div>';
setTimeout(done);
});

afterEach((done) => {
ReactDOM.unmountComponentAtNode(document.getElementById("container"));
document.body.innerHTML = '';
setTimeout(done);
});

it('handleLongTextEnhancer with defaults [with no formatter]', () => {
const Enhancer = handleLongTextEnhancer();
ReactDOM.render(
<Enhancer value={"test12334567899999"} />,
document.getElementById("container")
);
expect(document.getElementById("container").innerHTML).toExist();
expect(document.getElementsByTagName('span').length).toEqual(2);
expect(document.getElementsByTagName('span')[1].innerHTML).toExist();
});

it('handleLongTextEnhancer with formatter', () => {
const EnhancerWithFormatter = handleLongTextEnhancer(StringFormatter);
ReactDOM.render(
<EnhancerWithFormatter value={"test12334567899999"} />,
document.getElementById("container")
);
expect(document.getElementById("container").innerHTML).toExist();
expect(document.getElementsByTagName('span').length).toEqual(2);
expect(document.getElementsByTagName('span')[1].innerHTML).toExist();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from "react";
import OverlayTrigger from "../OverlayTrigger";
import { Tooltip } from "react-bootstrap";

export const handleLongTextEnhancer = (props, RenderFormatter) => {
export const handleLongTextEnhancer = (RenderFormatter) => (props) => {
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
mahmoudadel54 marked this conversation as resolved.
Show resolved Hide resolved
const { value } = props;
const cellRef = React.useRef(null);
const contentRef = React.useRef(null);
Expand Down
2 changes: 1 addition & 1 deletion web/client/utils/FeatureGridUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const featureTypeToGridColumns = (
editable,
filterable,
editor: getEditor(desc, field),
formatter: (props)=>handleLongTextEnhancer(props, getFormatter(desc, field)),
formatter: handleLongTextEnhancer(getFormatter(desc, field)),
filterRenderer: getFilterRenderer(desc, field)
};
});
Expand Down
Loading