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

More refactoring. New and edit works now

parent 5616310d
......@@ -29,7 +29,7 @@ function EventListMenu(props) {
sessionId,
getEvents,
periodicdata,
logbookContext,
isReleased,
eventCountSinceLastRefresh,
activePage,
categoryTypes,
......@@ -99,7 +99,7 @@ function EventListMenu(props) {
glyph="plus"
tooltipText="Create a new event"
isEnabled={isNewButtonEnabled}
isVisible={!logbookContext.isReleased}
isVisible={!isReleased}
/>
</NavItem>
......@@ -114,7 +114,7 @@ function EventListMenu(props) {
glyph="camera"
tooltipText="Take a photo"
isEnabled
isVisible={!logbookContext.isReleased}
isVisible={!isReleased}
/>
</NavItem>
</Nav>
......@@ -220,7 +220,7 @@ function EventListMenu(props) {
{isSettingsDisplayed && (
<SettingLogbookMenuPanel
categoryTypes={categoryTypes}
logbookContext={logbookContext}
isReleased={isReleased}
automaticCollapsing={automaticCollapsing}
automaticRefresh={automaticRefresh}
isSortingLatestEventsFirst={isSortingLatestEventsFirst}
......@@ -243,8 +243,8 @@ EventListMenu.propTypes = {
investigationId: PropTypes.number,
/** Whether the New button is enabled or not */
isNewButtonEnabled: PropTypes.bool,
/** Context in which the logbook is run */
logbookContext: PropTypes.object,
/** If investigation is relased */
isReleased: PropTypes.bool,
/** Selection filter for mongo request (used for PDF request) */
selectionFilter: PropTypes.object,
/** Session identifier */
......
......@@ -58,14 +58,17 @@ const checkBoxes = [
export default function SettingLogbookMenuPanel(props) {
const dispatch = useDispatch();
const {
isReleased,
automaticCollapsing,
automaticRefresh,
isSortingLatestEventsFirst,
} = props;
const getValueByName = (name) =>
checkBoxes.find((cb) => cb.name === name).value;
const logbookContext = props.logbookContext;
const toggleColor = '#428bca';
const automaticCollapsing = props.automaticCollapsing;
const automaticRefresh = props.automaticRefresh;
const isSortingLatestEventsFirst = props.isSortingLatestEventsFirst;
/** Checkbox will be checked if and only if its values are in the categoryTypes */
const isChecked = (values) => {
......@@ -129,7 +132,7 @@ export default function SettingLogbookMenuPanel(props) {
</Col>
<Col md={2} sm={6} xs={12}>
<Grid>
{!logbookContext.isReleased && (
{!isReleased && (
<Row>
<Col md={12} sm={12} xs={12}>
<Switch
......
......@@ -64,7 +64,7 @@ const AuthorAndTime = (props) => {
* React component which renders a Panel for creating of editing an event
*/
function NewOrEditEventPanel(props) {
const { event, user, investigationId } = props;
const { event, user, investigationId, refetch } = props;
const history = useHistory();
const query = useQuery();
......@@ -163,11 +163,13 @@ function NewOrEditEventPanel(props) {
type: ANNOTATION,
}
);
await refetch();
}
query.delete('edit');
history.push({ search: query.toString() });
} catch (e) {
console.log(e);
setError(`${e.status}:${e.message}`);
}
};
......
import React, { useEffect } from 'react';
import { useFetcher, useResource } from 'rest-hooks';
import { Col, Grid, Row } from 'react-bootstrap';
import { useParams } from 'react-router';
import { useResource } from 'rest-hooks';
import { useDispatch, useSelector } from 'react-redux';
import moment from 'moment';
import { useScrollToHash, useQuery } from '../helpers/hooks';
......@@ -16,7 +16,6 @@ import EventList from '../components/Logbook/List/EventList';
import EventListMenu from '../components/Logbook/Menu/EventListMenu';
import NewOrEditEventPanel from '../components/Logbook/NewOrEditEventPanel';
import OverlayBox from '../components/Logbook/OverlayBox';
import LoadingBoundary from '../components/LoadingBoundary';
const {
EVENTS_PER_PAGE,
......@@ -41,23 +40,28 @@ function EventsPage() {
id: investigationId,
});
const events = useResource(EventResource.listShape(), {
const fetchingParams = {
investigationId,
skip: EVENTS_PER_PAGE * (page - 1),
limit: EVENTS_PER_DOWNLOAD,
sortedBy: SORT_EVENTS_BY,
sortedOrder: SORTING_ORDER,
sortBy: SORT_EVENTS_BY,
sortOrder: SORTING_ORDER,
types: categoryTypes?.map((cat) =>
cat.category ? `${cat.type}-${cat.category}` : `${cat.type}`
),
});
};
const events = useResource(EventResource.listShape(), fetchingParams);
const refecth = useFetcher(EventResource.listShape());
const refetchEvent = () => {
refecth(fetchingParams);
};
const editEvent = events.find((event) => event._id === edit);
useScrollToHash({ milliseconds: 350, attempts: 50 });
//const search = query.get('search');
// Getting total number of events
let totalEventCount = events.length;
if (events && events.length > 0) {
......@@ -70,13 +74,6 @@ function EventsPage() {
}
}, [dispatch, investigation]);
const logbookContext = {
//name: LOGBOOK_CONTEXT_NAME_PROPOSAL,
isReleased:
!!investigation.releaseDate &&
moment().isAfter(investigation.releaseDate),
};
const isReleased =
!!investigation.releaseDate && moment().isAfter(investigation.releaseDate);
......@@ -93,13 +90,12 @@ function EventsPage() {
modal: 'newOrEditModalClass',
}}
>
<LoadingBoundary message="Loading your addresses..." spacedOut>
<NewOrEditEventPanel
event={editEvent}
investigationId={investigation.id}
user={user}
/>
</LoadingBoundary>
<NewOrEditEventPanel
event={editEvent}
investigationId={investigation.id}
user={user}
refetch={refetchEvent}
/>
</OverlayBox>
)}
......@@ -113,8 +109,8 @@ function EventsPage() {
eventCountBySelectionFilter={totalEventCount}
eventCountSinceLastRefresh={totalEventCount}
investigationId={investigation.id}
isNewButtonEnabled={!logbookContext.isReleased}
logbookContext={logbookContext}
isNewButtonEnabled={!isReleased}
isReleased={isReleased}
sessionId={sessionId}
/>
......
......@@ -14,17 +14,20 @@ export default class EventResource extends Resource {
}
static listUrl(params) {
const {
investigationId,
skip,
limit,
sortedOrder,
sortedBy,
types,
} = params;
const { investigationId, skip, limit, sortOrder, sortBy, types } = params;
const { sessionId } = store.getState().user;
if (investigationId) {
return `${ICATPLUS.server}/logbook/${sessionId}/event?investigationId=${investigationId}&skip=${skip}&limit=${limit}&sortBy=${sortedBy}&sortOrder=${sortedOrder}&types=${types}`;
const params = new URLSearchParams();
params.set('investigationId', investigationId);
if (limit) params.set('limit', limit);
if (sortBy) params.set('sortBy', sortBy);
if (sortOrder) params.set('sortOrder', sortOrder);
if (types) params.set('types', types);
if (skip) params.set('skip', skip);
return `${
ICATPLUS.server
}/logbook/${sessionId}/event?${params.toString()}`;
}
}
......
Supports Markdown
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