Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDESK-6199] Ability to search all wire versions #8

Merged
merged 21 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
283656b
[server]: add `original_id` field
MarkLark86 Oct 12, 2021
5ce2dbd
[server]: set `original_id` on push
MarkLark86 Oct 12, 2021
85d7d26
[server]: allow searching all versions
MarkLark86 Oct 12, 2021
a5e4798
[client]: add ability to search all versions
MarkLark86 Oct 12, 2021
ceba37a
[server]: migration script to add `original_id` elastic mapping
MarkLark86 Oct 12, 2021
3c8e003
[client]: Fix lint
MarkLark86 Oct 12, 2021
77329bb
On push endpoint set `original_id` before checking parent
MarkLark86 Oct 13, 2021
c6ad4fe
fix(install): Use pip v21.2
MarkLark86 Oct 13, 2021
14fd2bf
Simplify bool query
MarkLark86 Oct 13, 2021
60889f5
Merge branch 'develop' into SDESK-6199
MarkLark86 Oct 13, 2021
f2fcf92
Remove data_update script for `original_id`
MarkLark86 Oct 13, 2021
7afbbb8
fix(server-unit): After changes to search endpoint
MarkLark86 Oct 13, 2021
a61c6f0
[server]: Add list of IDs matched into the search response HATEOAS
MarkLark86 Oct 15, 2021
8fb4a59
[client]: Add css label modifiers for theme colours
MarkLark86 Oct 15, 2021
b636f4e
[client]: Show `MATCH` label on each version matched
MarkLark86 Oct 15, 2021
d342406
fix(server-lint)
MarkLark86 Oct 15, 2021
52fce3a
[client]: Dont show all versions toggle in Monitoring
MarkLark86 Oct 15, 2021
7afe320
[client]: Use dropdown on mobile for search settings
MarkLark86 Oct 15, 2021
978ecac
[client]: Reload list when toggling all versions
MarkLark86 Oct 15, 2021
827e92c
[client]: Default matchedIds to empty array
MarkLark86 Oct 15, 2021
3bb968d
Remove `constant_score` filter
MarkLark86 Oct 21, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

- name: pip install
run: |
python -m pip install --upgrade pip wheel setuptools
python -m pip install --upgrade 'pip<21.3' wheel setuptools
pip install -r dev-requirements.txt

- name: pytest
Expand Down
18 changes: 18 additions & 0 deletions assets/local-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {get} from 'lodash';

const READ_ITEMS_STORE = 'read_items';
const NEWS_ONLY_STORE = 'news_only';
const SEARCH_ALL_VERSIONS_STORE = 'search_all_versions';
const FEATURED_ONLY_STORE = 'featured-only';
const FILTER_TAB = 'filter_tab';
const ACTIVE_DATE = 'active_date';
Expand Down Expand Up @@ -56,6 +57,23 @@ export function toggleNewsOnlyParam() {
store.assign(NEWS_ONLY_STORE, {value: !getNewsOnlyParam()});
}

/**
* Get search all versions value
*
* @returns {boolean}
*/
export function getSearchAllVersionsParam() {
return !!((store.get(SEARCH_ALL_VERSIONS_STORE) || {}).value);
}

/**
* Toggles search all versions value
*
*/
export function toggleSearchAllVersionsParam() {
store.assign(SEARCH_ALL_VERSIONS_STORE, {value: !getSearchAllVersionsParam()});
}

