Skip to content

Commit

Permalink
[SDESK-2480] Refactored the code so that it relies on "type" of the d…
Browse files Browse the repository at this point in the history
…ocument instead of "_type".
  • Loading branch information
Mayur Dhamanwala committed Mar 15, 2018
1 parent 7b74c37 commit f061937
Show file tree
Hide file tree
Showing 63 changed files with 248 additions and 257 deletions.
2 changes: 1 addition & 1 deletion client/actions/assignments/tests/notification_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ describe('actions.assignments.notification', () => {
sinon.stub(assignmentsApi, 'fetchAssignmentById').callsFake(() => (
Promise.resolve(store.initialState.assignment.assignments.as1)));

store.initialState.locks.assignments = {as1: {user: 'ident1'}};
store.initialState.locks.assignment = {as1: {user: 'ident1'}};
store.initialState.workspace.currentDeskId = 'desk1';
let payload = {
item: 'as1',
Expand Down
2 changes: 2 additions & 0 deletions client/actions/assignments/tests/ui_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ describe('actions.assignments.ui', () => {
const newAssignment = {
_id: 'as3',
_type: 'assignments',
type: 'assignment',
coverage_id: 'c2',
planning_item: 'p1',
assigned_to: {
Expand All @@ -523,6 +524,7 @@ describe('actions.assignments.ui', () => {
const restrictedAssignment = {
_id: 'as4',
_type: 'assignments',
type: 'assignment',
coverage_id: 'c2',
planning_item: 'p1',
assigned_to: {
Expand Down
4 changes: 1 addition & 3 deletions client/actions/events/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ const loadEventDataForAction = (event, loadPlanning = true, publish = false, loa
start: moment(event.dates.start),
end: moment(event.dates.end),
},
_type: 'events',
type: 'event',
_recurring: relatedEvents.events,
_publish: publish,
_events: [],
Expand Down Expand Up @@ -1171,8 +1171,6 @@ const duplicate = (event) => (
api('events_duplicate', event).save({})
.then((newEvent) => {
newEvent.files = event.files;
newEvent._type = 'events';

return Promise.resolve(newEvent);
}, (error) => Promise.reject(error))
)
Expand Down
2 changes: 1 addition & 1 deletion client/actions/events/tests/notifications_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ describe('actions.events.notifications', () => {
});

it('dispatches notification modal if the Event unlocked is being edited', (done) => {
store.initialState.locks.events = {
store.initialState.locks.event = {
e1: {
action: 'edit',
user: 'ident1',
Expand Down
2 changes: 1 addition & 1 deletion client/actions/eventsPlanning/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const query = (

if (get(data, '_items')) {
data._items.forEach((item) => {
if (item._type === 'events') {
if (item.type === 'event') {
eventUtils.convertToMoment(item);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion client/actions/locks.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const unlock = (item) => (
switch (currentLock.item_type) {
case 'planning':
return dispatch(planning.api.unlock({_id: currentLock.item_id}));
case 'events':
case 'event':
return dispatch(events.api.unlock({_id: currentLock.item_id}));
}
}
Expand Down
14 changes: 8 additions & 6 deletions client/actions/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ const save = (item, withConfirmation = true) => (
promise = dispatch(planningUi.save(item));
break;
default:
promise = Promise.reject(gettext('Failed to save, could not find the item type!'));
promise = Promise.reject(
gettext('Failed to save, could not find the item {{itemType}}!', {itemType: itemType})
);
break;
}

Expand Down Expand Up @@ -504,7 +506,7 @@ const openEditor = (item) => (
});

// Update the URL
$timeout(() => $location.search('edit', JSON.stringify({id: item._id, type: item._type})));
$timeout(() => $location.search('edit', JSON.stringify({id: item._id, type: item.type})));
}
);

Expand Down Expand Up @@ -537,12 +539,12 @@ const openPreview = (item) => (
type: MAIN.ACTIONS.SET_PREVIEW_ITEM,
payload: {
itemId: item._id,
itemType: item._type
itemType: item.type
}
});

// Update the URL
$timeout(() => $location.search('preview', JSON.stringify({id: item._id, type: item._type})));
$timeout(() => $location.search('preview', JSON.stringify({id: item._id, type: item.type})));
}
);

Expand Down Expand Up @@ -645,12 +647,12 @@ const openFromURLOrRedux = (action) => (
if (action === MAIN.PREVIEW) {
dispatch(self.openPreview({
_id: item.id,
_type: item.type
type: item.type
}));
} else if (action === MAIN.EDIT) {
dispatch(self.openEditor({
_id: item.id,
_type: item.type
type: item.type
}));
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion client/actions/planning/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ const duplicate = (plan) => (
(dispatch, getState, {api}) => (
api('planning_duplicate', plan).save({})
.then((newPlan) => {
newPlan._type = 'planning';
newPlan.type = 'planning';
return Promise.resolve(newPlan);
}, (error) => (
Promise.reject(error)
Expand Down
26 changes: 13 additions & 13 deletions client/actions/tests/main_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('actions.main', () => {
expect(services.$location.search.callCount).toBe(1);
expect(services.$location.search.args[0]).toEqual([
'edit',
JSON.stringify({id: 'e1', type: 'events'})
JSON.stringify({id: 'e1', type: 'event'})
]);
});

Expand Down Expand Up @@ -221,7 +221,7 @@ describe('actions.main', () => {
it('closes the preview panel if item being edited is open for preview', (done) => {
store.init();
store.initialState.main.previewId = data.events[1]._id;
store.initialState.main.previewType = data.events[1]._type;
store.initialState.main.previewType = data.events[1].type;
store.test(done, main.lockAndEdit(data.events[1]))
.then((item) => {
expect(item).toEqual(data.events[1]);
Expand Down Expand Up @@ -398,7 +398,7 @@ describe('actions.main', () => {
});

it('loads an Event for preview', (done) => (
store.test(done, main.loadItem('e1', 'events', 'preview'))
store.test(done, main.loadItem('e1', 'event', 'preview'))
.then((item) => {
expect(item).toEqual(data.events[0]);

Expand All @@ -415,7 +415,7 @@ describe('actions.main', () => {
));

it('loads an Event for editing', (done) => (
store.test(done, main.loadItem('e1', 'events', 'edit'))
store.test(done, main.loadItem('e1', 'event', 'edit'))
.then((item) => {
expect(item).toEqual(data.events[0]);

Expand Down Expand Up @@ -466,7 +466,7 @@ describe('actions.main', () => {
));

it('fails if unknown action type supplied', (done) => (
store.test(done, main.loadItem('e1', 'events', 'dummy'))
store.test(done, main.loadItem('e1', 'event', 'dummy'))
.then(null, (error) => {
expect(error).toBe('Unknown action "dummy"');
expect(store.dispatch.callCount).toBe(0);
Expand Down Expand Up @@ -507,36 +507,36 @@ describe('actions.main', () => {

it('loads the preview item from the URL', () => {
store.init();
services.$location.search('preview', JSON.stringify({id: 'e1', type: 'events'}));
services.$location.search('preview', JSON.stringify({id: 'e1', type: 'event'}));
store.test(null, main.openFromURLOrRedux('preview'));
expect(main.openPreview.callCount).toBe(1);
expect(main.openPreview.args[0]).toEqual([{_id: 'e1', _type: 'events'}]);
expect(main.openPreview.args[0]).toEqual([{_id: 'e1', type: 'event'}]);
});

it('loads the preview item from the Redux store', () => {
store.init();
store.initialState.main.previewId = 'e1';
store.initialState.main.previewType = 'events';
store.initialState.main.previewType = 'event';
store.test(null, main.openFromURLOrRedux('preview'));
expect(main.openPreview.callCount).toBe(1);
expect(main.openPreview.args[0]).toEqual([{_id: 'e1', _type: 'events'}]);
expect(main.openPreview.args[0]).toEqual([{_id: 'e1', type: 'event'}]);
});

it('loads the edit item from the URL', () => {
store.init();
services.$location.search('edit', JSON.stringify({id: 'e1', type: 'events'}));
services.$location.search('edit', JSON.stringify({id: 'e1', type: 'event'}));
store.test(null, main.openFromURLOrRedux('edit'));
expect(main.openEditor.callCount).toBe(1);
expect(main.openEditor.args[0]).toEqual([{_id: 'e1', _type: 'events'}]);
expect(main.openEditor.args[0]).toEqual([{_id: 'e1', type: 'event'}]);
});

it('loads the edit item from the Redux store', () => {
store.init();
store.initialState.forms.itemId = 'e1';
store.initialState.forms.itemType = 'events';
store.initialState.forms.itemType = 'event';
store.test(null, main.openFromURLOrRedux('edit'));
expect(main.openEditor.callCount).toBe(1);
expect(main.openEditor.args[0]).toEqual([{_id: 'e1', _type: 'events'}]);
expect(main.openEditor.args[0]).toEqual([{_id: 'e1', type: 'event'}]);
});
});
});
4 changes: 2 additions & 2 deletions client/components/Events/EventHistory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ const mapDispatchToProps = (dispatch) => ({
openPlanningClick: (planningId) => (
dispatch(actions.main.openPreview({
_id: planningId,
_type: 'planning',
type: 'planning',
}))
),
openEventPreview: (eventId) => {
dispatch(actions.main.openPreview({
_id: eventId,
_type: 'events',
type: 'event',
}));
}
});
Expand Down
2 changes: 1 addition & 1 deletion client/components/Events/EventItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class EventItem extends React.PureComponent {
onEventCapture(e);
onItemClick({
_id: item.reschedule_from,
_type: 'events',
type: 'event',
});
}}
text={actionedState.label}
Expand Down
2 changes: 1 addition & 1 deletion client/components/Events/EventMetadata/_test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('<EventMetadata />', () => {
},
name: 'name1',
occur_status: {name: 'Planned, occurs certainly'},
_type: 'events',
type: 'event',
};
let store = createTestStore();
const wrapper = mount(
Expand Down
6 changes: 3 additions & 3 deletions client/components/Events/EventMetadata/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const EventMetadata = (
<span className="sd-overflow-ellipsis sd-list-item--element-grow">
<span className="sd-list-item__text-strong">{event.name}</span>
</span>
<time title>{dateStr}</time>
<time>{dateStr}</time>
</Row>
</Column>
</Item>
Expand All @@ -60,15 +60,15 @@ export const EventMetadata = (
mapUrl={streetMapUrl}
/>
</span>
<time title>{dateStr}</time>
<time>{dateStr}</time>
</Row>
</div>
) : (
<Row>
<span className="sd-overflow-ellipsis sd-list-item--element-grow">
<span className="sd-list-item__text-strong">{event.name}</span>
</span>
<time title>{dateStr}</time>
<time>{dateStr}</time>
</Row>
)}
</Column>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('<EventPreviewContent />', () => {
astore.initialState.planning.plannings.p2.original_creator =
astore.initialState.users[0];
astore.initialState.main.previewId = 'e1';
astore.initialState.main.previewType = 'events';
astore.initialState.main.previewType = 'event';

const getWrapper = () => {
const store = createTestStore({initialState: astore.initialState});
Expand Down
4 changes: 2 additions & 2 deletions client/components/Events/tests/EventPreviewHeader_test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ describe('<EventPreviewHeader />', () => {

astore.initialState.events.events.e1.lock_user = sessions[1].identity;
astore.initialState.events.events.e1.lock_session = sessions[1].session;
astore.initialState.locks.events = {e1: {user: sessions[1].identity._id}};
astore.initialState.locks.event = {e1: {user: sessions[1].identity._id}};
astore.initialState.main.previewId = 'e1';
astore.initialState.main.previewType = 'events';
astore.initialState.main.previewType = 'event';

const getWrapper = () => {
const store = createTestStore({initialState: astore.initialState});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const mapDispatchToProps = (dispatch) => ({
}
},

onValidate: (item, profile, errors) => dispatch(validateItem('events', item, profile, errors, ['dates']))
onValidate: (item, profile, errors) => dispatch(validateItem('event', item, profile, errors, ['dates']))
});

export const ConvertToRecurringEventForm = connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ const mapDispatchToProps = (dispatch) => ({
onSubmit: (event) => dispatch(actions.events.ui.rescheduleEvent(event)),
onHide: (event) => dispatch(actions.events.api.unlock(event)),

onValidate: (item, profile, errors) => dispatch(validateItem('events', item, profile, errors, ['dates']))
onValidate: (item, profile, errors) => dispatch(validateItem('event', item, profile, errors, ['dates']))
});

export const RescheduleEventForm = connect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(actions.events.api.unlock(event));
}
},
onValidate: (item, profile, errors) => dispatch(validateItem('events', item, profile, errors, ['dates']))
onValidate: (item, profile, errors) => dispatch(validateItem('event', item, profile, errors, ['dates']))
});

export const UpdateTimeForm = connect(
Expand Down
2 changes: 1 addition & 1 deletion client/components/ItemIcon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const ItemIcon = ({item, big, white, blue, showRepeating}) => {
icon = planningIcon;
title = 'Planning';
multiValidator = planningUtils.isPlanMultiDay;
} else if (itemType === ITEM_TYPE.ARCHIVE) {
} else if (itemType !== ITEM_TYPE.EVENT) {
icon = archiveIcon;
multiValidator = () => false;
}
Expand Down
2 changes: 1 addition & 1 deletion client/components/ListItem/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ListItem extends React.Component {
handleDragStart(e) {
e.dataTransfer.effectAllowed = 'copy';
e.dataTransfer.setData(
`application/superdesk.item.${this.props.item._type}`,
`application/superdesk.item.${this.props.item.type}`,
JSON.stringify(this.props.item)
);
}
Expand Down
2 changes: 1 addition & 1 deletion client/components/Main/ItemEditor/tests/Editor_test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Main.ItemEditor.Editor', () => {
});

if (item.lock_user) {
item._type === ITEM_TYPE.EVENT ?
item.type === ITEM_TYPE.EVENT ?
store.dispatch({
type: EVENTS.ACTIONS.LOCK_EVENT,
payload: {event: item}
Expand Down
2 changes: 1 addition & 1 deletion client/components/Planning/PlanningEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class PlanningEditorComponent extends React.Component {
this.props.contentTypes);

let newPlanning = {
_type: ITEM_TYPE.PLANNING,
type: ITEM_TYPE.PLANNING,
slugline: addNewsItemToPlanning.slugline,
planning_date: moment(),
ednote: get(addNewsItemToPlanning, 'ednote'),
Expand Down
2 changes: 1 addition & 1 deletion client/components/Planning/PlanningHistory.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const mapDispatchToProps = (dispatch) => ({
openPlanningPreview: (planningId) => (
dispatch(actions.main.openPreview({
_id: planningId,
_type: 'planning',
type: 'planning',
}))
),
});
Expand Down
2 changes: 1 addition & 1 deletion client/components/RelatedPlannings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const mapDispatchToProps = (dispatch) => ({
openPlanningClick: (planningId, agenda) => (
dispatch(actions.main.openPreview({
_id: planningId,
_type: 'planning',
type: 'planning',
}))
),
});
Expand Down

0 comments on commit f061937

Please sign in to comment.