Skip to content

Commit

Permalink
Authoring react post broadcasting (#1904)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskikutis authored Feb 6, 2024
1 parent 65434dc commit 218767b
Show file tree
Hide file tree
Showing 22 changed files with 1,744 additions and 821 deletions.
10 changes: 4 additions & 6 deletions client/actions/assignments/ui.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {get, cloneDeep, forEach} from 'lodash';
import moment from 'moment';

import {planningApi} from '../../superdeskApi';
import {planningApi, superdeskApi} from '../../superdeskApi';
import {IAssignmentItem} from '../../interfaces';

import {showModal} from '../index';
Expand Down Expand Up @@ -628,12 +628,10 @@ function startWorking(assignment: IAssignmentItem) {
promise.then(() =>
(planningApi.locks.lockItem(assignment, 'start_working')
.then((lockedAssignment) => {
const currentDesk = assignmentUtils.getCurrentSelectedDesk(desks, getState());
const defaultTemplateId = get(currentDesk, 'default_content_template') || null;
const defaultTemplateId = assignmentUtils
.getCurrentSelectedDesk(desks, getState())?.default_content_template ?? null;

return templates.fetchTemplatesByUserDesk(
session.identity._id,
get(currentDesk, '_id') || null,
return superdeskApi.entities.templates.getUserTemplates(
1,
200,
'create'
Expand Down
15 changes: 4 additions & 11 deletions client/actions/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -823,22 +823,15 @@ function _filter(filterType: PLANNING_VIEW, params: ICombinedEventOrPlanningSear
if (currentFilterId != undefined || filterType === PLANNING_VIEW.COMBINED) {
promise = planningApi.ui.list.changeFilterId(currentFilterId, params);
} else if (filterType === PLANNING_VIEW.EVENTS) {
const calendar = urlParams.getString('calendar') ||
lastParams?.calendars?.[0] ||
(lastParams?.noCalendarAssigned ?
EVENTS.FILTER.NO_CALENDAR_ASSIGNED :
EVENTS.FILTER.ALL_CALENDARS
);

const calender = $location.search().calendar ||
const calendar = $location.search().calendar ||
get(lastParams, 'calendars[0]', null) ||
(get(lastParams, 'noCalendarAssigned', false) ?
EVENTS.FILTER.NO_CALENDAR_ASSIGNED :
EVENTS.FILTER.ALL_CALENDARS
{qcode: EVENTS.FILTER.NO_CALENDAR_ASSIGNED} :
{qcode: EVENTS.FILTER.ALL_CALENDARS}
);

promise = planningApi.ui.list.changeCalendarId(
calender,
calendar.qcode,
params
);
} else if (filterType === PLANNING_VIEW.PLANNING) {
Expand Down
93 changes: 44 additions & 49 deletions client/components/Events/ManageEventTemplatesModal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
/* eslint-disable react/no-multi-comp */

import {IFormGroup, IBaseRestApiResponse, IGenericListPageComponent} from 'superdesk-api';
import {superdeskApi} from '../../superdeskApi';

import React from 'react';
import PropTypes from 'prop-types';
import {IFormGroup, IBaseRestApiResponse, IPropsGenericFormItemComponent, IFormField} from 'superdesk-api';
import {superdeskApi} from '../../superdeskApi';
import {Modal} from '../index';
import {planningEventTemplateEvents} from '../../actions/events/notifications';

Expand All @@ -16,67 +14,68 @@ interface IEventTemplate extends IBaseRestApiResponse {
template_name: string;
}

const getItemComponent = (nameField: IFormField) =>
class ItemComponent extends React.PureComponent<IPropsGenericFormItemComponent<any>> {
render(): React.ReactNode {
const {item, page} = this.props;

const {ListItem, ListItemColumn} = superdeskApi.components;
const {getFormFieldPreviewComponent} = superdeskApi.forms;

return (
<ListItem>
<ListItemColumn ellipsisAndGrow noBorder>
{getFormFieldPreviewComponent(item, nameField)}
</ListItemColumn>
<ListItemColumn noBorder>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<button onClick={() => page.startEditing(item._id)}>
<i className="icon-pencil" />
</button>
<button onClick={() => page.deleteItem(item)}>
<i className="icon-trash" />
</button>
</div>
</ListItemColumn>
</ListItem>
);
}
};

export class ManageEventTemplatesModal extends React.PureComponent<IProps> {
static propTypes: any;

render() {
const {handleHide} = this.props;

const {getGenericHttpEntityListPageComponent, ListItemColumn, ListItem} = superdeskApi.components;
const {getFormFieldPreviewComponent, FormFieldType} = superdeskApi.forms;

const {gettext} = superdeskApi.localization;
const {getGenericHttpEntityListPageComponent} = superdeskApi.components;
const {FormFieldType} = superdeskApi.forms;

const nameField = {
const nameField: IFormField = {
label: gettext('Template name'),
type: FormFieldType.textSingleLine,
type: FormFieldType.plainText,
field: 'template_name',
required: true,
};

const formConfig: IFormGroup = {
direction: 'vertical',
type: 'inline',
form: [
nameField,
],
form: [nameField],
};

const EventTemplatesComponent = getGenericHttpEntityListPageComponent<IEventTemplate>(
const EventTemplatesComponent = getGenericHttpEntityListPageComponent<IEventTemplate, unknown>(
'events_template',
formConfig
);

const renderRow = (
key: string,
item: IEventTemplate,
page: IGenericListPageComponent<IEventTemplate>
) => (
<ListItem
key={key}
>
<ListItemColumn ellipsisAndGrow noBorder>
{getFormFieldPreviewComponent(item, nameField)}
</ListItemColumn>
<ListItemColumn noBorder>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<button onClick={() => page.startEditing(item._id)}>
<i className="icon-pencil" />
</button>
<button onClick={() => page.deleteItem(item)}>
<i className="icon-trash" />
</button>
</div>
</ListItemColumn>
</ListItem>
);

return (
<Modal xLarge={true} show={true} onHide={handleHide}>
<Modal.Header>
Expand All @@ -87,8 +86,8 @@ export class ManageEventTemplatesModal extends React.PureComponent<IProps> {
</Modal.Header>
<Modal.Body noPadding={true}>
<EventTemplatesComponent
renderRow={renderRow}
formConfig={formConfig}
ItemComponent={getItemComponent(nameField)}
getFormConfig={() => formConfig}
defaultSortOption={{field: nameField.field, direction: 'ascending'}}
fieldForSearch={nameField}
refreshOnEvents={Object.keys(planningEventTemplateEvents)}
Expand All @@ -104,7 +103,3 @@ export class ManageEventTemplatesModal extends React.PureComponent<IProps> {
);
}
}

ManageEventTemplatesModal.propTypes = {
handleHide: PropTypes.func,
};
1 change: 1 addition & 0 deletions client/components/fields/editor/base/numberSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export class EditorFieldNumberSelect extends React.PureComponent<IProps> {
value={values}
onChange={this.onChangeMultiple}
allowMultiple={true}
zIndex={1051}
/>
);
}
Expand Down
3 changes: 1 addition & 2 deletions client/controllers/AddToPlanningController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {planning} from '../actions';
import {get, isEmpty, isNumber} from 'lodash';
import {registerNotifications, getErrorMessage, isExistingItem} from '../utils';
import {WORKSPACE, MODALS, MAIN} from '../constants';
import {GET_LABEL_MAP, DEFAULT_SCHEMA} from 'superdesk-core/scripts/apps/workspace/content/constants';
import {GET_LABEL_MAP} from 'superdesk-core/scripts/apps/workspace/content/constants';
import {planningApi} from '../superdeskApi';

const DEFAULT_PLANNING_SCHEMA = {
Expand Down Expand Up @@ -207,7 +207,6 @@ export class AddToPlanningController {
}

Object.keys(schema)
.filter((field) => DEFAULT_SCHEMA.hasOwnProperty(field)) // filter out planning only fields
.filter((field) => get(schema[field], 'required') &&
isEmpty(get(newsItem, field)) &&
!isNumber(get(newsItem, field)))
Expand Down
Loading

0 comments on commit 218767b

Please sign in to comment.