Commit ec1716f1 authored by Alejandro De Maria Antolinos's avatar Alejandro De Maria Antolinos
Browse files

Merge branch 'issue_504-adapt_ui_investigations' into 'master'

Resolve Issue 504 "date filter on manager beamline calendar"

Closes #504

See merge request !525
parents a9166f60 8662f03d
Pipeline #48825 passed with stages
in 10 minutes and 51 seconds
......@@ -10,6 +10,8 @@ import Timeline, {
import 'react-calendar-timeline/lib/Timeline.css';
import { Link } from 'react-router-dom';
import moment from 'moment';
import InstrumentResource from '../../resources/instrument';
import { useQuery } from '../../helpers/hooks';
const COLOR_EMPTY_SESSION = 'white';
const COLOR_NON_SCHEDULED_SESSION = 'red';
......@@ -52,22 +54,28 @@ function itemRenderer(props) {
}
function InvestigationsCalendarTimeLine() {
const investigations = useResource(InvestigationResource.listShape(), {});
const dateFormat = 'YYYY-MM-DD';
const query = useQuery();
const startDate = query.get('startDate')
? moment(query.get('startDate'), dateFormat)
: moment().startOf('month');
const endDate = query.get('endDate')
? moment(query.get('endDate'), dateFormat)
: moment().add(1, 'month').startOf('month');
const instrumentNames = [
...new Set(
investigations.map((investigation) => {
const { instrument } = investigation;
return instrument.name;
})
),
].sort();
const investigations = useResource(InvestigationResource.listShape(), {
startDate: startDate.format(dateFormat),
endDate: endDate.format(dateFormat),
});
const instruments = useResource(InstrumentResource.listShape(), {});
let id = 1;
const groups = instrumentNames.map((instrumentName) => {
id++;
return { id, title: instrumentName };
const groups = [];
instruments.forEach((instrument) => {
groups.push({ id: id++, title: instrument.name });
});
groups.push({ id: id++, title: undefined });
const items = investigations.map((investigation) => {
return {
......@@ -95,8 +103,8 @@ function InvestigationsCalendarTimeLine() {
<Timeline
groups={groups}
items={items}
defaultTimeStart={moment().startOf('month')}
defaultTimeEnd={moment().add(1, 'month').startOf('month')}
defaultTimeStart={startDate}
defaultTimeEnd={endDate}
stackItems
itemHeightRatio={0.65}
showCursorLine
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment