Skip to content

Commit

Permalink
AB#1064 events
Browse files Browse the repository at this point in the history
  • Loading branch information
Francisco del Castillo committed Jul 16, 2024
1 parent 8cab706 commit 5eee26d
Show file tree
Hide file tree
Showing 82 changed files with 5,125 additions and 81 deletions.
50 changes: 50 additions & 0 deletions anet-dictionary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,52 @@ fields:
authorizationGroupRelatedObjects:
label: Members

eventSeries:
hostOrg:
label: Host Organization
placeholder: Search for the organization hosting the event series...
adminOrg:
label: Admin Organization
placeholder: Search for the organization that will manage the event series in ANET...
name:
label: Name
placeholder: The name of the event series
description:
label: Description
placeholder: The description of the event series

event:
eventSeries:
label: Event Series this event belongs to
placeholder: Search for an event series
hostOrg:
label: Host Organization
placeholder: Search for the organization hosting the event...
adminOrg:
label: Admin Organization
placeholder: Search for the organization that will manage the event in ANET...
location:
label: Location where the event takes place
placeholder: Search for a location…
type:
label: Type
placeholder: The type of the event
name:
label: Name
placeholder: The name of the event
description:
label: Description
placeholder: The description of the event
startDate:
label: Start Date
placeholder: The start date of the event
endDate:
label: End Date
placeholder: The end date of the event
outcomes:
label: Outcomes
placeholder: The outcomes of the event

report:
canUnpublishReports: true
intent:
Expand Down Expand Up @@ -392,6 +438,10 @@ fields:
- label: Linguists
filter:
orgUuid: 70193ee9-05b4-4aac-80b5-75609825db9f
event:
label: Event
placeholder: Was the engagement part of an event?
filter: [CONFERENCE, EXERCISE, VISIT_BAN, OTHER]
customFields:
gridLocation:
type: geo_location
Expand Down
9 changes: 6 additions & 3 deletions client/src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const SEARCH_OBJECT_TYPES = {
LOCATIONS: "LOCATIONS",
TASKS: "TASKS",
AUTHORIZATION_GROUPS: "AUTHORIZATION_GROUPS",
ATTACHMENTS: "ATTACHMENTS"
ATTACHMENTS: "ATTACHMENTS",
EVENTS: "EVENTS"
}

