-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from Solovev-A/improvement-method-groups-order
Add method groups sorting
- Loading branch information
Showing
20 changed files
with
133 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import cookies from 'app/common/utils/helpers/cookies'; | ||
|
||
import { SORT_METHOD_GROUPS_COOKIE_NAME } from 'app/constants/sort'; | ||
|
||
class SortService { | ||
constructor() { | ||
this.isGroupsSortingEnabled = !!cookies.get({ | ||
name: SORT_METHOD_GROUPS_COOKIE_NAME, | ||
}); | ||
|
||
this.toggleGroupsSorting = this.toggleGroupsSorting.bind(this); | ||
} | ||
|
||
sortGroups(groups) { | ||
return [...groups].sort((a, b) => a.title.localeCompare(b.title)); | ||
} | ||
|
||
toggleGroupsSorting() { | ||
if (this.isGroupsSortingEnabled) { | ||
cookies.remove({ name: SORT_METHOD_GROUPS_COOKIE_NAME }); | ||
} else { | ||
cookies.set({ name: SORT_METHOD_GROUPS_COOKIE_NAME, value: true }); | ||
} | ||
|
||
window.location.reload(); | ||
} | ||
} | ||
|
||
export const sortService = new SortService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,52 @@ | ||
const DEFAULT_OPTIONS = { | ||
domain: window.location.hostname.split('.').slice(-2).join('.'), | ||
}; | ||
|
||
const getCookie = ({ name }) => { | ||
const regex = `(?:^|; )${name.replace(/([.$?*|{}()[\]\\/+^])/g, '\\$1')}=([^;]*)`; | ||
const matches = document.cookie.match(new RegExp(regex)); | ||
return matches ? decodeURIComponent(matches[1]) : undefined; | ||
}; | ||
|
||
const setCookie = ({ name, value, options = { path: '/' } }) => { | ||
const setCookie = ({ | ||
name, | ||
value, | ||
options = {}, | ||
}) => { | ||
const encodedValue = encodeURIComponent(value); | ||
let updatedCookie = `${name}=${encodedValue}`; | ||
|
||
if (!options.expires) { | ||
const updatedOptions = { | ||
...DEFAULT_OPTIONS, | ||
...options, | ||
}; | ||
|
||
if (!updatedOptions.expires) { | ||
const date = new Date(); | ||
date.setFullYear(2100); | ||
options.expires = date.toUTCString(); | ||
updatedOptions.expires = date.toUTCString(); | ||
} | ||
|
||
Object.keys(options).forEach(propKey => { | ||
const propValue = options[propKey]; | ||
Object.keys(updatedOptions).forEach(propKey => { | ||
const propValue = updatedOptions[propKey]; | ||
updatedCookie += `; ${propKey}=${propValue}`; | ||
}); | ||
|
||
document.cookie = updatedCookie; | ||
}; | ||
|
||
const removeCookie = ({ name }) => { | ||
setCookie({ | ||
name, | ||
value: '', | ||
options: { | ||
expires: new Date(0).toUTCString(), | ||
}, | ||
}); | ||
}; | ||
|
||
export default { | ||
get: getCookie, | ||
set: setCookie, | ||
remove: removeCookie, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/app/components/page/__stripe/_for/_sort/page-stripe_for_sort.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.page__stripe_for_sort { | ||
margin-top: auto; | ||
padding: 16px 18px 16px 30px; | ||
border-top: 1px solid var(--stroke-color--primary); | ||
|
||
@media print { | ||
display: none; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { default } from './sort-toggler'; | ||
|
||
require('./sort-toggler.scss'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { t } from '@lingui/macro'; | ||
import Toggler from 'app/components/toggler'; | ||
|
||
import { sortService } from 'app/common/services/sort-service'; | ||
|
||
const SortToggler = (props) => ( | ||
<div className={b('sort-toggler', props)}> | ||
<span> | ||
{t`Sort by name`} | ||
</span> | ||
|
||
<Toggler | ||
mods={{ checked: sortService.isGroupsSortingEnabled }} | ||
onChange={sortService.toggleGroupsSorting} | ||
> | ||
{t`Toggle sort by name`} | ||
</Toggler> | ||
</div> | ||
); | ||
|
||
export default SortToggler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.sort-toggler { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
font-weight: 500; | ||
color: var(--color--secondary); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import cookiePrefix from './cookie-prefix'; | ||
|
||
export const SORT_METHOD_GROUPS_COOKIE_NAME = `${cookiePrefix}_is_groups_sorting_enabled`; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters