Skip to content

Commit

Permalink
Feat coverage profiles (#2217)
Browse files Browse the repository at this point in the history
* add coverage profiles resource

STT-144

* add profile field to coverage schema

* validation

* WIP - coverage profiles UI

* Handle old profile, coverage profile id

* Fix types

* Fix unit test

* fix failing behave tests

* Small changes

* Rework field validation, remove unused embeddedProfile

* Cleanup

* fix failing tests due to mongo indexes

* fix failing tests due to mongo indexes

* fix client tests

* release 2.9.0rc1

* fix spelling

* use less width for buttons

* add behave to server requirements

* fix e2e client compile

* update e2e client core

---------

Co-authored-by: Petr Jasek <jasekpetr@gmail.com>
Co-authored-by: Tomas Kikutis <t.kikutis@gmail.com>
  • Loading branch information
3 people authored Mar 11, 2025
1 parent 029bf46 commit 653bdbf
Show file tree
Hide file tree
Showing 47 changed files with 915 additions and 415 deletions.
9 changes: 9 additions & 0 deletions client/actions/coverages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {ICoverageContentProfile} from '../interfaces';
import {COVERAGES} from '../constants';

export function updateCoverageProfiles(profiles: Array<ICoverageContentProfile>) {
return {
type: COVERAGES.UPDATE_PROFILES,
payload: profiles,
};
}
61 changes: 37 additions & 24 deletions client/api/contentProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
IPlanningCoverageItem,
IProfileMultilingualDetails,
IProfileSchemaTypeString,
ICoverageContentProfile,
} from '../interfaces';
import {planningApi, superdeskApi} from '../superdeskApi';

Expand All @@ -18,9 +19,10 @@ import {sortProfileGroups} from '../utils/contentProfiles';
import {showModalConnectedToStore} from '../utils/ui';
import {ContentProfileModal} from '../components/ContentProfiles/ContentProfileModal';
import {getUsersDefaultLanguage} from '../utils/users';
import {PLANNING_ITEM_SYSTEM_REQUIRED_FIELDS} from './utils/constants';
import {EVENT_ITEM_SYSTEM_REQUIRED_FIELDS, PLANNING_ITEM_SYSTEM_REQUIRED_FIELDS} from './utils/constants';

const RESOURCE = 'planning_types';
const COVERAGE_PROFILES_RESOURCE = 'coverage_profiles';

