diff --git a/web/client/api/GeoStoreDAO.js b/web/client/api/GeoStoreDAO.js index 346f97e5c8..189412283a 100644 --- a/web/client/api/GeoStoreDAO.js +++ b/web/client/api/GeoStoreDAO.js @@ -27,7 +27,7 @@ const createAttributeList = (metadata = {}) => { const attributes = metadata.attributes || omit(metadata, ["name", "description", "id", "advertised"]); const xmlAttrs = Object.keys(attributes).map((key) => { - return "" + key + "" + attributes[key] + "STRING"; + return "" + key + "STRING"; }); let attributesSection = ""; if (xmlAttrs.length > 0) { diff --git a/web/client/api/__tests__/GeoStoreDAO-test.jsx b/web/client/api/__tests__/GeoStoreDAO-test.jsx index c9900dd8f5..5df791ac7c 100644 --- a/web/client/api/__tests__/GeoStoreDAO-test.jsx +++ b/web/client/api/__tests__/GeoStoreDAO-test.jsx @@ -207,9 +207,9 @@ describe('Test correctness of the GeoStore APIs', () => { metadata = API.createAttributeList(metadata); expect(metadata).toEqual( "" + - "ninaninaSTRING" + - "eatingeatingSTRING" + - "plasticplasticSTRING" + + "ninaSTRING" + + "eatingSTRING" + + "plasticSTRING" + "" ); }); diff --git a/web/client/api/usersession/__tests__/server-test.js b/web/client/api/usersession/__tests__/server-test.js index 0187ea7caf..f326416df7 100644 --- a/web/client/api/usersession/__tests__/server-test.js +++ b/web/client/api/usersession/__tests__/server-test.js @@ -33,9 +33,13 @@ describe('usersession API server implementation', () => { } }); server.writeSession(null, "myname", "myuser", {myprop: "myvalue"}).subscribe((id) => { - expect(id).toBe(1); - expect(mockAxios.history.post[0].data).toContain(""); - expect(mockAxios.history.post[0].data).toContain("myuser"); + try { + expect(id).toBe(1); + expect(mockAxios.history.post[0].data).toContain(""); + expect(mockAxios.history.post[0].data).toContain(""); + } catch (e) { + done(e); + } done(); }); }); diff --git a/web/client/plugins/ResourcesCatalog/api/__tests__/resources-test.js b/web/client/plugins/ResourcesCatalog/api/__tests__/resources-test.js index 9184a7b2c7..78a55a6449 100644 --- a/web/client/plugins/ResourcesCatalog/api/__tests__/resources-test.js +++ b/web/client/plugins/ResourcesCatalog/api/__tests__/resources-test.js @@ -252,7 +252,10 @@ describe('resources api', () => { "category": { "id": 5, "name": "MAP" }, "id": 1, "name": "Map", - "attributes": { "context": 2 }, + "attributes": { + "context": 2, + "detailsSettings": {} + }, "@extras": { "context": { "category": { "id": 3, "name": "CONTEXT" }, diff --git a/web/client/plugins/ResourcesCatalog/api/resources.js b/web/client/plugins/ResourcesCatalog/api/resources.js index 7e721602f1..f166e772e1 100644 --- a/web/client/plugins/ResourcesCatalog/api/resources.js +++ b/web/client/plugins/ResourcesCatalog/api/resources.js @@ -139,6 +139,17 @@ const getFilter = ({ }; }; +const parseDetailsSettings = (detailsSettings) => { + if (isString(detailsSettings)) { + try { + return JSON.parse(detailsSettings); + } catch (e) { + return {}; + } + } + return detailsSettings || {}; +}; + export const requestResources = ({ params } = {}, { user } = {}) => { @@ -199,8 +210,13 @@ export const requestResources = ({ isNextPageAvailable: page < (response?.totalCount / pageSize), resources: resources .map(({ tags, ...resource }) => { + const detailsSettings = parseDetailsSettings(resource?.attributes?.detailsSettings); return { ...resource, + attributes: { + ...resource?.attributes, + detailsSettings + }, ...(tags && { tags: castArray(tags) }) }; }) @@ -221,17 +237,6 @@ export const requestResources = ({ }); }; -const parseDetailsSettings = (detailsSettings) => { - if (isString(detailsSettings)) { - try { - return JSON.parse(detailsSettings); - } catch (e) { - return {}; - } - } - return detailsSettings || {}; -}; - export const requestResource = ({ resource, user }) => { return getResource(resource.id, { includeAttributes: true, withData: false, withPermissions: !!user }) .toPromise() diff --git a/web/client/plugins/ResourcesCatalog/utils/ResourcesUtils.js b/web/client/plugins/ResourcesCatalog/utils/ResourcesUtils.js index 6f9dcbcb0a..e2623f7634 100644 --- a/web/client/plugins/ResourcesCatalog/utils/ResourcesUtils.js +++ b/web/client/plugins/ResourcesCatalog/utils/ResourcesUtils.js @@ -8,6 +8,7 @@ import { isEmpty, isEqual, omit, isArray, isObject } from 'lodash'; import merge from 'lodash/fp/merge'; +import uuid from 'uuid/v1'; const NODATA = 'NODATA'; @@ -104,7 +105,8 @@ export const computePendingChanges = (initialResource, resource, resourceData) = ]; const categoryOptions = { 'thumbnail': { - tail: '/raw?decode=datauri', + // this forces the reload the thumbnail image when updated + tail: `/raw?decode=datauri&v=${uuid()}`, category: 'THUMBNAIL' }, 'details': { diff --git a/web/client/plugins/ResourcesCatalog/utils/__tests__/ResourcesUtils-test.js b/web/client/plugins/ResourcesCatalog/utils/__tests__/ResourcesUtils-test.js index ffbd63e2f7..c076f3a3c2 100644 --- a/web/client/plugins/ResourcesCatalog/utils/__tests__/ResourcesUtils-test.js +++ b/web/client/plugins/ResourcesCatalog/utils/__tests__/ResourcesUtils-test.js @@ -127,38 +127,6 @@ describe('ResourcesUtils', () => { } ); - expect(computePendingChanges( - { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } }, - { id: 1, name: 'Title', attributes: { thumbnail: '' }, category: { name: 'MAP' } })).toEqual( - { - initialResource: { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } }, - resource: { id: 1, name: 'Title', attributes: { thumbnail: '' }, category: { name: 'MAP' } }, - saveResource: { - id: 1, - permission: undefined, - category: 'MAP', - metadata: { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' } }, - linkedResources: { thumbnail: { tail: '/raw?decode=datauri', category: 'THUMBNAIL', value: '/thumb', data: 'NODATA' } } - }, - changes: { linkedResources: { thumbnail: { tail: '/raw?decode=datauri', category: 'THUMBNAIL', value: '/thumb', data: 'NODATA' } } } } - ); - - expect(computePendingChanges( - { id: 1, name: 'Title', attributes: {}, category: { name: 'MAP' } }, - { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } })).toEqual( - { - initialResource: { id: 1, name: 'Title', attributes: { }, category: { name: 'MAP' } }, - resource: { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } }, - saveResource: { - id: 1, - permission: undefined, - category: 'MAP', - metadata: { id: 1, name: 'Title', attributes: {} }, - linkedResources: { thumbnail: { tail: '/raw?decode=datauri', category: 'THUMBNAIL', value: 'NODATA', data: '/thumb' } } - }, - changes: { linkedResources: { thumbnail: { tail: '/raw?decode=datauri', category: 'THUMBNAIL', value: 'NODATA', data: '/thumb' } } } } - ); - expect(computePendingChanges( { id: 1, name: 'Title', attributes: {}, category: { name: 'MAP' } }, { id: 1, name: 'Title', attributes: { details: '/details' }, category: { name: 'MAP' } })).toEqual( @@ -184,6 +152,26 @@ describe('ResourcesUtils', () => { } ); }); + it('computePendingChanges with thumbnail', () => { + let computedChanges = computePendingChanges( + { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } }, + { id: 1, name: 'Title', attributes: { thumbnail: '' }, category: { name: 'MAP' } }); + expect(computedChanges.initialResource).toEqual({ id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } }); + expect(computedChanges.resource).toEqual({ id: 1, name: 'Title', attributes: { thumbnail: '' }, category: { name: 'MAP' } }); + expect(computedChanges.changes.linkedResources.thumbnail.value).toBe('/thumb'); + expect(computedChanges.changes.linkedResources.thumbnail.data).toBe('NODATA'); + + computedChanges = computePendingChanges( + { id: 1, name: 'Title', attributes: {}, category: { name: 'MAP' } }, + { id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } }); + expect(computedChanges.initialResource).toEqual({ id: 1, name: 'Title', attributes: { }, category: { name: 'MAP' } }); + expect(computedChanges.resource).toEqual({ id: 1, name: 'Title', attributes: { thumbnail: '/thumb' }, category: { name: 'MAP' } }); + expect(computedChanges.changes.linkedResources.thumbnail.value).toBe('NODATA'); + expect(computedChanges.changes.linkedResources.thumbnail.data).toBe('/thumb'); + const tailsParts = computedChanges.changes.linkedResources.thumbnail.tail.split('&'); + expect(tailsParts[0]).toBe('/raw?decode=datauri'); + expect(tailsParts[1].includes('v=')).toBe(true); + }); it('computePendingChanges with tags', () => { const computed = computePendingChanges( { id: 1, name: 'Title', category: { name: 'MAP' }, tags: [{ id: '01' }, { id: '02' }] },