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

Add sorting bar to note list #2542

Merged
merged 17 commits into from
Feb 4, 2021
Merged

Conversation

codebykat
Copy link
Member

@codebykat codebykat commented Dec 24, 2020

Fix

Adds a "Sort by" bar to the bottom of the notes list. See p2XJRt-2Ct-p2

Designs are at:
https://app.zeplin.io/project/5d795a3d8ed5261aa146e057/screen/5fd77f1846903987b1b40e75 (light mode)
https://app.zeplin.io/project/5d795a3d8ed5261aa146e057/screen/5fd77f196e43637c2cb2889f (dark mode)

Also shortens the search results bar to 44px to match the height of the sorting bar and the new toolbar-height.

Fixes #1625

Test

  1. Use the toggle to change the sort type and direction of the results.
  2. Also try it with search filtering
  3. Try in different browsers/OSes to make sure the dropdown styling is okay

Screenshots

Screen Shot 2021-02-02 at 11 26 14 AM

Screen Shot 2021-02-02 at 11 26 20 AM

Screen Shot 2021-02-02 at 11 26 34 AM

Screen Shot 2021-02-02 at 11 26 59 AM

Note that in all browsers except Firefox, the dropdown styling is determined by the system theme, so it looks like this if you have a light system theme and the dark Simplenote theme:

Screen Shot 2021-02-02 at 11 26 44 AM

In Firefox, we have to style the dropdown since otherwise it takes the styles from the parent, so I have added dark mode styles for Firefox that will be shown regardless of the system setting (in Simplenote dark theme):

Screen Shot 2021-02-02 at 11 42 03 AM

The weird thing is that setting a background on the select seems to wipe out the padding and rounded edges (only in dark mode), but if we don't set it, we get this:

Screen Shot 2021-02-02 at 12 05 48 PM

Firefox light theme changes the white background to a light gray, which matches default styling:

Screen Shot 2021-02-02 at 11 33 15 AM

Search results bar shortened to match:

Screen Shot 2021-02-02 at 12 02 51 PM

Screen Shot 2021-02-02 at 12 05 11 PM

Release

Added sort order bar to note list

@codebykat codebykat self-assigned this Dec 24, 2020
@codebykat codebykat added this to the 2.5.0 milestone Dec 24, 2020
@codebykat codebykat changed the title [WIP] Add sort order to search results [WIP] Add sort order to note list Jan 7, 2021
@codebykat codebykat changed the title [WIP] Add sort order to note list [WIP] Add sorting bar to note list Jan 7, 2021
@codebykat codebykat changed the title [WIP] Add sorting bar to note list Add sorting bar to note list Jan 7, 2021
@codebykat codebykat marked this pull request as ready for review January 7, 2021 22:19
@codebykat codebykat force-pushed the add/sort-order-in-search-results branch from dee1479 to ea1785a Compare January 7, 2021 22:20
@codebykat

This comment has been minimized.

@codebykat codebykat requested review from a team and SylvesterWilmott January 7, 2021 22:26
@codebykat codebykat modified the milestones: 2.5.0, 2.6.0 Jan 8, 2021
@dmsnell
Copy link
Member

dmsnell commented Jan 8, 2021

Looks fine as it is but I left a few comments that you might consider. Feel free to merge it after responding to or rejecting my suggestions.

@codebykat codebykat modified the milestones: 2.6.0, 2.7.0 Jan 21, 2021
@codebykat
Copy link
Member Author

codebykat commented Jan 28, 2021

Next steps on this:

  1. Change dropdown labels per new designs (p2XJRt-2Ct-p2) 3a9fa0e

all 6 sorting options should be listed within each platforms ‘dropdown’ menu to reduce visual prominence of the bar since it will now be displayed all the time.

Dropdown should be:
Name: A-Z
Name: Z-A
Created: Newest
Created: Oldest
Modified: Newest
Modified: Oldest

  1. Add tracks event cb083c9, 3c28668

sp*_list_sortbar_mode_changed

  1. Address review feedback 8c26946

@codebykat codebykat marked this pull request as draft January 28, 2021 09:55
@codebykat codebykat force-pushed the add/sort-order-in-search-results branch from d1689ed to 0cd62c1 Compare February 2, 2021 05:11
@codebykat codebykat requested a review from a team February 2, 2021 20:12
@codebykat codebykat marked this pull request as ready for review February 2, 2021 20:12
@codebykat
Copy link
Member Author

Refactored with some data attributes, thanks @dmsnell for the suggestion.

Copy link
Contributor

