Skip to content
Open
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
10 changes: 6 additions & 4 deletions src/actions/selection-plan-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,10 @@ export const deleteSelectionPlanExtraQuestionValue =

/** ********************* EVENT TYPES ****************************************** */

export const EVENT_TYPE_ADDED = "EVENT_TYPE_ADDED";
export const EVENT_TYPE_REMOVED = "EVENT_TYPE_REMOVED";
export const SELECTION_PLAN_EVENT_TYPE_ADDED =
"SELECTION_PLAN_EVENT_TYPE_ADDED";
export const SELECTION_PLAN_EVENT_TYPE_REMOVED =
"SELECTION_PLAN_EVENT_TYPE_REMOVED";

export const addEventTypeSelectionPlan =
(selectionPlanId, eventType) => async (dispatch, getState) => {
Expand All @@ -606,7 +608,7 @@ export const addEventTypeSelectionPlan =

return putRequest(
null,
createAction(EVENT_TYPE_ADDED)({ eventType }),
createAction(SELECTION_PLAN_EVENT_TYPE_ADDED)({ eventType }),
`${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/selection-plans/${selectionPlanId}/event-types/${eventType.id}`,
{},
authErrorHandler
Expand All @@ -628,7 +630,7 @@ export const deleteEventTypeSelectionPlan =

return deleteRequest(
null,
createAction(EVENT_TYPE_REMOVED)({ eventTypeId }),
createAction(SELECTION_PLAN_EVENT_TYPE_REMOVED)({ eventTypeId }),
`${window.API_BASE_URL}/api/v1/summits/${currentSummit.id}/selection-plans/${selectionPlanId}/event-types/${eventTypeId}`,
null,
authErrorHandler
Expand Down
77 changes: 41 additions & 36 deletions src/pages/events/summit-event-list-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ import {
DEFAULT_CURRENT_PAGE,
DEFAULT_PER_PAGE,
DEFAULT_Z_INDEX,
HIGH_Z_INDEX,
INDEX_NOT_FOUND
HIGH_Z_INDEX
} from "../../utils/constants";
import {
defaultColumns,
Expand All @@ -68,6 +67,7 @@ import {
} from "../../actions/filter-criteria-actions";
import { CONTEXT_ACTIVITIES } from "../../utils/filter-criteria-constants";
import EditableTable from "../../components/tables/editable-table/EditableTable";
import { buildNameIdDDL } from "../../utils/events/summit-event-list-page.utils";

const fieldNames = (allSelectionPlans, allTracks, event_types) => [
{
Expand Down Expand Up @@ -113,9 +113,7 @@ const fieldNames = (allSelectionPlans, allTracks, event_types) => [
value: "track",
sortable: true,
editableField: (extraProps) => {
const track_ddl = allTracks
?.sort((a, b) => a.order - b.order)
.map((t) => ({ label: t.name, value: t.id }));
const track_ddl = buildNameIdDDL(allTracks);

return (
<Dropdown
Expand Down Expand Up @@ -152,29 +150,44 @@ const fieldNames = (allSelectionPlans, allTracks, event_types) => [
value: "selection_plan",
sortable: true,
editableField: (extraProps) => {
if (!extraProps.row.type?.id) return false;

const event_type = event_types.find(
(t) => t.id === extraProps.row.type?.id
);
const isValid = (obj, keys) =>
keys.every((k) => obj && typeof obj[k] !== "undefined");
const isValidSP = (sp) =>
sp &&
typeof sp.id !== "undefined" &&
typeof sp.name === "string" &&
sp.name.trim();

if (!extraProps.row?.type?.id) return false;
const event_type = Array.isArray(event_types)
? event_types.find(
(t) => isValid(t, ["id"]) && t.id === extraProps.row.type?.id
)
: null;
if (!event_type) return false;

const allowSelectionPlanEdit =
["PresentationType"].indexOf(event_type.class_name) !==
INDEX_NOT_FOUND ||
["PresentationType"].indexOf(event_type.name) !== INDEX_NOT_FOUND;

["PresentationType"].includes(event_type.class_name) ||
["PresentationType"].includes(event_type.name);
if (!allowSelectionPlanEdit) return false;

const track = allTracks.find((t) => t.id === extraProps.row?.track?.id);

const selection_plans_per_track = allSelectionPlans
.filter(
(sp) =>
!track ||
sp.track_groups.some((gr) => track.track_groups.includes(gr))
)
?.sort((a, b) => a.order - b.order)
.map((sp) => ({ label: sp.name, value: sp.id }));
const trackId = extraProps.row?.track?.id;
const track =
trackId !== undefined && trackId !== null
? allTracks.find((t) => isValid(t, ["id"]) && t.id === trackId)
: null;

const selection_plans_per_track = buildNameIdDDL(
(Array.isArray(allSelectionPlans) ? allSelectionPlans : [])
.filter(isValidSP)
.filter(
(sp) =>
!track ||
(Array.isArray(sp.track_groups) &&
Array.isArray(track.track_groups) &&
sp.track_groups.some((gr) => track.track_groups.includes(gr)))
)
);

return (
<Dropdown
Expand Down Expand Up @@ -1013,13 +1026,9 @@ class SummitEventListPage extends React.Component {
}
};

const selection_plans_ddl = currentSummit.selection_plans
?.sort((a, b) => a.order - b.order)
.map((sp) => ({ label: sp.name, value: sp.id }));
const selection_plans_ddl = buildNameIdDDL(currentSummit.selection_plans);

const location_ddl = currentSummit.locations
?.sort((a, b) => a.order - b.order)
.map((l) => ({ label: l.name, value: l.id }));
const location_ddl = buildNameIdDDL(currentSummit.locations);

const selection_status_ddl = [
{ label: "Pending", value: "pending" },
Expand All @@ -1028,13 +1037,9 @@ class SummitEventListPage extends React.Component {
{ label: "Alternate", value: "alternate" }
];

const track_ddl = currentSummit.tracks
?.sort((a, b) => a.order - b.order)
.map((t) => ({ label: t.name, value: t.id }));
const track_ddl = buildNameIdDDL(currentSummit.tracks);

const event_type_ddl = currentSummit.event_types
?.sort((a, b) => a.order - b.order)
.map((t) => ({ label: t.name, value: t.id }));
const event_type_ddl = buildNameIdDDL(currentSummit.event_types);

const level_ddl = [
{ label: "Beginner", value: "beginner" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import selectionPlanReducer from "../selection-plan-reducer";
import { SELECTION_PLAN_EVENT_TYPE_ADDED } from "../../../actions/selection-plan-actions";

describe("SelectionPlanReducer", () => {
describe("SELECTION_PLAN_EVENT_TYPE_ADDED", () => {
test("should append event type for selection plan event type added action", () => {
const initialState = {
entity: {
id: 1,
event_types: [{ id: 1, name: "Talk" }],
track_groups: [],
extra_questions: [],
allowed_presentation_action_types: [],
track_chair_rating_types: [],
marketing_settings: {}
},
allowedMembers: { data: [], currentPage: 1, lastPage: 1 },
errors: {}
};

const eventType = { id: 2, name: "Workshop" };
const result = selectionPlanReducer(initialState, {
type: SELECTION_PLAN_EVENT_TYPE_ADDED,
payload: { eventType }
});

expect(result.entity.event_types).toStrictEqual([
{ id: 1, name: "Talk" },
{ id: 2, name: "Workshop" }
]);
});
});
});
53 changes: 26 additions & 27 deletions src/reducers/selection_plans/selection-plan-reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
SELECTION_PLAN_ADDED,
TRACK_GROUP_REMOVED,
TRACK_GROUP_ADDED,
EVENT_TYPE_ADDED,
EVENT_TYPE_REMOVED,
SELECTION_PLAN_EVENT_TYPE_ADDED,
SELECTION_PLAN_EVENT_TYPE_REMOVED,
SELECTION_PLAN_EXTRA_QUESTION_ADDED,
SELECTION_PLAN_EXTRA_QUESTION_DELETED,
SELECTION_PLAN_EXTRA_QUESTION_UPDATED,
Expand Down Expand Up @@ -123,9 +123,8 @@ const selectionPlanReducer = (state = DEFAULT_STATE, action) => {
// we need this in case the token expired while editing the form
if (payload.hasOwnProperty("persistStore")) {
return state;
}
return { ...state, entity: { ...DEFAULT_ENTITY }, errors: {} };

}
return { ...state, entity: { ...DEFAULT_ENTITY }, errors: {} };
}
case SET_CURRENT_SUMMIT:
case RESET_SELECTION_PLAN_FORM: {
Expand Down Expand Up @@ -176,10 +175,10 @@ const selectionPlanReducer = (state = DEFAULT_STATE, action) => {
}
case RECEIVE_SELECTION_PLAN_PROGRESS_FLAGS: {
const progressFlags = payload.response.data.map((r) => ({
id: r.id,
label: r.label,
order: parseInt(r.order)
}));
id: r.id,
label: r.label,
order: parseInt(r.order)
}));
return {
...state,
entity: {
Expand All @@ -203,10 +202,10 @@ const selectionPlanReducer = (state = DEFAULT_STATE, action) => {
}
case SELECTION_PLAN_PROGRESS_FLAG_ORDER_UPDATED: {
const progressFlags = payload.map((r) => ({
id: r.id,
label: r.label,
order: parseInt(r.order)
}));
id: r.id,
label: r.label,
order: parseInt(r.order)
}));
return {
...state,
entity: {
Expand Down Expand Up @@ -249,14 +248,14 @@ const selectionPlanReducer = (state = DEFAULT_STATE, action) => {
}
};
}
case EVENT_TYPE_REMOVED: {
case SELECTION_PLAN_EVENT_TYPE_REMOVED: {
const { eventTypeId } = payload;
const eventTypes = state.entity.event_types.filter(
(t) => t.id !== eventTypeId
);
return { ...state, entity: { ...state.entity, event_types: eventTypes } };
}
case EVENT_TYPE_ADDED: {
case SELECTION_PLAN_EVENT_TYPE_ADDED: {
const eventType = { ...payload.eventType };
return {
...state,
Expand Down Expand Up @@ -307,12 +306,12 @@ const selectionPlanReducer = (state = DEFAULT_STATE, action) => {

case SELECTION_PLAN_EXTRA_QUESTION_ORDER_UPDATED: {
const extra_questions = payload.map((q, i) => ({
id: q.id,
name: q.name,
label: q.label,
type: q.type,
order: i + 1
}));
id: q.id,
name: q.name,
label: q.label,
type: q.type,
order: i + 1
}));

return {
...state,
Expand Down Expand Up @@ -357,11 +356,11 @@ const selectionPlanReducer = (state = DEFAULT_STATE, action) => {
}
case SELECTION_PLAN_RATING_TYPE_ORDER_UPDATED: {
const track_chair_rating_types = payload.map((r) => ({
id: r.id,
name: r.name,
weight: parseFloat(r.weight),
order: parseInt(r.order)
}));
id: r.id,
name: r.name,
weight: parseFloat(r.weight),
order: parseInt(r.order)
}));
return {
...state,
entity: {
Expand Down Expand Up @@ -396,7 +395,7 @@ const selectionPlanReducer = (state = DEFAULT_STATE, action) => {
return { ...state, errors: payload.errors };
}
case RECEIVE_SELECTION_PLAN_SETTINGS: {
const {data} = payload.response;
const { data } = payload.response;
// parse data
const settings = data.map((ms) => ({
[ms.key.toLowerCase()]: {
Expand Down
50 changes: 50 additions & 0 deletions src/reducers/summits/__tests__/current-summit-reducer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import currentSummitReducer, { DEFAULT_STATE } from "../current-summit-reducer";
import { EVENT_TYPE_ADDED } from "../../../actions/event-type-actions";
import { SELECTION_PLAN_EVENT_TYPE_ADDED } from "../../../actions/selection-plan-actions";

describe("CurrentSummitReducer", () => {
describe("SELECTION_PLAN_EVENT_TYPE_ADDED", () => {
test("should ignore selection plan event type added action", () => {
const initialState = {
...DEFAULT_STATE,
currentSummit: {
...DEFAULT_STATE.currentSummit,
event_types: [{ id: 1, name: "Talk" }]
}
};

const result = currentSummitReducer(initialState, {
type: SELECTION_PLAN_EVENT_TYPE_ADDED,
payload: { eventType: { id: 2, name: "Workshop" } }
});

expect(result).toBe(initialState);
expect(result.currentSummit.event_types).toStrictEqual([
{ id: 1, name: "Talk" }
]);
});
});

describe("EVENT_TYPE_ADDED", () => {
test("should append event type for summit event type added action", () => {
const initialState = {
...DEFAULT_STATE,
currentSummit: {
...DEFAULT_STATE.currentSummit,
event_types: [{ id: 1, name: "Talk" }]
}
};

const response = { id: 2, name: "Workshop" };
const result = currentSummitReducer(initialState, {
type: EVENT_TYPE_ADDED,
payload: { response }
});

expect(result.currentSummit.event_types).toStrictEqual([
{ id: 1, name: "Talk" },
{ id: 2, name: "Workshop" }
]);
});
});
});
Loading
Loading