Merge pull request #1683 from symonbaikov/feat/negative-label-filter
Add negative label filtering for cards Two conflicts, both from work that landed while this branch was open. In the endless list query, master had added an ORDER BY so the cursor and the limit agree. The exclusion clause belongs in the WHERE part, so it is placed before it rather than after; the other way round the statement does not parse. The label item had been restructured here for the tri-state filter and had gained a tooltip on master. The restructured version is kept and the tooltip put back on top of it, which also brings back the translation hook this branch had dropped.
This commit is contained in:
@@ -38,8 +38,13 @@ const getByListId = async (listId, { exceptIdOrIds, sort = ['position', 'id'] }
|
||||
return defaultFind(criteria, { sort });
|
||||
};
|
||||
|
||||
const getByEndlessListId = async (listId, { before, search, userIds, labelIds }) => {
|
||||
if (search || userIds || labelIds) {
|
||||
const getByEndlessListId = async (
|
||||
listId,
|
||||
{ before, search, userIds, labelIds, excludedLabelIds },
|
||||
) => {
|
||||
const hasExcludedLabelIds = excludedLabelIds && excludedLabelIds.length > 0;
|
||||
|
||||
if (search || userIds || labelIds || hasExcludedLabelIds) {
|
||||
if (userIds && userIds.length === 0) {
|
||||
return [];
|
||||
}
|
||||
@@ -108,6 +113,20 @@ const getByEndlessListId = async (listId, { before, search, userIds, labelIds })
|
||||
query += ` AND card_label.label_id IN (${inValues.join(', ')})`;
|
||||
}
|
||||
|
||||
if (hasExcludedLabelIds) {
|
||||
const inValues = excludedLabelIds.map((labelId) => {
|
||||
queryValues.push(labelId);
|
||||
return `$${queryValues.length}`;
|
||||
});
|
||||
|
||||
query += ` AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM card_label AS excluded_card_label
|
||||
WHERE excluded_card_label.card_id = card.id
|
||||
AND excluded_card_label.label_id IN (${inValues.join(', ')})
|
||||
)`;
|
||||
}
|
||||
|
||||
// Must match the cursor built from the last returned card, otherwise the
|
||||
// limit cuts an arbitrary slice and pages skip or repeat cards
|
||||
query += ' ORDER BY card.list_changed_at DESC, card.id DESC';
|
||||
|
||||
Reference in New Issue
Block a user