• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jumpinjackie / mapguide-react-layout / 15160437878

21 May 2025 11:00AM UTC coverage: 21.631% (-42.6%) from 64.24%
15160437878

Pull #1552

github

web-flow
Merge 8b7153d9e into 236e2ea07
Pull Request #1552: Feature/package updates 2505

839 of 1165 branches covered (72.02%)

11 of 151 new or added lines in 25 files covered. (7.28%)

1332 existing lines in 50 files now uncovered.

4794 of 22163 relevant lines covered (21.63%)

6.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.77
/src/components/context.tsx
1
/**
2
 * context.ts
3
 *
4
 * This module holds various React component contexts and validation maps
5
 */
6
import * as React from "react";
1✔
7
import { IDOMElementMetrics } from "../api/common";
8
import { MapLayer, MapGroup } from "../api/contracts/runtime-map";
9
import { DEFAULT_LOCALE } from '../api/i18n';
1✔
10
import { STR_EMPTY } from '../utils/string';
1✔
11
import { IMapGuideAppProps } from "../containers/app";
12

13
const VOID_NOOP = () => { }
1✔
14

15
/**
16
 * @since 0.14.9
17
 */
18
export type LegendNodeExtraHTMLProps<T> = {
19
    /**
20
     * The item (group or layer)
21
     */
22
    item: T;
23
    /**
24
     * The map name
25
     */
26
    mapName: string;
27
    /**
28
     * The current session id
29
     */
30
    session: string;
31
    /**
32
     * The size of the node (height and width). Use this as guidelines for constraining your custom content
33
     */
34
    elementSize: number;
35
    /**
36
     * A function that helps sanitize the given HTML content
37
     * 
38
     * @param html The HTML content to sanitize
39
     * @returns A sanitized version of the given HTML
40
     */
41
    sanitize: (html: string) => string;
42
}
43

44

45
export interface IApplicationContext {
46
    /**
47
     * Gets whether to display HTML property values in the selection panel (provided via mount option)
48
     * 
49
     * @since 0.11
50
     * @memberof IApplicationContext
51
     */
52
    allowHtmlValuesInSelection: () => boolean;
53
    /**
54
     * Gets a HTML sanitization function (if provided via mount option)
55
     * 
56
     * @since 0.11
57
     * @memberof IApplicationContext
58
     */
59
    getHTMLCleaner: () => (((value: string) => string) | undefined);
60
    /**
61
     * Provide extra HTML elements to insert before a layer name in a layer legend node
62
     * 
63
     * @param options
64
     * @since 0.14.9
65
     */
66
    getLegendLayerExtraIconsProvider: (options: LegendNodeExtraHTMLProps<MapLayer>) => string[];
67
    /**
68
     * Provide extra HTML elements to insert before a group name in a group legend node
69
     * 
70
     * @param options
71
     * @since 0.14.9
72
     */
73
    getLegendGroupExtraIconsProvider: (options: LegendNodeExtraHTMLProps<MapGroup>) => string[];
74
}
75

76
export const AppContext = React.createContext<IApplicationContext>({
1✔
77
    allowHtmlValuesInSelection: () => false,
1✔
78
    getHTMLCleaner: () => v => v,
1✔
79
    getLegendLayerExtraIconsProvider: () => [],
1✔
80
    getLegendGroupExtraIconsProvider: () => []
1✔
81
});
1✔
82

83
/**
84
 * @since 0.14.9
85
 */
86
export const AppContextProvider: React.FC<{ mapguide: IMapGuideAppProps | undefined }> = ({ mapguide, children }) => {
1✔
87
    const providerImpl = React.useMemo<IApplicationContext>(() => ({
×
88
        allowHtmlValuesInSelection: () => mapguide?.selectionSettings?.allowHtmlValues ?? false,
×
89
        getHTMLCleaner: () => mapguide?.selectionSettings?.cleanHtml ?? (v => v),
×
90
        getLegendLayerExtraIconsProvider: (options: LegendNodeExtraHTMLProps<MapLayer>) => mapguide?.legendSettings?.provideExtraLayerIconsHtml?.(options) ?? [],
×
91
        getLegendGroupExtraIconsProvider: (options: LegendNodeExtraHTMLProps<MapGroup>) => mapguide?.legendSettings?.provideExtraGroupIconsHtml?.(options) ?? []
×
UNCOV
92
    }), [mapguide]);
×
93
    return <AppContext.Provider value={providerImpl}>
×
UNCOV
94
        {children}
×
UNCOV
95
    </AppContext.Provider>
×
UNCOV
96
}
×
97

