Skip to content

Commit f86728a

Browse files
authored
Merge pull request #41 from Solovev-A/improvement-method-groups-order
Add method groups sorting
2 parents 654fa04 + 50dc2f3 commit f86728a

File tree

20 files changed

+133
-18
lines changed

20 files changed

+133
-18
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 6.1.0 (01.02.2024)
4+
5+
Added an option to sort method groups by name.
6+
37
## 6.0.0 (06.06.2023)
48

59
Dropped support for Node.js 12.

CHANGELOG.ru.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# История изменений проекта
22

3+
## 6.1.0 (01.02.2024)
4+
5+
Добавлена возможность сортировки групп методов по названию.
6+
37
## 6.0.0 (06.06.2023)
48

59
Node.js 12 больше не поддерживается.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@funboxteam/blueprinter",
3-
"version": "6.0.0",
3+
"version": "6.1.0",
44
"description": "Replacement of Aglio library for rendering generated AST as HTML page.",
55
"repository": {
66
"type": "git",

src/app/common/providers/theme-provider/theme-provider.jsx

+1-5
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class ThemeProvider extends React.Component {
7171

7272
updateTheme(theme) {
7373
this.applyTheme(theme);
74-
cookies.set({ name: themeCookieName, value: theme, options: { domain: this.documentationDomain } });
74+
cookies.set({ name: themeCookieName, value: theme });
7575
this.darkQuery.removeListener(this.applySystemTheme);
7676
}
7777

@@ -81,10 +81,6 @@ class ThemeProvider extends React.Component {
8181
this.updateTheme(newTheme);
8282
}
8383

84-
get documentationDomain() {
85-
return window.location.hostname.split('.').slice(-2).join('.');
86-
}
87-
8884
render() {
8985
return (
9086
<ThemeContext.Provider value={this.state}>
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import cookies from 'app/common/utils/helpers/cookies';
2+
3+
import { SORT_METHOD_GROUPS_COOKIE_NAME } from 'app/constants/sort';
4+
5+
class SortService {
6+
constructor() {
7+
this.isGroupsSortingEnabled = !!cookies.get({
8+
name: SORT_METHOD_GROUPS_COOKIE_NAME,
9+
});
10+
11+
this.toggleGroupsSorting = this.toggleGroupsSorting.bind(this);
12+
}
13+
14+
sortGroups(groups) {
15+
return [...groups].sort((a, b) => a.title.localeCompare(b.title));
16+
}
17+
18+
toggleGroupsSorting() {
19+
if (this.isGroupsSortingEnabled) {
20+
cookies.remove({ name: SORT_METHOD_GROUPS_COOKIE_NAME });
21+
} else {
22+
cookies.set({ name: SORT_METHOD_GROUPS_COOKIE_NAME, value: true });
23+
}
24+
25+
window.location.reload();
26+
}
27+
}
28+
29+
export const sortService = new SortService();
+29-5
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,52 @@
1+
const DEFAULT_OPTIONS = {
2+
domain: window.location.hostname.split('.').slice(-2).join('.'),
3+
};
4+
15
const getCookie = ({ name }) => {
26
const regex = `(?:^|; )${name.replace(/([.$?*|{}()[\]\\/+^])/g, '\\$1')}=([^;]*)`;
37
const matches = document.cookie.match(new RegExp(regex));
48
return matches ? decodeURIComponent(matches[1]) : undefined;
59
};
610

7-
const setCookie = ({ name, value, options = { path: '/' } }) => {
11+
const setCookie = ({
12+
name,
13+
value,
14+
options = {},
15+
}) => {
816
const encodedValue = encodeURIComponent(value);
917
let updatedCookie = `${name}=${encodedValue}`;
1018

11-
if (!options.expires) {
19+
const updatedOptions = {
20+
...DEFAULT_OPTIONS,
21+
...options,
22+
};
23+
24+
if (!updatedOptions.expires) {
1225
const date = new Date();
1326
date.setFullYear(2100);
14-
options.expires = date.toUTCString();
27+
updatedOptions.expires = date.toUTCString();
1528
}
1629

17-
Object.keys(options).forEach(propKey => {
18-
const propValue = options[propKey];
30+
Object.keys(updatedOptions).forEach(propKey => {
31+
const propValue = updatedOptions[propKey];
1932
updatedCookie += `; ${propKey}=${propValue}`;
2033
});
2134

2235
document.cookie = updatedCookie;
2336
};
2437

38+
const removeCookie = ({ name }) => {
39+
setCookie({
40+
name,
41+
value: '',
42+
options: {
43+
expires: new Date(0).toUTCString(),
44+
},
45+
});
46+
};
47+
2548
export default {
2649
get: getCookie,
2750
set: setCookie,
51+
remove: removeCookie,
2852
};

src/app/components/app/app.jsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import parseSourceFile from 'app/common/utils/helpers/parse-source-file';
44
import { HASH_DELIMITER } from 'app/common/utils/helpers/hash';
55
import IdProvider from 'app/common/utils/helpers/id-provider';
66
import sourceMock from 'app/source';
7+
import { sortService } from 'app/common/services/sort-service';
78

89
import MainLayout from 'app/components/main-layout';
910
import PageDescription from 'app/components/page-description';
@@ -28,6 +29,10 @@ const {
2829
actions,
2930
} = parsedSource;
3031

32+
const groupsToDisplay = sortService.isGroupsSortingEnabled
33+
? sortService.sortGroups(groups)
34+
: groups;
35+
3136
const isModal = location => {
3237
const modalPaths = ['/service-help'];
3338
return modalPaths.indexOf(location.pathname) >= 0;
@@ -98,7 +103,7 @@ export default class App extends React.Component {
98103
return (
99104
<MainLayout
100105
topLevelMeta={topLevelMeta}
101-
groups={groups}
106+
groups={groupsToDisplay}
102107
resources={resources}
103108
actions={actions}
104109
>
@@ -127,7 +132,7 @@ export default class App extends React.Component {
127132
}
128133
<ManualSearch
129134
{...props}
130-
groups={groups}
135+
groups={groupsToDisplay}
131136
/>
132137
</ViewContext.Provider>
133138
)}

src/app/components/main-layout/main-layout.jsx

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Link from 'app/components/link';
1919
import SearchStripe from 'app/components/search-stripe';
2020
import ThemeToggler from 'app/components/theme-toggler';
2121
import InfoButton from 'app/components/info-button';
22+
import SortToggler from 'app/components/sort-toggler';
2223

2324
import { API_DEFAULT_TITLE } from 'app/constants/defaults';
2425

@@ -105,6 +106,10 @@ class MainLayout extends React.PureComponent {
105106
<SideMenu data={groups}/>
106107
<PrintMenu data={groups}/>
107108
</Page__Navigation>
109+
110+
<Page__Stripe mods={{ for: 'sort' }}>
111+
<SortToggler/>
112+
</Page__Stripe>
108113
</Page__Aside>
109114
</Sidebar>
110115

src/app/components/page/__aside/_for/_navigation/page__aside_for_navigation.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
top: 0;
77
box-sizing: border-box;
88
height: 100vh;
9-
padding: 24px 0;
9+
padding-top: 24px;
1010
background-color: var(--background-color--sidebar);
1111

1212
@media print {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.page__stripe_for_sort {
2+
margin-top: auto;
3+
padding: 16px 18px 16px 30px;
4+
border-top: 1px solid var(--stroke-color--primary);
5+
6+
@media print {
7+
display: none;
8+
}
9+
}

src/app/components/page/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require('./__navigation/page__navigation.scss');
1313
require('./__stripe/_for/_api-host/page__stripe_for_api-host.scss');
1414
require('./__stripe/_for/_search/page__stripe_for_search.scss');
1515
require('./__stripe/_for/_group/page__stripe_for_group.scss');
16+
require('./__stripe/_for/_sort/page-stripe_for_sort.scss');
1617
require('./__title/page__title.scss');
1718

1819
require('./_type/_error/page_type_error.scss');
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default } from './sort-toggler';
2+
3+
require('./sort-toggler.scss');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { t } from '@lingui/macro';
2+
import Toggler from 'app/components/toggler';
3+
4+
import { sortService } from 'app/common/services/sort-service';
5+
6+
const SortToggler = (props) => (
7+
<div className={b('sort-toggler', props)}>
8+
<span>
9+
{t`Sort by name`}
10+
</span>
11+
12+
<Toggler
13+
mods={{ checked: sortService.isGroupsSortingEnabled }}
14+
onChange={sortService.toggleGroupsSorting}
15+
>
16+
{t`Toggle sort by name`}
17+
</Toggler>
18+
</div>
19+
);
20+
21+
export default SortToggler;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.sort-toggler {
2+
display: flex;
3+
align-items: center;
4+
justify-content: space-between;
5+
font-weight: 500;
6+
color: var(--color--secondary);
7+
}

src/app/constants/sort.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import cookiePrefix from './cookie-prefix';
2+
3+
export const SORT_METHOD_GROUPS_COOKIE_NAME = `${cookiePrefix}_is_groups_sorting_enabled`;

src/locales/en/messages.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.json

+2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
"Search modifiers": "Search modifiers",
2626
"Show Body example": "Show Body example",
2727
"Show help": "Show help",
28+
"Sort by name": "Sort by name",
2829
"This message has no content": "This message has no content",
2930
"This request has no content": "This request has no content",
3031
"This response has no content": "This response has no content",
3132
"To manual search page": "To manual search page",
3233
"Toggle dark theme": "Toggle dark theme",
34+
"Toggle sort by name": "Toggle sort by name",
3335
"Type a modifier in the search field before the search query.": "Type a modifier in the search field before the search query.",
3436
"URI Parameters": "URI Parameters",
3537
"Useful information": "Useful information",

src/locales/ru/messages.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/ru/messages.json

+2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
"Search modifiers": "Модификаторы поиска",
2626
"Show Body example": "Показать пример Body",
2727
"Show help": "Открыть окно помощи",
28+
"Sort by name": "Сортировать по названию",
2829
"This message has no content": "Пустое сообщение",
2930
"This request has no content": "Пустой запрос",
3031
"This response has no content": "Пустой ответ",
3132
"To manual search page": "Перейти на страницу ручного поиска",
3233
"Toggle dark theme": "Включить тёмную тему",
34+
"Toggle sort by name": "Включить сортировку по названию",
3335
"Type a modifier in the search field before the search query.": "Модификатор указывается в строке поиска перед поисковым запросом.",
3436
"URI Parameters": "URI параметры",
3537
"Useful information": "Полезная информация",

0 commit comments

Comments
 (0)