-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#9553: Improving readability of long attribute values in attribute ta…
…ble and table widgets (#9701) (#9719) * #9553: handle showing tooltip on attr table cells once user hovers on cell * #9553: create a separate enhnacer for handleLongText and use it for formatter table cell * #9553: add copyright for the created handleLongTextEnhancer * #9553: handle test cases for handleLongTextEnhancer * #9553: add unit tests for handleLongTextEnhancer * #9553: fix unit test failure for featureTypeToGridColumns formatters * #9553:reset tests.webpack file * Update web/client/components/misc/enhancers/handleLongTextEnhancer.jsx --------- Co-authored-by: Matteo V <[email protected]>
- Loading branch information
1 parent
6f59a61
commit e654fba
Showing
5 changed files
with
165 additions
and
2 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
76 changes: 76 additions & 0 deletions
76
web/client/components/misc/enhancers/__tests__/handleLongTextEnhancer-test.jsx
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,76 @@ | ||
/** | ||
* 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 by passing formatter as wrapper', () => { | ||
const EnhancerWithFormatter = ()=> handleLongTextEnhancer(StringFormatter)({ value: "test12334567899999" }); | ||
ReactDOM.render( | ||
<EnhancerWithFormatter />, | ||
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 by passing td as wrapper', () => { | ||
const wrapper = () => (<td>15234568965</td>); | ||
const EnhancerWithFormatter = ()=> handleLongTextEnhancer(wrapper)({ value: "15234568965" }); | ||
ReactDOM.render( | ||
<EnhancerWithFormatter />, | ||
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 by passing span as wrapper', () => { | ||
const wrapper = () => (<span>15234568965</span>); | ||
const EnhancerWithFormatter = ()=> handleLongTextEnhancer(wrapper)({ value: "15234568965" }); | ||
ReactDOM.render( | ||
<EnhancerWithFormatter />, | ||
document.getElementById("container") | ||
); | ||
expect(document.getElementById("container").innerHTML).toExist(); | ||
expect(document.getElementsByTagName('span').length).toEqual(3); | ||
expect(document.getElementsByTagName('span')[1].innerHTML).toExist(); | ||
}); | ||
|
||
|
||
it('handleLongTextEnhancer with by passing td div wrapper', () => { | ||
const wrapper = () => (<div>test</div>); | ||
const EnhancerWithFormatter = ()=> handleLongTextEnhancer(wrapper)({ value: "test" }); | ||
ReactDOM.render( | ||
<EnhancerWithFormatter />, | ||
document.getElementById("container") | ||
); | ||
expect(document.getElementById("container").innerHTML).toExist(); | ||
expect(document.getElementsByTagName('span').length).toEqual(2); | ||
expect(document.getElementsByTagName('span')[1].innerHTML).toExist(); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
web/client/components/misc/enhancers/handleLongTextEnhancer.jsx
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,50 @@ | ||
/* | ||
* 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 React from "react"; | ||
import OverlayTrigger from "../OverlayTrigger"; | ||
import { Tooltip } from "react-bootstrap"; | ||
/** | ||
* handleLongTextEnhancer enhancer. Enhances a long text content by adding a tooltip. | ||
* @type {function} | ||
* @name handleLongTextEnhancer | ||
* @memberof components.misc.enhancers | ||
* Wraps [wrapped component with content] to add tooltip for long content if shown content less than the main content | ||
* @param {Component} Wrapped the component wrapped with a tooltip when its content is too long | ||
* @param {object} props the props that contains value content | ||
* @return {Component} the rendered component that renders the content with the tooltip if the content is long or renders the content with no tooltip if not long | ||
* @example | ||
* const wrapper = () = > <span>testtttttttttt</span> | ||
* const Component = ()=> handleLongTextEnhancer(wrapper)(props); | ||
* render (){ | ||
* return <Component /> | ||
* } | ||
* | ||
*/ | ||
export const handleLongTextEnhancer = (Wrapped) => (props) => { | ||
const cellRef = React.useRef(null); | ||
const contentRef = React.useRef(null); | ||
const [isContentOverflowing, setIsContentOverflowing] = React.useState(false); | ||
|
||
const handleMouseEnter = () => { | ||
const cellWidth = cellRef.current.offsetWidth; | ||
const contentWidth = contentRef.current.offsetWidth; | ||
setIsContentOverflowing(contentWidth > cellWidth); | ||
}; | ||
|
||
return (<OverlayTrigger | ||
placement="top" | ||
overlay={isContentOverflowing ? <Tooltip id="tooltip">{<Wrapped {...props} />}</Tooltip> : <></>} | ||
> | ||
<div ref={cellRef} onMouseEnter={handleMouseEnter}> | ||
<span ref={contentRef}> | ||
<span>{<Wrapped {...props} />}</span> | ||
</span> | ||
</div> | ||
</OverlayTrigger>); | ||
}; |
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