Skip to content

Commit 5beff13

Browse files
geosolutions-it#11973: fix issue of MetadataExplorer plugin config - hideThumbnails value setting has no effect (geosolutions-it#11975)
* geosolutions-it#11973: fix issue of MetadataExplorer plugin config - hideThumbnails value setting has no effect - fix issue of not reflect cfg value for hideThumbnail in MetadataExplorer plugin - handle use priority for hideThumbnail of service if configred/set then global cfg hideThumbnail from plugin - add unit tests * - rename TOGGLE_THUMBNAIL to SET_THUMBNAIL_FLAG for clarity and consistency in catalog action/reducer - edit unit tests due to above change * - Enhance JSDoc for cfg.hideThumbnail prop: clarify global vs service configuration behavior.
1 parent 1a224d7 commit 5beff13

11 files changed

Lines changed: 113 additions & 21 deletions

File tree

web/client/actions/__tests__/catalog-test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import {
5757
CHANGE_TEXT,
5858
TOGGLE_ADVANCED_SETTINGS,
5959
toggleAdvancedSettings,
60-
TOGGLE_THUMBNAIL,
60+
SET_THUMBNAIL_FLAG,
6161
toggleThumbnail,
6262
TOGGLE_TEMPLATE,
6363
toggleTemplate,
@@ -353,9 +353,15 @@ describe('Test correctness of the catalog actions', () => {
353353
const action = toggleTemplate();
354354
expect(action.type).toBe(TOGGLE_TEMPLATE);
355355
});
356-
it('test toggleThumbnail action', () => {
357-
const action = toggleThumbnail();
358-
expect(action.type).toBe(TOGGLE_THUMBNAIL);
356+
it('test toggleThumbnail action if toggleValue = true', () => {
357+
const action = toggleThumbnail(true);
358+
expect(action.type).toBe(SET_THUMBNAIL_FLAG);
359+
expect(action.toggleValue).toEqual(true);
360+
});
361+
it('test toggleThumbnail action if toggleValue = false', () => {
362+
const action = toggleThumbnail(false);
363+
expect(action.type).toBe(SET_THUMBNAIL_FLAG);
364+
expect(action.toggleValue).toEqual(false);
359365
});
360366
it('test changeMetadataTemplate action', () => {
361367
const action = changeMetadataTemplate("${title}");

web/client/actions/catalog.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const GET_METADATA_RECORD_BY_ID = 'CATALOG:GET_METADATA_RECORD_BY_ID';
4848
export const SET_LOADING = 'CATALOG:SET_LOADING';
4949
export const SHOW_FORMAT_ERROR = 'CATALOG:SHOW_FORMAT_ERROR';
5050
export const TOGGLE_TEMPLATE = 'CATALOG:TOGGLE_TEMPLATE';
51-
export const TOGGLE_THUMBNAIL = 'CATALOG:TOGGLE_THUMBNAIL';
51+
export const SET_THUMBNAIL_FLAG = 'CATALOG:SET_THUMBNAIL_FLAG';
5252
export const TOGGLE_ADVANCED_SETTINGS = 'CATALOG:TOGGLE_ADVANCED_SETTINGS';
5353
export const FORMAT_OPTIONS_FETCH = 'CATALOG:FORMAT_OPTIONS_FETCH';
5454
export const FORMAT_OPTIONS_LOADING = 'CATALOG:FORMAT_OPTIONS_LOADING';
@@ -294,7 +294,7 @@ export function getMetadataRecordById(metadataOptions) {
294294
export const changeMetadataTemplate = (metadataTemplate) => ({type: CHANGE_METADATA_TEMPLATE, metadataTemplate});
295295
export const toggleAdvancedSettings = () => ({type: TOGGLE_ADVANCED_SETTINGS});
296296
export const toggleTemplate = () => ({type: TOGGLE_TEMPLATE});
297-
export const toggleThumbnail = () => ({type: TOGGLE_THUMBNAIL});
297+
export const toggleThumbnail = (currentVal) => ({type: SET_THUMBNAIL_FLAG, toggleValue: currentVal});
298298
export const formatOptionsFetch = (url, force) => ({type: FORMAT_OPTIONS_FETCH, url, force});
299299
export const formatsLoading = (loading) => ({type: FORMAT_OPTIONS_LOADING, loading});
300300
export const setSupportedFormats = (formats, url) => ({type: SET_FORMAT_OPTIONS, formats, url});

web/client/components/catalog/Catalog.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class Catalog extends React.Component {
227227
// defaults for recordItem elements
228228
let metadataTemplate = "";
229229
let showTemplate = false;
230-
let hideThumbnail = false;
230+
let hideThumbnail = this.props.hideThumbnail;
231231

232232
if (this.props.services && this.props.services[this.props.selectedService]) {
233233
const selectedService = this.props.services[this.props.selectedService];

web/client/components/catalog/CatalogServiceEditor.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ const CatalogServiceEditor = ({
6666
infoFormatOptions,
6767
services,
6868
autoSetVisibilityLimits = false,
69-
disabled
69+
disabled,
70+
hideThumbnail
7071
}) => {
7172
const [valid, setValid] = useState(true);
7273
return (<BorderLayout
@@ -107,6 +108,7 @@ const CatalogServiceEditor = ({
107108
formatsLoading={formatsLoading}
108109
infoFormatOptions={infoFormatOptions}
109110
autoSetVisibilityLimits={autoSetVisibilityLimits}
111+
globalHideThumbnail={hideThumbnail}
110112
/>
111113
<FormGroup controlId="buttons" key="buttons">
112114
<Col xs={12}>

web/client/components/catalog/__tests__/Catalog-test.jsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,30 @@ describe('Test Catalog panel', () => {
7373
const expandButton = document.querySelector(expandClass);
7474
expect(expandButton).toExist(`${expandClass} does not exist`);
7575
});
76+
it('renders records without thumbnail for all services', () => {
77+
const title = "title";
78+
const description = "description";
79+
const item = ReactDOM.render(<Catalog
80+
services={{"csw": {
81+
type: "csw",
82+
url: "url",
83+
title: "csw",
84+
format: "image/png8",
85+
metadataTemplate: "<p>${title} and ${description}</p>"
86+
}}}
87+
searchOptions={{}}
88+
selectedService="csw"
89+
loading={false}
90+
mode="view"
91+
result={{numberOfRecordsMatched: 3}}
92+
records={[{title, description, references: []}, {title, description, references: []}, {title, description, references: []}]}
93+
hideThumbnail
94+
/>, document.getElementById("container"));
95+
expect(item).toExist();
96+
const previewClassName = ".mapstore-side-preview";
97+
const preview = document.querySelectorAll(previewClassName);
98+
expect(preview.length).toEqual(0);
99+
});
76100
it('renders records without thumbnail for a specific service', () => {
77101
const title = "title";
78102
const description = "description";

web/client/components/catalog/editor/AdvancedSettings/CommonAdvancedSettings.jsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ import InfoPopover from '../../../widgets/widget/InfoPopover';
1818
* - autoload: Option allows the automatic fetching of the results upon selecting the service from Service dropdown
1919
* - hideThumbnail: Options allows to hide the thumbnail on the result
2020
*
21+
* @prop {boolean} globalHideThumbnail - Global default cfg for thumbnail visibility.
22+
* @prop {object} service the service to edit
23+
* @prop {function} onChangeServiceProperty handler (key, value) to change a property of service.
24+
* @prop {function} onToggleThumbnail - Thumbnail toggle handler.
2125
*/
2226
export default ({
2327
children,
28+
globalHideThumbnail,
2429
service,
2530
onChangeServiceProperty = () => { },
2631
onToggleThumbnail = () => { }
2732
}) => {
33+
const showThumbnailValue = !isNil(service.hideThumbnail) ? !service.hideThumbnail : !isNil(globalHideThumbnail) ? !globalHideThumbnail : true;
2834
return (
2935
<>
3036
<FormGroup controlId="autoload" key="autoload">
@@ -35,8 +41,8 @@ export default ({
3541
</FormGroup>
3642
<FormGroup controlId="thumbnail" key="thumbnail">
3743
<Checkbox
38-
onChange={() => onToggleThumbnail()}
39-
checked={!isNil(service.hideThumbnail) ? !service.hideThumbnail : true}>
44+
onChange={(evt) => onToggleThumbnail(!evt.target.checked)}
45+
checked={showThumbnailValue}>
4046
<Message msgId="catalog.showPreview" />
4147
</Checkbox>
4248
</FormGroup>

web/client/components/catalog/editor/AdvancedSettings/TMSAdvancedEditor.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ const INITIAL_CODE_VALUE = {
2929
* - *forceDefaultTileGrid*: When `provider` is `tms`, the option allows to force the usage of global projection's tile grid rather than one provided by server.
3030
* Useful for TMS services that advertise wrong origin or resolutions
3131
* - *customTMSConfiguration*: Allows user to configure the tile URL template manually. For more info [Custom TMS](https://mapstore.readthedocs.io/en/latest/user-guide/catalog/#custom-tms)
32-
*
32+
* @prop {boolean} globalHideThumbnail - Global default for thumbnail visibility.
3333
* @prop {object} service the service to edit
34+
* @prop {function} setValid - Validity state callback.
35+
* @prop {function} onToggleThumbnail - Thumbnail toggle handler.
3436
* @prop {function} onChangeServiceProperty handler (key, value) to change a property of service.
3537
*/
3638
export default ({
39+
globalHideThumbnail,
3740
service = {},
3841
setValid = () => { },
3942
onToggleThumbnail = () => {},
@@ -62,6 +65,8 @@ export default ({
6265
}
6366
setValid(false);
6467
};
68+
const showThumbnailValue = !isNil(service.hideThumbnail) ? !service.hideThumbnail : !isNil(globalHideThumbnail) ? !globalHideThumbnail : true;
69+
6570
return (<div>
6671
<FormGroup controlId="autoload" key="autoload">
6772
{service.autoload !== undefined && <Checkbox key="autoload" value="autoload"
@@ -70,8 +75,8 @@ export default ({
7075
<Message msgId="catalog.autoload" />
7176
</Checkbox>}
7277
<Checkbox key="thumbnail" value="thumbnail"
73-
onChange={() => onToggleThumbnail()}
74-
checked={!isNil(service.hideThumbnail) ? !service.hideThumbnail : true}>
78+
onChange={(evt) => onToggleThumbnail(!evt.target.checked)}
79+
checked={showThumbnailValue}>
7580
<Message msgId="catalog.showPreview" />
7681
</Checkbox>
7782
{service.provider === "tms"

web/client/components/catalog/editor/AdvancedSettings/__tests__/CommonAdvancedSettings-test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,51 @@ describe('Test common advanced settings', () => {
105105
expect(interactiveLegendLabel).toBeTruthy();
106106
expect(interactiveLegendLabel.innerHTML).toEqual('layerProperties.enableInteractiveLegendInfo.label');
107107
});
108+
109+
it('test if thumbnail checkbox is checked when globalHideThumbnail is true', () => {
110+
ReactDOM.render(
111+
<CommonAdvancedSettings
112+
globalHideThumbnail
113+
service={{ type: "csw" }}
114+
/>, document.getElementById("container"));
115+
116+
const thumbnailCheckbox = document.querySelector('.checkbox input');
117+
expect(thumbnailCheckbox).toBeTruthy();
118+
expect(thumbnailCheckbox.checked).toBeFalsy();
119+
});
120+
it('test if thumbnail checkbox is checked when globalHideThumbnail is false', () => {
121+
ReactDOM.render(
122+
<CommonAdvancedSettings
123+
globalHideThumbnail={false}
124+
service={{ type: "csw" }}
125+
/>, document.getElementById("container"));
126+
127+
const thumbnailCheckbox = document.querySelector('.checkbox input');
128+
expect(thumbnailCheckbox).toBeTruthy();
129+
expect(thumbnailCheckbox.checked).toBeTruthy();
130+
});
131+
it('test if thumbnail checkbox is checked when service.hideThumbnail is false', () => {
132+
ReactDOM.render(
133+
<CommonAdvancedSettings
134+
globalHideThumbnail
135+
service={{ type: "csw", hideThumbnail: false }}
136+
/>, document.getElementById("container"));
137+
138+
const thumbnailCheckbox = document.querySelector('.checkbox input');
139+
expect(thumbnailCheckbox).toBeTruthy();
140+
expect(thumbnailCheckbox.checked).toBeTruthy();
141+
});
142+
it('test if thumbnail checkbox is not checked when service.hideThumbnail is true', () => {
143+
ReactDOM.render(
144+
<CommonAdvancedSettings
145+
globalHideThumbnail
146+
service={{ type: "csw", hideThumbnail: true }}
147+
/>, document.getElementById("container"));
148+
149+
const thumbnailCheckbox = document.querySelector('.checkbox input');
150+
expect(thumbnailCheckbox).toBeTruthy();
151+
// here the priority for service hideThumbnail
152+
expect(thumbnailCheckbox.checked).toBeFalsy();
153+
});
154+
108155
});

web/client/plugins/MetadataExplorer.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ export const BackgroundSelectorAdd = connect(
370370
* @class
371371
* @name MetadataExplorer
372372
* @memberof plugins
373-
* @prop {string} cfg.hideThumbnail shows/hides thumbnail
373+
* @prop {string} cfg.hideThumbnail - Global configuration for thumbnail visibility.
374+
* - **Value**: `true` to hide thumbnails globally, `false` to show thumbnails in catalog.
375+
* - **Overrides**: Service-specific configurations take precedence.
374376
* @prop {object[]} cfg.serviceTypes Service types available to add a new catalog. default: `[{ name: "csw", label: "CSW" }, { name: "wms", label: "WMS" }, { name: "wmts", label: "WMTS" }, { name: "tms", label: "TMS", allowedProviders },{ name: "wfs", label: "WFS" },{ name: "flatgeobuf", label: "FlatGeobuf" }]`.
375377
* `allowedProviders` is a whitelist of tileProviders from ConfigProvider.js. you can set a global variable allowedProviders in localConfig.json to set it up globally. You can configure it to "ALL" to get all the list (at your own risk, some services could change or not be available anymore)
376378
* @prop {object} cfg.hideIdentifier shows/hides identifier

web/client/reducers/__tests__/catalog-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import {
4949
DELETE_CATALOG_SERVICE,
5050
SAVING_SERVICE,
5151
CHANGE_METADATA_TEMPLATE,
52-
TOGGLE_THUMBNAIL,
52+
SET_THUMBNAIL_FLAG,
5353
TOGGLE_TEMPLATE,
5454
TOGGLE_ADVANCED_SETTINGS,
5555
addCatalogService,
@@ -292,14 +292,14 @@ describe('Test the catalog reducer', () => {
292292
}}, {type: CHANGE_CATALOG_MODE, mode, isNew});
293293
expect(state2.newService.title).toBe("tit");
294294
});
295-
it('TOGGLE_THUMBNAIL ', () => {
295+
it('SET_THUMBNAIL_FLAG ', () => {
296296
const state = catalog({
297297
newService: {}
298-
}, {type: TOGGLE_THUMBNAIL});
298+
}, {type: SET_THUMBNAIL_FLAG, toggleValue: true});
299299
expect(state.newService.hideThumbnail).toBe(true);
300300
const state2 = catalog({
301301
newService: {hideThumbnail: true}
302-
}, {type: TOGGLE_THUMBNAIL});
302+
}, {type: SET_THUMBNAIL_FLAG, toggleValue: false});
303303
expect(state2.newService.hideThumbnail).toBe(false);
304304
});
305305
it('TOGGLE_TEMPLATE toggling on the template', () => {

0 commit comments

Comments
 (0)