98
export interface ILegendContext {
99
    stateless: boolean;
100
    isFiltering(): boolean;
101
    getMapName(): string | undefined;
102
    /**
103
     * @since 0.14.9
104
     */
105
    getSessionId(): string | undefined;
106
    getFilterText(): string;
107
    getLocale(): string;
108
    getBaseIconSize(): number;
109
    getIconMimeType(): string | undefined;
110
    getChildren(objectId: string): (MapLayer | MapGroup)[];
111
    getCurrentScale(): number;
112
    getTree(): any;
113
    getLayerVisibility(layer: MapLayer): boolean;
114
    getGroupVisibility(group: MapGroup): boolean;
115
    setGroupVisibility(groupId: string, visible: boolean): void;
116
    setLayerVisibility(layerId: string, visible: boolean): void;
117
    getLayerSelectability(layerId: string): boolean;
118
    setLayerSelectability(layerId: string, selectable: boolean): void;
119
    getGroupExpanded(groupId: string): boolean;
120
    setGroupExpanded(groupId: string, expanded: boolean): void;
121
    getLayerExpanded(layerId: string): boolean;
122
    setLayerExpanded(layerId: string, expanded: boolean): void;
123
    /**
124
     * Provide extra HTML elements to insert before a layer name in a layer legend node
125
     * 
126
     * @param options
127
     * @since 0.14.9
128
     */
129
    provideExtraLayerIconsHtml?: (options: LegendNodeExtraHTMLProps<MapLayer>) => string[];
130
    /**
131
     * Provide extra HTML elements to insert before a group name in a group legend node
132
     * 
133
     * @param options
134
     * @since 0.14.9
135
     */
136
    provideExtraGroupIconsHtml?: (options: LegendNodeExtraHTMLProps<MapGroup>) => string[];
137
}
138

139
export const LegendContext = React.createContext<ILegendContext>({
1✔
140
    stateless: false,
1✔
141
    getMapName: () => undefined,
1✔
142
    getSessionId: () => undefined,
1✔
143
    isFiltering: () => false,
1✔
144
    getFilterText: () => STR_EMPTY,
1✔
145
    getLocale: () => DEFAULT_LOCALE,
1✔
146
    getBaseIconSize: () => 0,
1✔
147
    getIconMimeType: () => STR_EMPTY,
1✔
148
    getChildren: () => [],
1✔
149
    getCurrentScale: () => -1,
1✔
150
    getTree: VOID_NOOP,
1✔
151
    getLayerVisibility: () => false,
1✔
152
    getGroupVisibility: () => false,
1✔
153
    setGroupVisibility: VOID_NOOP,
1✔
154
    setLayerVisibility: VOID_NOOP,
1✔
155
    getLayerSelectability: () => false,
1✔
156
    setLayerSelectability: () => false,
1✔
157
    getGroupExpanded: () => false,
1✔
158
    setGroupExpanded: VOID_NOOP,
1✔
159
    getLayerExpanded: () => false,
1✔
160
    setLayerExpanded: VOID_NOOP,
1✔
161
    provideExtraGroupIconsHtml: () => [],
1✔
162
    provideExtraLayerIconsHtml: () => []
1✔
163
});
1✔
164

165
export interface IToolbarContext {
166
    openFlyout(id: string, metrics: IDOMElementMetrics): void;
167
    closeFlyout(id: string): void;
168
    openComponent(id: string, metrics: IDOMElementMetrics, name: string, props?: any): void;
169
    closeComponent(id: string): void;
170
}
171

172
export const ToolbarContext = React.createContext<IToolbarContext>({
1✔
173
    openFlyout: VOID_NOOP,
1✔
174
    closeFlyout: VOID_NOOP,
1✔
175
    openComponent: VOID_NOOP,
1✔
176
    closeComponent: VOID_NOOP
1✔
177
});
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc