From d2c61b67ac58fff143787320491929a24fa6592d Mon Sep 17 00:00:00 2001 From: stevekaplan123 Date: Tue, 16 Jul 2024 10:43:36 -0400 Subject: [PATCH 1/3] chore: started search filtering bug --- static/js/ElasticSearchQuerier.jsx | 5 ++++- static/js/ReaderApp.jsx | 19 ++++++++++++++++++- static/js/ReaderPanel.jsx | 2 ++ static/js/SearchPage.jsx | 3 ++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/static/js/ElasticSearchQuerier.jsx b/static/js/ElasticSearchQuerier.jsx index 485bd5dc66..fd86ffc698 100644 --- a/static/js/ElasticSearchQuerier.jsx +++ b/static/js/ElasticSearchQuerier.jsx @@ -62,6 +62,8 @@ class ElasticSearchQuerier extends Component { moreToLoad: true, }); this._executeAllQueries(newProps); + // this.props.resetSearchFilters('sheet'); + // this.props.resetSearchFilters('text'); } else if (this._shouldUpdateQuery(this.props, newProps, this.props.type)) { let state = { hits: [], @@ -375,7 +377,8 @@ ElasticSearchQuerier.propTypes = { onQueryChange: PropTypes.func, updateAppliedFilter: PropTypes.func, updateAppliedOptionSort: PropTypes.func, - updateAppliedOptionField: PropTypes.func + updateAppliedOptionField: PropTypes.func, + resetSearchFilters: PropTypes.func }; export { ElasticSearchQuerier }; \ No newline at end of file diff --git a/static/js/ReaderApp.jsx b/static/js/ReaderApp.jsx index 6125fa317a..2bd6e90b33 100644 --- a/static/js/ReaderApp.jsx +++ b/static/js/ReaderApp.jsx @@ -1218,6 +1218,21 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) { }) }); } + resetSearchFilters(n, type) { + // reset both availableFilters and appliedFilters + const state = this.state.panels[n]; + const searchState = this._getSearchState(state, type); + const searchStateName = this._getSearchStateName(type); + searchState.availableFilters.forEach(filterNode => { + if (!filterNode.isUnselected()) { + filterNode.setUnselected(true); + } + }) + this.setPanelState(n, { + [searchStateName]: searchState.update({appliedFilters: [], appliedFilterAggTypes: [], filterRegistry: {}, + filtersValid: false}), + }); + } updateSearchFilter(n, type, searchState, filterNode) { const searchStateName = this._getSearchStateName(type); if (filterNode.isUnselected()) { @@ -2139,8 +2154,9 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) { var unsetTextHighlight = this.unsetTextHighlight.bind(null, i); var updateQuery = this.updateQuery.bind(null, i); var updateAvailableFilters = this.updateAvailableFilters.bind(null, i); - let updateSearchState = this.updateSearchState.bind(null, i); + const updateSearchState = this.updateSearchState.bind(null, i); var updateSearchFilter = this.updateSearchFilter.bind(null, i); + const resetSearchFilters = this.resetSearchFilters.bind(null, i); var updateSearchOptionField = this.updateSearchOptionField.bind(null, i); var updateSearchOptionSort = this.updateSearchOptionSort.bind(null, i); var openConnectionsPanel = this.openTextListAt.bind(null, i+1); @@ -2171,6 +2187,7 @@ toggleSignUpModal(modalContentKind = SignUpModalKind.Default) { Date: Tue, 23 Jul 2024 14:53:28 -0400 Subject: [PATCH 2/3] chore: URL params exist for sheetsWithRef but dont properly set searchState --- sourcesheets/views.py | 31 +++++++++++++------------- static/js/ReaderApp.jsx | 7 +++--- static/js/Sheets/SheetsWithRefPage.jsx | 19 ++++++++-------- static/js/sefaria/sefaria.js | 1 + 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/sourcesheets/views.py b/sourcesheets/views.py index d6373ede3f..dbee46e6c5 100644 --- a/sourcesheets/views.py +++ b/sourcesheets/views.py @@ -36,7 +36,7 @@ from sefaria.system.decorators import catch_error_as_json from sefaria.utils.util import strip_tags -from reader.views import render_template, catchall +from reader.views import render_template, catchall, get_search_params from sefaria.sheets import clean_source, bleach_text from bs4 import BeautifulSoup @@ -1026,24 +1026,22 @@ def sheets_by_ref_api(request, ref): include_first_comment = bool(int(request.GET.get("include_first_comment", 0))) return jsonResponse(get_sheets_for_ref(ref, include_collections=include_collections, include_first_comment=include_first_comment)) - -def sheets_with_ref(request, tref): - """ - Accepts tref as a string which is expected to be in the format of a ref or refs separated by commas, indicating a range. - """ - is_range = bool(int(request.GET.get('range', 0))) - if is_range: - refs = [Ref(r) for r in tref.split(",")] - tref = refs[0].to(refs[-1]).normal() - he_tref = Ref(tref).he_normal() - normal_ref = tref if request.interfaceLang == "english" else he_tref - title = _(f"Sheets with ")+normal_ref+_(" on Sefaria") - return menu_page(request, page="sheetsWithRef", title=title, props={"sheetsWithRef": {"en": tref, "he": he_tref}}) - def sheets_with_ref(request, tref): """ Accepts tref as a string which is expected to be in the format of a ref or refs separated by commas, indicating a range. """ + search_params = get_search_params(request.GET) + + props={ + "initialSearchType": "sheet", + "initialTextSearchFilters": search_params["textFilters"], + "initialTextSearchFilterAggTypes": search_params["textFilterAggTypes"], + "initialTextSearchField": search_params["textField"], + "initialTextSearchSortType": search_params["textSort"], + "initialSheetSearchFilters": search_params["sheetFilters"], + "initialSheetSearchFilterAggTypes": search_params["sheetFilterAggTypes"], + "initialSheetSearchSortType": search_params["sheetSort"] + } is_range = bool(int(request.GET.get('range', 0))) if is_range: refs = [Ref(r) for r in tref.split(",")] @@ -1051,7 +1049,8 @@ def sheets_with_ref(request, tref): he_tref = Ref(tref).he_normal() normal_ref = tref if request.interfaceLang == "english" else he_tref title = _(f"Sheets with ")+normal_ref+_(" on Sefaria") - return menu_page(request, page="sheetsWithRef", title=title, props={"sheetsWithRef": {"en": tref, "he": he_tref}}) + props["sheetsWithRef"] = {"en": tref, "he": he_tref} + return menu_page(request, page="sheetsWithRef", title=title, props=props) def get_aliyot_by_parasha_api(request, parasha): response = {"ref":[]}; diff --git a/static/js/ReaderApp.jsx b/static/js/ReaderApp.jsx index 2bd6e90b33..967ac2bac7 100644 --- a/static/js/ReaderApp.jsx +++ b/static/js/ReaderApp.jsx @@ -455,10 +455,11 @@ class ReaderApp extends Component { hist.mode = "navigation"; break; case "sheetsWithRef": - const lang = Sefaria.interfaceLang === "hebrew" ? "he" : "en"; - hist.title = Sefaria._("Sheets with ") + Sefaria.sheetsWithRef[lang] + Sefaria._(" on Sefaria"); + const encodedSheetsWithRef = Sefaria.sheetsWithRef[shortLang] ? encodeURIComponent(Sefaria.sheetsWithRef[shortLang]) : ""; + hist.title = Sefaria._("Sheets with ") + Sefaria.sheetsWithRef[shortLang] + Sefaria._(" on Sefaria"); + hist.url = "sheetsWithRef" + (Sefaria.sheetsWithRef[shortLang] ? (`/${encodedSheetsWithRef}` + + state.sheetSearchState.makeURL({ prefix: 's', isStart: false })) : ""); hist.mode = "sheetsWithRef"; - hist.url = `sheetsWithRef/${Sefaria.sheetsWithRef['en']}`; break; case "text toc": var ref = state.refs.slice(-1)[0]; diff --git a/static/js/Sheets/SheetsWithRefPage.jsx b/static/js/Sheets/SheetsWithRefPage.jsx index fcac50d457..456d866d0c 100644 --- a/static/js/Sheets/SheetsWithRefPage.jsx +++ b/static/js/Sheets/SheetsWithRefPage.jsx @@ -10,6 +10,7 @@ const SheetsWithRefPage = ({srefs, searchState, updateSearchState, updateApplied const [loading, setLoading] = useState(true); const [totalResults, setTotalResults] = useState(new SearchTotal()); const [origAvailableFilters, setOrigAvailableFilters] = useState([]); + const [refs, setRefs] = useState(srefs); const cloneFilters = (availableFilters, resetDocCounts = true) => { return availableFilters.map(availableFilter => { let newAvailableFilter = availableFilter.clone(); @@ -25,7 +26,7 @@ const SheetsWithRefPage = ({srefs, searchState, updateSearchState, updateApplied const currDocCounts = getDocCounts(searchState.availableFilters); if (!newDocCounts.compare(currDocCounts)) { availableFilters = availableFilters.sort((a, b) => b.docCount - a.docCount || a.title.localeCompare(b.title)); - registerAvailableFilters('sheet', availableFilters, {}, [], ['collections', 'topics']); + registerAvailableFilters('sheet', availableFilters, {}, [], ['collections', 'topics_en']); } } const updateDocCounts = (newAvailableFilters, slugs) => { @@ -36,7 +37,7 @@ const SheetsWithRefPage = ({srefs, searchState, updateSearchState, updateApplied }) } const getSheetSlugs = (type, sheet) => { - const items = sheet[[type]]; + const items = type === 'topics_en' ? sheet.topics : sheet.collections; return items.map(x => x.slug); } const applyFiltersToSheets = (sheets) => { @@ -63,7 +64,7 @@ const SheetsWithRefPage = ({srefs, searchState, updateSearchState, updateApplied return sheets; } const updateNewAvailableFilters = (newAvailableFilters, sheets) => { - ['collections', 'topics'].forEach(type => { + ['collections', 'topics_en'].forEach(type => { let allSlugs = {}; sheets.forEach(sheet => { let slugs = getSheetSlugs(type, sheet); @@ -178,18 +179,18 @@ const SheetsWithRefPage = ({srefs, searchState, updateSearchState, updateApplied // 'collections' won't be present if the related API set _sheetsByRef, // but 'collections' will be present if the sheets_by_ref_api has run // if the field is not present, we need to call the sheets_by_ref_api - const currentSheetsByRef = Sefaria.sheets._sheetsByRef[srefs]; + const currentSheetsByRef = Sefaria.sheets._sheetsByRef[refs]; const collectionsInCache = !!currentSheetsByRef && currentSheetsByRef.every(sheet => 'collections' in sheet); if (!collectionsInCache) { - delete Sefaria.sheets._sheetsByRef[srefs]; - Sefaria.sheets.getSheetsByRef(srefs, getSheetsByRefCallback).then(sheets => { + delete Sefaria.sheets._sheetsByRef[refs]; + Sefaria.sheets.getSheetsByRef(refs, getSheetsByRefCallback).then(sheets => { handleSheetsLoad(sheets); }) } else { - handleSheetsLoad(Sefaria.sheets._sheetsByRef[srefs]); + handleSheetsLoad(Sefaria.sheets._sheetsByRef[refs]); } - }, []); + }, [refs]); updateOrigAvailableFilters(); let sortedSheets = [...sheets]; @@ -201,7 +202,7 @@ const SheetsWithRefPage = ({srefs, searchState, updateSearchState, updateApplied isQueryRunning={loading} searchTopMsg="Sheets With" hits={sortedSheets} - query={srefs} + query={refs} type={'sheet'} totalResults={totalResults} compare={false} diff --git a/static/js/sefaria/sefaria.js b/static/js/sefaria/sefaria.js index e8eba67334..b84b1fcbee 100644 --- a/static/js/sefaria/sefaria.js +++ b/static/js/sefaria/sefaria.js @@ -2797,6 +2797,7 @@ _media: {}, let title, heTitle; if (type === 'topics') { [title, heTitle] = [item.en, item.he]; + type = 'topics_en'; } else if (type === 'collections') { [title, heTitle] = [item.name, item.name]; From e3c62db0f7565e2f73240260def822e4138aa713 Mon Sep 17 00:00:00 2001 From: stevekaplan123 Date: Wed, 21 Aug 2024 09:07:10 +0300 Subject: [PATCH 3/3] chore: undo unnecessary merge additions --- sourcesheets/views.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/sourcesheets/views.py b/sourcesheets/views.py index fbe2ab5fb6..371fa5a7a9 100644 --- a/sourcesheets/views.py +++ b/sourcesheets/views.py @@ -1043,10 +1043,7 @@ def sheets_with_ref(request, tref): props={ "initialSearchType": "sheet", - "initialTextSearchFilters": search_params["textFilters"], - "initialTextSearchFilterAggTypes": search_params["textFilterAggTypes"], "initialTextSearchField": search_params["textField"], - "initialTextSearchSortType": search_params["textSort"], "initialSheetSearchFilters": search_params["sheetFilters"], "initialSheetSearchFilterAggTypes": search_params["sheetFilterAggTypes"], "initialSheetSearchSortType": search_params["sheetSort"]