function getAll(): Promise<Array<IPlanningContentProfile>> {
return superdeskApi.dataApi.query<IPlanningContentProfile>(
Expand Down Expand Up @@ -139,6 +141,35 @@ function patch(original: IPlanningContentProfile, updates: IPlanningContentProfi
}
}

function patchCoverageProfile(
original: ICoverageContentProfile,
updates: ICoverageContentProfile,
): Promise<ICoverageContentProfile> {
delete updates._created;
delete updates._updated;
delete updates._etag;
delete updates._links;

if (updates._id != null) {
return superdeskApi.dataApi.patch<ICoverageContentProfile>(COVERAGE_PROFILES_RESOURCE, original, updates);
}

return superdeskApi.dataApi.create<ICoverageContentProfile>(COVERAGE_PROFILES_RESOURCE, updates);
}

function getAllCoverageProfiles(): Promise<Array<ICoverageContentProfile>> {
return superdeskApi.dataApi.query<ICoverageContentProfile>(
COVERAGE_PROFILES_RESOURCE,
1,
{field: 'name', direction: 'ascending'},
{},
200
)
.then((response) => {
return response._items;
});
}

function showManagePlanningProfileModal(): Promise<void> {
const {gettext} = superdeskApi.localization;

Expand All @@ -162,25 +193,6 @@ function showManagePlanningProfileModal(): Promise<void> {
'associated_event',
],
},
embeddedProfile: {
label: gettext('Coverage Fields'),
profile: getProfile('coverage'),
systemRequiredFields: [
['g2_content_type'],
['scheduled'],
['add_coverage_to_workflow']
],
disableMinMaxFields: [
'g2_content_type',
'language',
'genre',
'news_coverage_status',
'no_content_linking',
],
disableRequiredFields: [
'no_content_linking',
],
},
}
);
}
Expand All @@ -195,10 +207,7 @@ function showManageEventProfileModal(): Promise<void> {
mainProfile: {
label: gettext('Event Fields'),
profile: getProfile('event'),
systemRequiredFields: [
['dates'],
['slugline', 'name'],
],
systemRequiredFields: EVENT_ITEM_SYSTEM_REQUIRED_FIELDS,
disableMinMaxFields: [
'language',
'location',
Expand Down Expand Up @@ -243,6 +252,10 @@ export const contentProfiles: IPlanningAPI['contentProfiles'] = {
get: getProfile,
getDefaultValues: getDefaultValues,
patch: patch,
coverages: {
patch: patchCoverageProfile,
getAll: getAllCoverageProfiles,
},
showManagePlanningProfileModal: showManagePlanningProfileModal,
showManageEventProfileModal: showManageEventProfileModal,
updateProfilesInStore: updateProfilesInStore,
Expand Down
8 changes: 1 addition & 7 deletions client/api/coverages.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import {PLANNING, WORKFLOW_STATE} from '../constants';
import {ICoverageScheduledUpdate, IPlanningAPI, IPlanningCoverageItem} from '../interfaces';
import {coverageProfile} from '../selectors/forms';
import {planningApi, superdeskApi} from '../superdeskApi';

function getCoverageEditorProfile() {
return coverageProfile(planningApi.redux.store.getState());
}
import {superdeskApi} from '../superdeskApi';

function cancelCoverageOrScheduledUpdate<T extends IPlanningCoverageItem | ICoverageScheduledUpdate>(
item: T,
Expand Down Expand Up @@ -67,7 +62,6 @@ function cancelScheduledUpdate(
}

export const coverages: IPlanningAPI['coverages'] = {
getEditorProfile: getCoverageEditorProfile,
cancelCoverage: cancelCoverage,
cancelScheduledUpdate: cancelScheduledUpdate,
};
23 changes: 16 additions & 7 deletions client/api/editor/item_planning.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {createRef, RefObject} from 'react';
import {cloneDeep} from 'lodash';
import {cloneDeep, omit} from 'lodash';

import {
BOOKMARK_TYPE,
EDITOR_TYPE,
ICoverageContentProfile,
ICoverageType,
IEditorAPI,
IEditorBookmark,
IEditorFormGroup,
Expand All @@ -21,22 +23,29 @@ import {

import {CoveragesBookmark, AddCoverageBookmark} from '../../components/Editor/bookmarks';
import {AssociatedEventItem} from '../../components/fields/editor/AssociatedEventItem';
import {coverageProfiles, oldProfile} from '../../selectors/coverageProfiles';

export function getCoverageFields(): ISearchProfile {
const fields = getGroupFieldsSorted(planningApi.contentProfiles.get('coverage'))
.filter((item) => item.field.enabled);
const profile: ISearchProfile = {};
export function getCoverageFields(
type: ICoverageType,
): {searchProfile: ISearchProfile; profile: ICoverageContentProfile} {
const storeState = planningApi.redux.store.getState();
const allProfiles = coverageProfiles(storeState);
const newProfile = allProfiles.find((x) => x.content_type === type);
const profile = newProfile ? newProfile : omit(oldProfile(storeState), '_id');

const fields = getGroupFieldsSorted(profile).filter((item) => item.field.enabled);
const searchProfile: ISearchProfile = {};

fields.forEach(
(field, index) => {
profile[field.name] = {
searchProfile[field.name] = {
enabled: true,
index: index,
};
},
);

return profile;
return {searchProfile, profile};
}

export function getPlanningInstance(type: EDITOR_TYPE): IEditorAPI['item']['planning'] {
Expand Down
16 changes: 3 additions & 13 deletions client/api/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
import {flatMap} from 'lodash';

export const PLANNING_ITEM_SYSTEM_REQUIRED_FIELDS = [
['planning_date'],
['slugline', 'headline', 'name'],
['coverages'],
];

export const isSystemRequiredField = (() => {
const SYSTEM_REQUIRED_FIELDS_SET = new Set(flatMap(PLANNING_ITEM_SYSTEM_REQUIRED_FIELDS));

return (fieldId: string) => SYSTEM_REQUIRED_FIELDS_SET.has(fieldId);
})();
export const COVERAGE_SYSTEM_REQUIRED_FIELDS = ['g2_content_type', 'scheduled', 'add_coverage_to_workflow'];
export const PLANNING_ITEM_SYSTEM_REQUIRED_FIELDS = ['planning_date', 'coverages'];
export const EVENT_ITEM_SYSTEM_REQUIRED_FIELDS = ['dates'];
Loading

0 comments on commit 653bdbf

Please sign in to comment.