@SylvesterWilmott SylvesterWilmott left a comment

Choose a reason for hiding this comment

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

The design looks good! Thanks @codebykat

if (selectedSortType !== sortType) {
setSortType(selectedSortType as T.SortType);
}
if ((selectedSortReversed === 'false') === sortReversed) {
Copy link
Member

Choose a reason for hiding this comment

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

this is confusing me, specifically because we're comparing against the string value of false

I think we're doing it funny-like because it's a string value and not a real value. in this case parsing it could go a long way for readability. what I expect is to find something like selectedSortReversed !== sortReversed

const selectedSortReversed = selectedOption.dataset.reversed === 'true'; // true if 'true' else false
const selectedSortReversed = JSON.parse(selectedOption.dataset.reversed); // 'true' and 'false' decode properly

if (selectedSortReversed !== sortReversed) {
	
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, I should have refactored that out actually.

toggleSortOrder,
}) => {
const changeSort = (event: React.ChangeEvent<HTMLSelectElement>) => {
const selectedOption = event.currentTarget.selectedOptions[0];
Copy link
Member

Choose a reason for hiding this comment

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

did you find HTMLSelectElement.selectedIndex?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes but is dropdown.options[selectedIndex] better in some way than dropdown.selectedOptions[0]?

Copy link
Member

Choose a reason for hiding this comment

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

only in the sense that it relies on named things vs. the assumption of 0. I know that I wouldn't expect the selected option to always be the first one in the list, or that's how I read this line. I'm guessing this is a list of all possible selections because a drop down can have multiple selected items?

otherwise we're getting the actual option I think, if using seletedIndex

order: 'modificationDate',
reversed: true,
},
];
Copy link
Member

Choose a reason for hiding this comment

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

if we want to simplify the flow of data and types through the select component then we can do another thing and that is directly index into this list. consider if this sortTypes array were outside of the component and in the module scope and we had a function to find the current setting. our HTMLSelectElement could refer to an index into the array as the choice, and although that's less meaningful in itself, it does preserve the types the eliminates the processing and parsing needed to re-connect the data.

type SortOption = {
	label: string,
	order: T.SortOrder,
	isReversed: boolean
}

const sortTypes: SortOption[] = [{
	label: 'Name: A-Z',
  order: 'alphabetical',
  isReversed: false
}, {}];

const onChange = ({currentTarget: {selectedIndex}}) => {
	if (-1 === selectedIndex) {
		return;
	}

	const sort = sortTypes[selectedIndex];
	if (sort.sortOrder !== sortOrder) {
		
	}

	if (sort.isReversed !== sortReversed) {
		
	}
}

const sortTypesIndex = (sortOrder, isReversed) => sortTypes.findIndex(type => type.order === sortOrder && type.isReversed === isReversed);

<select id="sort-selection" value={sortTypesIndex(sortOrder, reversed)} onChange={}>
{sortTypes.map((type, index) => (
	<option key={type.label} value={index}>{type.label}</option>
))}
</select>

Copy link
Member

Choose a reason for hiding this comment

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

it's rare to use an index as the React key but here since the sortTypes array is static the indices will never change and it's safe to use that value

Copy link
Member Author

Choose a reason for hiding this comment

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

That works like a charm! a7d6f62


const mapDispatchToProps: S.MapDispatch<DispatchProps> = {
setSortType,
toggleSortOrder,
Copy link
Member

Choose a reason for hiding this comment

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

calling two separate Redux actions introduces another partial update into our app. that is, if we change both sort properties then we're asking React to update after the first Redux dispatch and then again after the second. that intervening time represents a state that was never requested by the customer.

should we examine the setSortType action and give it the ability to also change the reversing of the search? if we did that, add an optional reversed: boolean property to the action, then we could perform the update in one go and we could eliminate the conditionals at the same time.

Copy link
Member Author

Choose a reason for hiding this comment

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

Very cool! I do end up checking for undefined a bit, not sure if that's the right way to do this. 3e8bac4

@codebykat codebykat requested a review from dmsnell February 3, 2021 23:34
Copy link
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

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

the logic is more readable to me after using the array of sort options vs. the data-passing. good detail work making sure the search index updates ✅

@codebykat codebykat merged commit 1bc0567 into develop Feb 4, 2021
@codebykat codebykat deleted the add/sort-order-in-search-results branch February 4, 2021 22:37
@pachlava
Copy link
Contributor

[testing] fix/feature verified on Dell Latitude 7400 | Win 10 | Simplenote 2.7.0-beta1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Search: Add "sort by" to search results
4 participants