Skip to content

Commit

Permalink
Create a selected and not-selected filter.
Browse files Browse the repository at this point in the history
It's treated like a normal filterMemberships, but unlike all of the other ones (which are derivable entirely from the card itself) this FilterMap is stored in a different part of state.

Part of #688. Part of #174.
  • Loading branch information
jkomoros committed Mar 31, 2024
1 parent 7e5bf41 commit cab5c49
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ const MISSING_CONCEPT_FILTER_NAME = 'missing-concept';
const SAME_TYPE_FILTER_NAME = 'same-type';
const DIFFERENT_TYPE_FILTER_NAME = 'different-type';

export const SELECTED_FILTER_NAME = 'selected';
const NOT_SELECTED_FILTER_NAME = 'not-selected';

/*
* filterEquivalent - the name of the filter that, when applied to the everything
set, will filter down to contain just the items in that set (although
Expand Down Expand Up @@ -1991,6 +1994,7 @@ export const INVERSE_FILTER_NAMES = Object.assign(
{
'unstarred': 'starred',
'unread': 'read',
[NOT_SELECTED_FILTER_NAME]: SELECTED_FILTER_NAME,
[ALL_FILTER_NAME]: NONE_FILTER_NAME,
[TODO_COMBINED_INVERSE_FILTER_NAME]: TODO_COMBINED_FILTER_NAME,
},
Expand Down
17 changes: 14 additions & 3 deletions src/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import {
limitFilter,
excludeFilter,
cardsFilter,
cardTypeFilter
cardTypeFilter,
SELECTED_FILTER_NAME
} from './filters.js';

import {
Expand Down Expand Up @@ -155,7 +156,8 @@ import {
ViewMode,
ReferenceType,
SortExtra,
CardDiff
CardDiff,
Filters
} from './types.js';

import {
Expand Down Expand Up @@ -231,7 +233,7 @@ export const selectEditorMinimized = (state : State) => state.editor ? state.edi
export const selectEditingUpdatedFromContentEditable = (state : State) => state.editor ? state.editor.updatedFromContentEditable : {};
export const selectEditingPendingReferenceType = (state : State) : ReferenceType => state.editor ? state.editor.pendingReferenceType : 'ack';
export const selectPendingSlug = (state : State) => state.editor ? state.editor.pendingSlug : '';
export const selectFilters = (state : State) => state.collection ? state.collection.filters : {};
const selectBaseFilters = (state : State) => state.collection ? state.collection.filters : {};
const selectFiltersSnapshot = (state : State) => state.collection ? state.collection.filtersSnapshot : {};
export const selectSections = (state : State) => state.data ? state.data.sections : {};
export const selectTags = (state : State) => state.data ? state.data.tags : {};
Expand Down Expand Up @@ -431,6 +433,15 @@ export const selectKeyboardNavigates = createSelector(
(editing, find, compose) => !editing && !find && !compose
);

export const selectFilters = createSelector(
selectBaseFilters,
selectExplicitlySelectedCardIDs,
(baseFilters, selectedCards) : Filters => ({
...baseFilters,
[SELECTED_FILTER_NAME]: selectedCards
})
);

//This is just the userPermissions fetched; for the actual permissions object in
//use, see selectCOmposedPermissions.
const selectUserPermissions = (state : State) => state.user ? state.user.userPermissions : {};
Expand Down

0 comments on commit cab5c49

Please sign in to comment.