export const SEARCH_OBJECT_LABELS = {
Expand All @@ -36,7 +37,8 @@ export const SEARCH_OBJECT_LABELS = {
[SEARCH_OBJECT_TYPES.LOCATIONS]: "Locations",
[SEARCH_OBJECT_TYPES.TASKS]: pluralize(Settings.fields.task.shortLabel),
[SEARCH_OBJECT_TYPES.AUTHORIZATION_GROUPS]: "Authorization Groups",
[SEARCH_OBJECT_TYPES.ATTACHMENTS]: "Attachments"
[SEARCH_OBJECT_TYPES.ATTACHMENTS]: "Attachments",
[SEARCH_OBJECT_TYPES.EVENTS]: "Events"
}

export const DEFAULT_SEARCH_PROPS = {
Expand All @@ -49,7 +51,8 @@ export const DEFAULT_SEARCH_PROPS = {
SEARCH_OBJECT_TYPES.LOCATIONS,
SEARCH_OBJECT_TYPES.TASKS,
SEARCH_OBJECT_TYPES.AUTHORIZATION_GROUPS,
SEARCH_OBJECT_TYPES.ATTACHMENTS
SEARCH_OBJECT_TYPES.ATTACHMENTS,
SEARCH_OBJECT_TYPES.EVENTS
]
}
export const DEFAULT_SEARCH_QUERY = {
Expand Down
8 changes: 7 additions & 1 deletion client/src/components/CreateButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { useNavigate } from "react-router-dom"

const DEFAULT_ACTIONS = [Models.Report]

const SUPERUSER_ACTIONS = [Models.Person, Models.Position, Models.Location]
const SUPERUSER_ACTIONS = [
Models.Person,
Models.Position,
Models.Location,
Models.Event,
Models.EventSeries
]

const ADMIN_ACTIONS = [
Models.Organization,
Expand Down
9 changes: 7 additions & 2 deletions client/src/components/CustomDateInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const CustomDateInput = ({
className,
disabled,
showIcon,
minDate,
maxDate,
placement,
withTime,
Expand Down Expand Up @@ -73,8 +74,10 @@ const CustomDateInput = ({
return dt.isValid() ? dt.toDate() : false
}}
placeholder={inputFormat}
maxDate={maxDate}
minDate={moment().subtract(100, "years").startOf("year").toDate()}
maxDate={maxDate || moment().add(20, "years").endOf("year").toDate()}
minDate={
minDate || moment().subtract(100, "years").startOf("year").toDate()
}
canClearSelection={canClearSelection}
showActionsBar
closeOnSelection={!withTime}
Expand All @@ -92,6 +95,7 @@ CustomDateInput.propTypes = {
disabled: PropTypes.bool,
showIcon: PropTypes.bool,
maxDate: PropTypes.instanceOf(Date),
minDate: PropTypes.instanceOf(Date),
placement: PropTypes.string,
withTime: PropTypes.bool,
value: PropTypes.oneOfType([
Expand All @@ -107,6 +111,7 @@ CustomDateInput.defaultProps = {
disabled: false,
showIcon: true,
maxDate: moment().add(20, "years").endOf("year").toDate(),
minDate: moment().subtract(100, "years").startOf("year").toDate(),
placement: "auto",
withTime: false,
canClearSelection: false
Expand Down
74 changes: 74 additions & 0 deletions client/src/components/EventCalendar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import API from "api"
import { eventToCalendarEvents } from "components/aggregations/utils"
import Calendar from "components/Calendar"
import Model from "components/Model"
import { PageDispatchersPropType } from "components/Page"
import _isEqual from "lodash/isEqual"
import { Event } from "models"
import moment from "moment"
import PropTypes from "prop-types"
import React, { useRef } from "react"
import { useNavigate } from "react-router-dom"

const EventCalendar = ({
pageDispatchers: { showLoading, hideLoading },
queryParams,
setTotalCount
}) => {
const navigate = useNavigate()
const prevEventQuery = useRef(null)
const apiPromise = useRef(null)
const calendarComponentRef = useRef(null)
return (
<Calendar
events={getEvents}
eventClick={info => {
navigate(info.event.url)
// Prevent browser navigation to the url
info.jsEvent.preventDefault()
}}
calendarComponentRef={calendarComponentRef}
/>
)

function getEvents(fetchInfo, successCallback, failureCallback) {
const eventQuery = Object.assign({}, queryParams, {
status: Model.STATUS.ACTIVE,
pageSize: 0,
startDate: moment(fetchInfo.start).startOf("day"),
endDate: moment(fetchInfo.end).endOf("day")
})
if (_isEqual(prevEventQuery.current, eventQuery)) {
// Optimise, return API promise instead of calling API.query again
return apiPromise.current
}
prevEventQuery.current = eventQuery
if (setTotalCount) {
// Reset the total count
setTotalCount(null)
}
// Store API promise to use in optimised case
showLoading()
apiPromise.current = API.query(Event.getEventListQuery, {
eventQuery
}).then(data => {
const events = data ? data.eventList.list : []
if (setTotalCount) {
const { totalCount } = data.eventList
setTotalCount(totalCount)
}
const results = eventToCalendarEvents(events)
hideLoading()
return results
})
return apiPromise.current
}
}

EventCalendar.propTypes = {
pageDispatchers: PageDispatchersPropType,
queryParams: PropTypes.object,
setTotalCount: PropTypes.func
}

export default EventCalendar
150 changes: 150 additions & 0 deletions client/src/components/EventCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { setPagination } from "actions"
import ButtonToggleGroup from "components/ButtonToggleGroup"
import EventCalendar from "components/EventCalendar"
import EventMap from "components/EventMap"
import EventSummary from "components/EventSummary"
import EventTable from "components/EventTable"
import {
mapPageDispatchersToProps,
PageDispatchersPropType
} from "components/Page"
import PropTypes from "prop-types"
import React, { useState } from "react"
import { Button } from "react-bootstrap"
import { connect } from "react-redux"

export const FORMAT_CALENDAR = "calendar"
export const FORMAT_MAP = "map"
export const FORMAT_SUMMARY = "summary"
export const FORMAT_TABLE = "table"

const EventCollection = ({
pageDispatchers,
paginationKey,
pagination,
setPagination,
viewFormats,
queryParams,
setTotalCount,
mapId,
width,
height,
marginBottom
}) => {
const [viewFormat, setViewFormat] = useState(viewFormats[0])
const showHeader = viewFormats.length > 1
return (
<div className="event-collection">
<div>
{showHeader && (
<header>
{viewFormats.length > 1 && (
<>
<ButtonToggleGroup
value={viewFormat}
onChange={setViewFormat}
className="d-print-none"
>
{viewFormats.includes(FORMAT_TABLE) && (
<Button value={FORMAT_TABLE} variant="outline-secondary">
Table
</Button>
)}
{viewFormats.includes(FORMAT_SUMMARY) && (
<Button value={FORMAT_SUMMARY} variant="outline-secondary">
Summary
</Button>
)}
{viewFormats.includes(FORMAT_CALENDAR) && (
<Button value={FORMAT_CALENDAR} variant="outline-secondary">
Calendar
</Button>
)}
{viewFormats.includes(FORMAT_MAP) && (
<Button value={FORMAT_MAP} variant="outline-secondary">
Map
</Button>
)}
</ButtonToggleGroup>
</>
)}
</header>
)}

<div>
{viewFormat === FORMAT_TABLE && (
<EventTable
pageDispatchers={pageDispatchers}
paginationKey={paginationKey}
pagination={pagination}
setPagination={setPagination}
queryParams={queryParams}
setTotalCount={setTotalCount}
/>
)}
{viewFormat === FORMAT_SUMMARY && (
<EventSummary
pageDispatchers={pageDispatchers}
paginationKey={paginationKey}
pagination={pagination}
setPagination={setPagination}
queryParams={queryParams}
setTotalCount={setTotalCount}
/>
)}
{viewFormat === FORMAT_CALENDAR && (
<EventCalendar
pageDispatchers={pageDispatchers}
queryParams={queryParams}
setTotalCount={setTotalCount}
/>
)}
{viewFormat === FORMAT_MAP && (
<EventMap
pageDispatchers={pageDispatchers}
queryParams={queryParams}
setTotalCount={setTotalCount}
mapId={mapId}
width={width}
height={height}
marginBottom={marginBottom}
/>
)}
</div>
</div>
</div>
)
}

EventCollection.propTypes = {
pageDispatchers: PageDispatchersPropType,
paginationKey: PropTypes.string,
pagination: PropTypes.object.isRequired,
setPagination: PropTypes.func.isRequired,
viewFormats: PropTypes.arrayOf(PropTypes.string),
queryParams: PropTypes.object,
setTotalCount: PropTypes.func,
mapId: PropTypes.string,
width: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
height: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
marginBottom: PropTypes.oneOfType([PropTypes.number, PropTypes.string])
}

EventCollection.defaultProps = {
viewFormats: [FORMAT_TABLE, FORMAT_SUMMARY, FORMAT_CALENDAR, FORMAT_MAP]
}

const mapDispatchToProps = (dispatch, ownProps) => {
const pageDispatchers = mapPageDispatchersToProps(dispatch, ownProps)
return {
setPagination: (pageKey, pageNum) =>
dispatch(setPagination(pageKey, pageNum)),
...pageDispatchers
}
}

const mapStateToProps = (state, ownProps) => ({
pagination: state.pagination
})

export default connect(mapStateToProps, mapDispatchToProps)(EventCollection)
Loading

0 comments on commit 5eee26d

Please sign in to comment.