Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 17 additions & 2 deletions public/src/client/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ define('forum/search', [
let selectedTags = [];
let selectedCids = [];
let searchFilters = {};
let lastAutoQueryUrl = null;

Search.init = function () {
const searchIn = $('#search-in');
searchIn.on('change', function () {
Expand Down Expand Up @@ -65,6 +67,16 @@ define('forum/search', [
updateSortFilter();

searchFilters = getSearchDataFromDOM();
const currentUrl = window.location.pathname + window.location.search;

// Only auto-query when arriving with a term AND the page doesn't already have results rendered
const hasRenderedResults = !!$('#results .search-results').length;
const term = (searchFilters.term || '').trim();

if (term && !hasRenderedResults && lastAutoQueryUrl !== currentUrl) {
lastAutoQueryUrl = currentUrl;
searchModule.query(searchFilters);
}
};

function updateTagFilter() {
Expand Down Expand Up @@ -122,7 +134,8 @@ define('forum/search', [
if (['posts', 'titlesposts', 'titles', 'bookmarks'].includes(searchData.in)) {
searchData.matchWords = form.find('#match-words-filter').val();
searchData.by = selectedUsers.length ? selectedUsers.map(u => u.username) : undefined;
searchData.categories = selectedCids.length ? selectedCids : undefined;
const cids = Array.isArray(selectedCids) ? selectedCids : [];
searchData.categories = cids.length ? cids : ['all'];
searchData.searchChildren = form.find('#search-children').is(':checked');
searchData.hasTags = selectedTags.length ? selectedTags.map(t => t.value) : undefined;
searchData.replies = form.find('#reply-count').val();
Expand Down Expand Up @@ -290,6 +303,8 @@ define('forum/search', [
});
}



function userFilterDropdown(el, _selectedUsers) {
selectedUsers = _selectedUsers || [];
userFilter.init(el, {
Expand Down Expand Up @@ -395,4 +410,4 @@ define('forum/search', [
}

return Search;
});
});
12 changes: 10 additions & 2 deletions public/src/modules/categoryFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ define('categoryFilter', ['categorySearch', 'api', 'hooks'], function (categoryS
const icon = categoryEl.find('[component="category/select/icon"]');

if (cid !== 'all') {
if (selectedCids.length === 1 && selectedCids[0] === 'all') {
selectedCids = [];
}

if (selectedCids.includes(cid)) {
selectedCids.splice(selectedCids.indexOf(cid), 1);
} else {
Expand All @@ -86,7 +90,7 @@ define('categoryFilter', ['categorySearch', 'api', 'hooks'], function (categoryS
} else {
el.find('[component="category/select/icon"]').addClass('invisible');
listEl.find('[data-cid="all"] i').removeClass('invisible');
selectedCids = [];
selectedCids = ['all']; // IMPORTANT: backend expects this
}

options.selectedCids = selectedCids;
Expand All @@ -106,7 +110,11 @@ define('categoryFilter', ['categorySearch', 'api', 'hooks'], function (categoryS
bgColor: '#ddd',
});
} else if (selectedCids.length === 1) {
api.get(`/categories/${selectedCids[0]}`, {}).then(renderButton);
if (selectedCids[0] === 'all') {
renderButton(); // default button
} else {
api.get(`/categories/${selectedCids[0]}`, {}).then(renderButton);
}
} else {
renderButton();
}
Expand Down
6 changes: 4 additions & 2 deletions test/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ describe('API', async () => {

// Recursively iterate through schema properties, comparing type
it('response body should match schema definition', () => {
if (path === '/api/admin/extend/plugins') {
return;
}

const http302 = context[method].responses['302'];
if (http302 && result.response.statusCode === 302) {
// Compare headers instead
Expand Down Expand Up @@ -574,8 +578,6 @@ describe('API', async () => {
schema = context[method].responses['200'].content['application/json'].schema;
compare(schema, result.body, method.toUpperCase(), path, 'root');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we're allowed to remove everything here lmao. This removes like all api endpoint schema checks I'm pretty sure

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty much the discussion on slack tech-support currently. Not a clue how to remove the flaky test without this though. The other suggestion on slack was to remove 2 lines of the plugins.yaml file, but it didn't work for me.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the discussion only said to add the if statement, not delete everything else?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually if you merge in main now, we can probably revert this change as well (I fixed the tests another way)

// TODO someday: text/csv, binary file type checking?
});

it('should successfully re-login if needed', async () => {
Expand Down