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

Custom popup renderer are broken by long string tooltip #9763

Closed
1 task done
offtherailz opened this issue Nov 28, 2023 · 0 comments · Fixed by #9793
Closed
1 task done

Custom popup renderer are broken by long string tooltip #9763

offtherailz opened this issue Nov 28, 2023 · 0 comments · Fixed by #9793

Comments

@offtherailz
Copy link
Member

Description

After updating a project to obtain latest fixes, I noticed that the custom renderer I defined in the project didn't worked anymore.
This is important to have for the future JSON fields or customizations.

In particular the new feature #9553 , backported, applied these changes :

0716234

Wrapping all formatters breaks the possibility to use popups as custom renderers.

Solution We should apply the wrapper to each of the default rendererers (string, date ...) but not wrap every renderer, that may include also custom ones, with custom popups that may be broken by this change.

How to reproduce

  • As a developer, create and register a renderer to a field, then assign it to a column.

Sample formatter code:

import React from "react";
import { Popover, OverlayTrigger} from "react-bootstrap";

const PopupFormatter = ({ children, placement = 'left' }) => {
    return (
        <OverlayTrigger
            trigger="click"
            rootClose
            key={placement}
            placement={placement}
            overlay={
                <Popover id={`popover-positioned-${placement}`}>
                    {children}
                </Popover>
            }
        >
            <div
                className="popup-formatter-container"
                style={{
                    width: "100%",
                    height: 25,
                    overflow: "hidden"
                }}
            >
        Click To Show
            </div>
        </OverlayTrigger>
    );
};

export default PopupFormatter;

const renderObject = (obj, labels = {}) => {
    if (Array.isArray(obj)) {
        return (<ul>
            {obj.map((item, index) => {
                return <li key={index}>{renderObject(item)}</li>;
            })}
        </ul>);
    }
    if (typeof obj === 'object') {
        return (<ul>
            {Object.keys(obj).map((key, index) => {
                return <li key={index}><strong>{labels[key] || key}</strong>: {renderObject(obj[key])}</li>;
            })}
        </ul>);
    }
    return <span>{obj}</span>;
};

const renderObject = (obj, labels = {}) => {
    if (Array.isArray(obj)) {
        return (<ul>
            {obj.map((item, index) => {
                return <li key={index}>{renderObject(item)}</li>;
            })}
        </ul>);
    }
    if (typeof obj === 'object') {
        return (<ul>
            {Object.keys(obj).map((key, index) => {
                return <li key={index}><strong>{labels[key] || key}</strong>: {renderObject(obj[key])}</li>;
            })}
        </ul>);
    }
    return <span>{obj}</span>;
};

const JSONFormatter = ({value, labels = {}}) => {
    try {
        if (!value) {
            return <span>{value}</span>;
        }
        const json = JSON.parse(value);
        if (!json) {
            return <span>{value}</span>;
        }
        return (<PopupContainer>
            {renderObject(json, labels)}
        </PopupContainer>);


    } catch (e) {
        return <span>{value}</span>;

    }

};

export default JSONFormatter;

registering:

registerFormatter('json', JsonFormatter); // somewhere on init

use (in fields of a layer):

{
          "name": "JSON_ATTRIBUTE",
          "alias": "My custom attribute",
          "type": "string",
          "featureGridFormatter": {
            "name": "json",
            "directRender": true
          }
        }

Expected Result

The renderer is used for the column and working

Current Result

The renderer do not work because of the wrapper blocking any action on it.

  • Not browser related
Browser info (use this site: https://www.whatsmybrowser.org/ for non expert users)
Browser Affected Version
Internet Explorer
Edge
Chrome
Firefox
Safari

Other useful information

@tdipisa tdipisa added this to the 2023.02.02 milestone Nov 30, 2023
@tdipisa tdipisa assigned offtherailz and unassigned tdipisa Nov 30, 2023
offtherailz added a commit to offtherailz/MapStore2 that referenced this issue Dec 6, 2023
@MV88 MV88 closed this as completed in #9793 Dec 6, 2023
MV88 pushed a commit that referenced this issue Dec 6, 2023
* Fix #9763. long string tooltip applied statically to components

* Fixed tests
offtherailz added a commit that referenced this issue Dec 6, 2023
* Fix #9763. long string tooltip applied statically to components

* Fixed tests
MV88 pushed a commit that referenced this issue Dec 6, 2023
… (#9794)

* Fix #9763. long string tooltip applied statically to components

* Fixed tests
@ElenaGallo ElenaGallo added BackportNeeded Commits provided for an issue need to be backported to the milestone's stable branch and removed BackportNeeded Commits provided for an issue need to be backported to the milestone's stable branch labels Dec 6, 2023
@ElenaGallo ElenaGallo self-assigned this Dec 6, 2023
mahmoudadel54 pushed a commit to mahmoudadel54/MapStore2 that referenced this issue Dec 7, 2023
…omponents (geosolutions-it#9793)

* Fix geosolutions-it#9763. long string tooltip applied statically to components

* Fixed tests
MV88 pushed a commit that referenced this issue Dec 7, 2023
… (#9800)

* Fix #9763. long string tooltip applied statically to components

* Fixed tests

Co-authored-by: Lorenzo Natali <[email protected]>
@tdipisa tdipisa modified the milestones: 2023.02.02, 2023.02.01 Dec 7, 2023
@offtherailz offtherailz changed the title Custom popup renderer are broken by Custom popup renderer are broken by #9553 Dec 7, 2023
@offtherailz offtherailz changed the title Custom popup renderer are broken by #9553 Custom popup renderer are broken by long string visualizer #9553 Dec 7, 2023
@offtherailz offtherailz changed the title Custom popup renderer are broken by long string visualizer #9553 Custom popup renderer are broken by long string tooltip Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment