Skip to content

Selection Panel: add formatPropertyValue hook and property/layer context to cleanHTML#1601

Merged
jumpinjackie merged 4 commits intomasterfrom
copilot/limit-digits-of-double-number
Mar 12, 2026
Merged

Selection Panel: add formatPropertyValue hook and property/layer context to cleanHTML#1601
jumpinjackie merged 4 commits intomasterfrom
copilot/limit-digits-of-double-number

Conversation

Copy link
Contributor

Copilot AI commented Mar 11, 2026

The Selection Panel had no mechanism to transform plain-text property values before display, making it impossible to limit decimal precision of floating-point numbers like 38.174886687764541.

Changes

  • New ISelectionPanelCellContext interface — carries propertyName and layerName (the name of the active selection layer) and is passed to all value customization functions, enabling property-aware and layer-aware formatting decisions.

  • New formatPropertyValue hook — called for all property values regardless of allowHtmlValues. Primary solution for the decimal precision use case. Available on ISelectedFeatureProps, ISelectionPanelProps, and SelectionOptions (mount option).

  • Context added to cleanHTML — signature changed from (html: string) => string to (html: string, context: ISelectionPanelCellContext) => string. Backward compatible — existing functions ignoring the second argument continue to work.

  • layerName added to ISelectedFeatureProps — the active selection layer name is now passed down to the feature renderer, and included in ISelectionPanelCellContext.

  • Security fixgetHTMLCleaner() default changed from returning an identity function (silently bypassing DOMPurify) to undefined, so DOMPurify is now correctly used when no custom cleaner is configured.

Usage

viewer.mount(el, {
    layout: "...",
    resourceId: "...",
    mapguide: {
        agentUri: "...",
        selectionSettings: {
            formatPropertyValue: (value, context) => {
                // Optionally scope formatting to a specific layer
                if (context.layerName === "Parcels" && /^-?\d+\.\d+$/.test(value)) {
                    return parseFloat(value).toFixed(3); // 38.174886687764541 → 38.175
                }
                return value;
            }
        }
    }
});

For HTML values, formatPropertyValue runs first, then cleanHTML sanitizes the result.

Original prompt

This section details on the original issue you should resolve

<issue_title>Limit digits of of a Double number</issue_title>
<issue_description># THIS ISSUE WAS IS A MATTER OF VISIBILITY

Bug Describe
Limit digits of of a Doubl-Data-Property, displayed
in selection property window

What is your environment?

  1. MapGuide OS4.WINDOWS.IIS
  2. mapguide-react-layout 4.19

Expected behavior
Can we somehow limit digits of whole/integral part of a decimal number, something like regex
from 25.538652375185784 to 25.386

limitdigits

Include relevant output/screenshots here</issue_description>

<agent_instructions>Please explore possible solutions to allow customizing the cell content of the Value column to be displayed in the Selection Panel component. The primary use case is to address the problem in this issue: The ability to customize the number of decimal places for a cell value that is a floating point number.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@jumpinjackie Currently you can provide a HTML cleaning function as part of the viewer mount options:

See: #477 (comment)

The original purpose is to plug in your own HTML sanitizer function for the given HTML and return a sanitized version. The current consumer of this function is the selection panel which sanitizes its property values through either DOMPurify or your custom provided function before rendering the cleaned value out to its table cell.

So conceivably you could provide your own HTML sanitizer function, check the content for anything matching a decimal number and as part of "cleaning" it trim it down to however many decimal places you require if the content looks like a decimal number.

A limitation of this currently is that the sanitizer function only receives the HTML to clean, there is no additional context given around this content (ie. What is this content? Who/what is requesting for this HTML content to be cleaned?).

For the 0.15 release I'll look at providing additional context to this cleaning function so that you can be more fine-grained in what kind of content to clean/reformat.</comment_new>


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

… to cleanHTML for Selection Panel

Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
Copilot AI changed the title [WIP] Limit digits of a Double number in selection property window Selection Panel: add formatPropertyValue hook and property context to cleanHTML Mar 11, 2026
@jumpinjackie
Copy link
Owner

@copilot The ISelectionPanelCellContext should also include the name of the active selection layer

Co-authored-by: jumpinjackie <563860+jumpinjackie@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 11, 2026

@copilot The ISelectionPanelCellContext should also include the name of the active selection layer

Done in commit 815ee54. ISelectionPanelCellContext now includes layerName: string | undefined — populated from selLayer.getName() — alongside propertyName. This lets you write per-layer formatting logic like:

formatPropertyValue: (value, context) => {
    if (context.layerName === "Parcels" && /^-?\d+\.\d+$/.test(value)) {
        return parseFloat(value).toFixed(3);
    }
    return value;
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • storybook.js.org
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node /home/REDACTED/work/mapguide-react-layout/mapguide-react-layout/node_modules/.bin/storybook build -c .storybook (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Selection Panel: add formatPropertyValue hook and property context to cleanHTML Selection Panel: add formatPropertyValue hook and property/layer context to cleanHTML Mar 11, 2026
@coveralls
Copy link

coveralls commented Mar 12, 2026

Coverage Status

coverage: 37.045% (+0.02%) from 37.029%
when pulling bff91d2 on copilot/limit-digits-of-double-number
into 50ddae9 on master.

@jumpinjackie
Copy link
Owner

@copilot This is working, the only problem is that your example in the PR description is wrong. The selectionSettings object should be a property under the mapguide object.

Pls fix up all relevant documentation.

Copy link
Contributor Author

Copilot AI commented Mar 12, 2026

@copilot This is working, the only problem is that your example in the PR description is wrong. The selectionSettings object should be a property under the mapguide object.

Pl...

Fixed the PR description. The usage example now correctly places selectionSettings inside the mapguide object:

viewer.mount(el, {
    layout: "...",
    resourceId: "...",
    mapguide: {
        agentUri: "...",
        selectionSettings: {
            formatPropertyValue: (value, context) => {
                if (context.layerName === "Parcels" && /^-?\d+\.\d+$/.test(value)) {
                    return parseFloat(value).toFixed(3);
                }
                return value;
            }
        }
    }
});

@jumpinjackie jumpinjackie marked this pull request as ready for review March 12, 2026 14:53
@jumpinjackie jumpinjackie merged commit e3020d5 into master Mar 12, 2026
3 checks passed
@jumpinjackie jumpinjackie deleted the copilot/limit-digits-of-double-number branch March 12, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Limit digits of of a Double number

3 participants