Skip to content

Commit

Permalink
automatically show related plannings added to event
Browse files Browse the repository at this point in the history
atm it's a workaround, but eventually we will need to
get rid of `planning_ids` on event which is computed
on load but without updating event itself it gets
cached.

STT-86
  • Loading branch information
petrjasek committed Oct 3, 2024
1 parent 8419963 commit aee7f08
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
7 changes: 7 additions & 0 deletions client/actions/agenda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {getErrorMessage, gettext, planningUtils} from '../utils';
import {planning, showModal, main} from './index';
import {convertStringFields} from '../utils/strings';
import planningApis from '../actions/planning/api';
import eventsApis from '../actions/events/api';

const openAgenda = () => (
(dispatch) => (
Expand Down Expand Up @@ -311,6 +312,12 @@ const createPlanningFromEvent = (

return (dispatch) => (
dispatch(planningApis.save({}, newPlanningItem))
.then((planningResponse) => {
return dispatch(eventsApis.fetchById(event.guid, {force: true, saveToStore: true, loadPlanning: false}))
.then(() => {
return planningResponse;
});
})
);
};

Expand Down
2 changes: 1 addition & 1 deletion client/actions/events/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ const fetchById = (eventId, {force = false, saveToStore = true, loadPlanning = t
if (has(storedEvents, eventId) && !force) {
promise = Promise.resolve(storedEvents[eventId]);
} else {
promise = planningApi.events.getById(eventId)
promise = planningApi.events.getById(eventId, force ? {cache: false} : undefined)
.then((event) => {
if (saveToStore) {
dispatch(self.receiveEvents([event]));
Expand Down
5 changes: 3 additions & 2 deletions client/api/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ISearchSpikeState,
IPlanningConfig,
IEventUpdateMethod,
IGetRequestParams,
} from '../interfaces';
import {appConfig as config} from 'appConfig';
import {IRestApiResponse} from 'superdesk-api';
Expand Down Expand Up @@ -70,9 +71,9 @@ export function searchEventsGetAll(params: ISearchParams): Promise<Array<IEventI
});
}

export function getEventById(eventId: IEventItem['_id']): Promise<IEventItem> {
export function getEventById(eventId: IEventItem['_id'], params: IGetRequestParams): Promise<IEventItem> {
return superdeskApi.dataApi
.findOne<IEventItem>('events', eventId)
.findOne<IEventItem>('events', eventId + (params?.cache === false ? `?time=${Math.floor(Date.now() / 1000)}` : ''))
.then(modifyItemForClient);
}

Expand Down
6 changes: 5 additions & 1 deletion client/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2186,14 +2186,18 @@ export interface IEditorAPI {
};
}

export interface IGetRequestParams {
cache?: boolean;
}

export interface IPlanningAPI {
redux: {
store: Store;
};
events: {
search(params: ISearchParams): Promise<IRestApiResponse<IEventItem>>;
searchGetAll(params: ISearchParams): Promise<Array<IEventItem>>;
getById(eventId: IEventItem['_id']): Promise<IEventItem>;
getById(eventId: IEventItem['_id'], params?: IGetRequestParams): Promise<IEventItem>;
getByIds(eventIds: Array<IEventItem['_id']>, spikeState?: ISearchSpikeState): Promise<Array<IEventItem>>;
getEditorProfile(): IEventFormProfile;
getSearchProfile(): IEventSearchProfile;
Expand Down
2 changes: 1 addition & 1 deletion client/reducers/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ const eventsReducer = createReducer<IEventState>(initialState, {
[EVENTS.ACTIONS.EVENT_RECENT_TEMPLATES]: (state, payload) => ({
...state,
recentEventTemplates: payload,
})
}),
});

const onEventPostChanged = (state, payload) => {
Expand Down

0 comments on commit aee7f08

Please sign in to comment.