/**
* Get featured stories only value
*
Expand Down
14 changes: 11 additions & 3 deletions assets/wire/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {getNavigationUrlParam} from 'search/utils';
import {searchParamsSelector} from 'search/selectors';
import {context} from 'selectors';

import {markItemAsRead, toggleNewsOnlyParam} from 'local-store';
import {markItemAsRead, toggleNewsOnlyParam, toggleSearchAllVersionsParam} from 'local-store';
import {renderModal, closeModal, setSavedItemsCount} from 'actions';

import {
Expand Down Expand Up @@ -108,8 +108,8 @@ export function recieveItem(data) {
}

export const INIT_DATA = 'INIT_DATA';
export function initData(wireData, readData, newsOnly) {
return {type: INIT_DATA, wireData, readData, newsOnly};
export function initData(wireData, readData, newsOnly, searchAllVersions) {
return {type: INIT_DATA, wireData, readData, newsOnly, searchAllVersions};
}

export const TOGGLE_NEWS = 'TOGGLE_NEWS';
Expand All @@ -118,6 +118,12 @@ export function toggleNews() {
return {type: TOGGLE_NEWS};
}

export const TOGGLE_SEARCH_ALL_VERSIONS = 'TOGGLE_SEARCH_ALL_VERSIONS';
export function toggleSearchAllVersions() {
toggleSearchAllVersionsParam();
return {type: TOGGLE_SEARCH_ALL_VERSIONS};
}

export function removeItems(items) {
if (confirm(gettext('Are you sure you want to permanently remove these item(s)?'))) {
return server.del('/wire', {items})
Expand Down Expand Up @@ -227,6 +233,7 @@ export function search(state, next) {
}

const newsOnly = !!get(state, 'wire.newsOnly');
const searchAllVersions = !!get(state, 'wire.searchAllVersions');
const context = get(state, 'context', 'wire');

const params = {
Expand All @@ -241,6 +248,7 @@ export function search(state, next) {
newsOnly,
product: searchParams.product,
es_highlight: !searchParams.query ? null : 1,
all_versions: !searchAllVersions ? null : 1,
};

const queryString = Object.keys(params)
Expand Down
23 changes: 22 additions & 1 deletion assets/wire/components/ListViewControls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,29 @@ import React from 'react';
import PropTypes from 'prop-types';

import NewsOnlyControl from './NewsOnlyControl';
import SearchAllVersionsControl from './SearchAllVersionsControl';
import ListViewOptions from '../../components/ListViewOptions';

function ListViewControls({activeView, setView, newsOnly, toggleNews, activeNavigation, hideNewsOnly}) {
function ListViewControls({
activeView,
setView,
newsOnly,
toggleNews,
activeNavigation,
hideNewsOnly,
hideSearchAllVersions,
searchAllVersions,
toggleSearchAllVersions,
}) {
return(
<div className='content-bar__right'>
{hideSearchAllVersions ? null : (
<SearchAllVersionsControl
activeNavigation={activeNavigation}
searchAllVersions={searchAllVersions}
toggleSearchAllVersions={toggleSearchAllVersions}
/>
)}
{!hideNewsOnly && <NewsOnlyControl
activeNavigation={activeNavigation}
newsOnly={newsOnly}
Expand All @@ -25,6 +43,9 @@ ListViewControls.propTypes = {
toggleNews: PropTypes.func,
activeNavigation: PropTypes.arrayOf(PropTypes.string),
hideNewsOnly: PropTypes.bool,
hideSearchAllVersions: PropTypes.bool,
searchAllVersions: PropTypes.bool,
toggleSearchAllVersions: PropTypes.func,
};

export default ListViewControls;
2 changes: 1 addition & 1 deletion assets/wire/components/NewsOnlyControl.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {noNavigationSelected} from 'search/utils';
function NewsOnlyControl ({newsOnly, toggleNews, activeNavigation}) {
return !noNavigationSelected(activeNavigation) ? null : (
<div className="d-flex align-items-center px-2 px-sm-3">
<div className={'d-flex align-items-center'}>
<div className="d-flex align-items-center flex-column-reverse flex-md-row">
<label htmlFor='news-only' className="mr-2">{gettext('News only')}</label>
<Toggle
id="news-only"
Expand Down
29 changes: 29 additions & 0 deletions assets/wire/components/SearchAllVersionsControl.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import * as React from 'react';
import PropTypes from 'prop-types';
import Toggle from 'react-toggle';
import {gettext} from 'utils';
import {noNavigationSelected} from 'search/utils';

function SearchAllVersionsControl({searchAllVersions, toggleSearchAllVersions, activeNavigation}) {
return !noNavigationSelected(activeNavigation) ? null : (
<div className="d-flex align-items-center px-2 px-sm-3">
<div className="d-flex align-items-center flex-column-reverse flex-md-row">
<label htmlFor='all-versions' className="mr-2">{gettext('All Versions')}</label>
<Toggle
id="all-versions"
defaultChecked={searchAllVersions}
className='toggle-background'
icons={false}
onChange={toggleSearchAllVersions}/>
</div>
</div>
);
}

SearchAllVersionsControl.propTypes = {
searchAllVersions: PropTypes.bool,
toggleSearchAllVersions: PropTypes.func,
activeNavigation: PropTypes.arrayOf(PropTypes.string),
};

export default SearchAllVersionsControl;
8 changes: 8 additions & 0 deletions assets/wire/components/WireApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
fetchMoreItems,
previewItem,
toggleNews,
toggleSearchAllVersions,
downloadVideo,
} from 'wire/actions';

Expand Down Expand Up @@ -179,6 +180,9 @@ class WireApp extends BaseApp {
newsOnly={this.props.newsOnly}
toggleNews={this.props.toggleNews}
hideNewsOnly={!(this.props.context === 'wire' && DISPLAY_NEWS_ONLY)}
hideSearchAllVersions={false}
searchAllVersions={this.props.searchAllVersions}
toggleSearchAllVersions={this.props.toggleSearchAllVersions}
/>
</nav>
</section>,
Expand Down Expand Up @@ -279,6 +283,8 @@ WireApp.propTypes = {
activeNavigation: PropTypes.arrayOf(PropTypes.string),
toggleNews: PropTypes.func,
newsOnly: PropTypes.bool,
toggleSearchAllVersions: PropTypes.func,
searchAllVersions: PropTypes.bool,
activeTopic: PropTypes.object,
activeProduct: PropTypes.object,
activeFilter: PropTypes.object,
Expand Down Expand Up @@ -312,6 +318,7 @@ const mapStateToProps = (state) => ({
navigations: navigationsSelector(state),
activeNavigation: searchNavigationSelector(state),
newsOnly: !!get(state, 'wire.newsOnly'),
searchAllVersions: !!get(state, 'wire.searchAllVersions'),
bookmarks: state.bookmarks,
savedItemsCount: state.savedItemsCount,
userSections: state.userSections,
Expand All @@ -335,6 +342,7 @@ const mapDispatchToProps = (dispatch) => ({
dispatch(toggleNews());
dispatch(fetchItems());
},
toggleSearchAllVersions: () => dispatch(toggleSearchAllVersions()),
setQuery: (query) => dispatch(setQuery(query)),
actions: getItemActions(dispatch),
fetchMoreItems: () => dispatch(fetchMoreItems()),
Expand Down
4 changes: 2 additions & 2 deletions assets/wire/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {createStore, render, initWebSocket, getInitData, closeItemOnMobile, isMobilePhone} from 'utils';

import wireReducer from './reducers';
import {getNewsOnlyParam, getReadItems} from 'local-store';
import {getNewsOnlyParam, getSearchAllVersionsParam, getReadItems} from 'local-store';
import WireApp from './components/WireApp';
import {
fetchItems,
Expand All @@ -17,7 +17,7 @@ import {setView} from 'search/actions';
const store = createStore(wireReducer, 'Wire');

// init data
store.dispatch(initData(getInitData(window.wireData), getReadItems(), getNewsOnlyParam()));
store.dispatch(initData(getInitData(window.wireData), getReadItems(), getNewsOnlyParam(), getSearchAllVersionsParam()));

// init view
if (localStorage.getItem('view')) {
Expand Down
14 changes: 13 additions & 1 deletion assets/wire/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
RECIEVE_ITEMS,
INIT_DATA,
TOGGLE_NEWS,
TOGGLE_SEARCH_ALL_VERSIONS,
WIRE_ITEM_REMOVED,
} from './actions';

Expand Down Expand Up @@ -100,6 +101,13 @@ function _wireReducer(state, action) {
};
}

case TOGGLE_SEARCH_ALL_VERSIONS: {
return {
...state,
searchAllVersions: !state.searchAllVersions,
};
}

default:
return state;
}
Expand All @@ -125,7 +133,10 @@ export default function wireReducer(state = initialState, action) {
bookmarks: action.wireData.bookmarks || false,
formats: action.wireData.formats || [],
secondaryFormats: get(action, 'wireData.secondary_formats') || [],
wire: Object.assign({}, state.wire, {newsOnly: action.newsOnly}),
wire: Object.assign({}, state.wire, {
newsOnly: action.newsOnly,
searchAllVersions: action.searchAllVersions,
}),
search: Object.assign({}, state.search, {
navigations,
products,
Expand All @@ -139,6 +150,7 @@ export default function wireReducer(state = initialState, action) {
}

case TOGGLE_NEWS:
case TOGGLE_SEARCH_ALL_VERSIONS:
return {...state, wire: _wireReducer(state.wire, action)};

case WIRE_ITEM_REMOVED:
Expand Down
2 changes: 1 addition & 1 deletion newsroom/news_api/news/search_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class NewsAPINewsService(BaseSearchService):

default_fields = {
'_id', 'uri', 'embargoed', 'pubstatus', 'ednote', 'signal', 'copyrightnotice', 'copyrightholder',
'versioncreated', 'evolvedfrom'
'versioncreated', 'evolvedfrom', 'original_id'
}

# set of fields that will be removed from all responses, we are not currently supporting associations and
Expand Down
7 changes: 6 additions & 1 deletion newsroom/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,24 @@ def publish_item(doc, original):
doc['publish_schedule'] = parse_date_str(doc.get('publish_schedule'))
doc.setdefault('wordcount', get_word_count(doc.get('body_html', '')))
doc.setdefault('charcount', get_char_count(doc.get('body_html', '')))
doc['original_id'] = doc['guid']

service = superdesk.get_resource_service('content_api')
service.datasource = 'items'

if 'evolvedfrom' in doc:
if doc.get('evolvedfrom'):
parent_item = service.find_one(req=None, _id=doc['evolvedfrom'])
if parent_item:
if parent_item.get("original_id"):
doc["original_id"] = parent_item["original_id"]
doc['ancestors'] = copy(parent_item.get('ancestors', []))
doc['ancestors'].append(doc['evolvedfrom'])
doc['bookmarks'] = parent_item.get('bookmarks', [])
doc['planning_id'] = parent_item.get('planning_id')
doc['coverage_id'] = parent_item.get('coverage_id')
else:
logger.warning("Failed to find evolvedfrom item %s for %s", doc['evolvedfrom'], doc['guid'])

fix_hrefs(doc)
logger.debug('publishing %s', doc['guid'])
for assoc in doc.get('associations', {}).values():
Expand Down
Loading