Skip to content

Commit

Permalink
Fix geosolutions-it#9075. Handle cases when domain isnot in format st…
Browse files Browse the repository at this point in the history
…art--end (geosolutions-it#9076)

* Fix geosolutions-it#9075. Handle cases when domain isnot in format start--end

* Update web/client/epics/timeline.js

---------

Co-authored-by: Suren <[email protected]>
  • Loading branch information
offtherailz and dsuren1 committed Apr 6, 2023
1 parent 41dc821 commit 9be3251
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 6 deletions.
163 changes: 163 additions & 0 deletions web/client/epics/__tests__/timeline-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,169 @@ describe('timeline Epics', () => {
}
});
});
it("setRangeOnInit on domain returned as list", (done) => {
testEpic(setRangeOnInit, 3, initializeRange(), ([action1, action2, action3]) => {
const { time, type } = action1;
const { offsetTime, type: typeOff} = action2;
const { type: typeRange } = action3;
expect(time).toEqual("2000-01-01T00:00:00.000Z");
expect(offsetTime).toBeTruthy();
expect(type).toBe(SET_CURRENT_TIME);
expect(typeOff).toBe(SET_OFFSET_TIME);
expect(typeRange).toBe(RANGE_CHANGED);
done();
}, {
timeline: {
selectedLayer: "TEST_LAYER",
settings: {
initialMode: 'range',
initialSnap: 'fullRange'
}
},
dimension: {
currentTime: "2000-01-01T00:00:00.000Z",
offsetTime: "2001-12-31T00:00:00.000Z",
data: {
time: {
TEST_LAYER: {
name: "time",
domain: "2000-01-01T00:00:00.000Z,2001-12-31T00:00:00.000Z"
}
}
}
},
layers: {
flat: [{
id: 'TEST_LAYER',
name: 'TEST_LAYER',
type: 'wms',
visibility: true,
url: 'base/web/client/test-resources/wmts/DomainValues.xml',
dimensions: [
{
source: {
type: 'multidim-extension',
url: 'base/web/client/test-resources/wmts/DomainValues.xml'
},
name: 'time'
}
],
params: {
time: '2000-06-08T00:00:00.000Z'
}
}]
}
});
});
it("setRangeOnInit on domain returned as single time", (done) => {
testEpic(setRangeOnInit, 3, initializeRange(), ([action1, action2, action3]) => {
const { time, type } = action1;
const { offsetTime, type: typeOff} = action2;
const { type: typeRange } = action3;
expect(time).toBeTruthy();
expect(offsetTime).toBeTruthy();
expect(time).toBe("2000-01-01T00:00:00.000Z");
expect(type).toBe(SET_CURRENT_TIME);
expect(typeOff).toBe(SET_OFFSET_TIME);
expect(typeRange).toBe(RANGE_CHANGED);
done();
}, {
timeline: {
selectedLayer: "TEST_LAYER",
settings: {
initialMode: 'range',
initialSnap: 'fullRange'
}
},
dimension: {
currentTime: "2000-01-01T00:00:00.000Z",
offsetTime: "2001-12-31T00:00:00.000Z",
data: {
time: {
TEST_LAYER: {
name: "time",
domain: "2000-01-01T00:00:00.000Z"
}
}
}
},
layers: {
flat: [{
id: 'TEST_LAYER',
name: 'TEST_LAYER',
type: 'wms',
visibility: true,
url: 'base/web/client/test-resources/wmts/DomainValues.xml',
dimensions: [
{
source: {
type: 'multidim-extension',
url: 'base/web/client/test-resources/wmts/DomainValues.xml'
},
name: 'time'
}
],
params: {
time: '2000-06-08T00:00:00.000Z'
}
}]
}
});
});
it("setRangeOnInit on domain returned empty", (done) => {
testEpic(setRangeOnInit, 3, initializeRange(), ([action1, action2, action3]) => {
const { time, type } = action1;
const { offsetTime, type: typeOff} = action2;
const { type: typeRange } = action3;
expect(time).toBeTruthy();
expect(offsetTime).toBeTruthy();
expect(type).toBe(SET_CURRENT_TIME);
expect(typeOff).toBe(SET_OFFSET_TIME);
expect(typeRange).toBe(RANGE_CHANGED);
done();
}, {
timeline: {
selectedLayer: "TEST_LAYER",
settings: {
initialMode: 'range',
initialSnap: 'fullRange'
}
},
dimension: {
currentTime: "2000-01-01T00:00:00.000Z",
offsetTime: "2001-12-31T00:00:00.000Z",
data: {
time: {
TEST_LAYER: {
name: "time",
domain: ""
}
}
}
},
layers: {
flat: [{
id: 'TEST_LAYER',
name: 'TEST_LAYER',
type: 'wms',
visibility: true,
url: 'base/web/client/test-resources/wmts/DomainValues.xml',
dimensions: [
{
source: {
type: 'multidim-extension',
url: 'base/web/client/test-resources/wmts/DomainValues.xml'
},
name: 'time'
}
],
params: {
time: '2000-06-08T00:00:00.000Z'
}
}]
}
});
});
});
it("updateTimelineDataOnMapLoad", (done) =>{
const config = {
Expand Down
31 changes: 25 additions & 6 deletions web/client/epics/timeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,22 +202,41 @@ const loadRangeData = (id, timeData, getState) => {
/**
* Update timeline with current, offset and the range data
* on range initialization
* @param state
* @param {string} value
* @param state application state
* @param {string|string[]} value the range values. It can be an array or a domain string. (`start--end`, `start,x1,x2,x3,end` or `start,end`)
* @param {string} [currentTime]
* @returns {Observable}
*/
const updateRangeOnInit = (state, value, currentTime) => {
const { isFullRange, offsetTime } = state;
// The startTime and endTime is full range of the layer
let [startTime, endTime] = value?.filter(v => !!v) || [];
const start = isFullRange ? startTime : currentTime;
let values;

// convert to array
if (isString(value)) {
if (value.indexOf('--') > 0) {
values = value.split('--');
} else if (value.indexOf(',') > 0) {
values = value.split(',');
} else {
values = [value]; // single value is the last chance
}
} else {
values = value;
}

if (values.length > 2) {
values = [values[0], values[values.length - 1]]; // more than 2 values, start and end are the first and last values
}

let [startTime, endTime] = values?.filter(v => !!v) || [];
const start = isFullRange ? startTime ?? currentTime : currentTime;

// Set the offset 1 day by default
const rangeDistance = moment(1000 * 60 * 60 * 24 * RATIO).diff(0);
const defaultOffset = moment(new Date()).add(rangeDistance / RATIO).toISOString();

const end = isFullRange ? endTime : (offsetTime ?? defaultOffset);
const end = isFullRange ? endTime ?? defaultOffset : (offsetTime ?? defaultOffset);
const difference = moment(end).diff(moment(start));
const nextEnd = moment(start).add(difference).toISOString();
// Set current, offset and the range of the timeline
Expand Down Expand Up @@ -456,7 +475,7 @@ export const setRangeOnInit = (action$, { getState = () => { } } = {}) =>

if (!isEmpty(domain) && !isEmpty(currentTime)) {
// Update range when domain and current time present
return updateRangeOnInit(rangeState, domain?.split("--"), currentTime);
return updateRangeOnInit(rangeState, domain, currentTime);
} else if ((isEmpty(domain) && !isEmpty(currentTime)) || rangeState.isFullRange) {
// Get time domain and set range
return updateRangeObs(currentTime);
Expand Down

0 comments on commit 9be3251

Please sign in to comment.