Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #9075. Handle cases when domain isnot in format start--end #9076

Merged
merged 2 commits into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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