-
Notifications
You must be signed in to change notification settings - Fork 409
/
Copy pathTemplateViewer.jsx
44 lines (38 loc) · 1.29 KB
/
TemplateViewer.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
* Copyright 2018, 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 { template } from 'lodash';
import PropTypes from 'prop-types';
import { getCleanTemplate } from '../../../../utils/TemplateUtils';
import HtmlRenderer from '../../../misc/HtmlRenderer';
import Message from '../../../I18N/Message';
const TemplateViewer = ({layer = {}, response}) => (
<div className="ms-template-viewer">
{response?.features?.map((feature, i) => {
const cleanTemplate = getCleanTemplate(layer.featureInfo && layer.featureInfo.template || '', feature, /\$\{.*?\}/g, 2, 1);
let html = "";
try {
html = template(cleanTemplate)(feature);
} catch (e) {
console.error(e);
return (<div key={i}>
<Message msgId="layerProperties.templateError"/>
</div>);
}
return (<div key={i}>
<HtmlRenderer html={html}/>
</div>);
}
)}
</div>
);
export default TemplateViewer;
TemplateViewer.propTypes = {
response: PropTypes.object,
layer: PropTypes.object
};