Skip to content

Commit 2ee3177

Browse files
Refactored + added demo for manifestFileComparer
1 parent c2ea59f commit 2ee3177

File tree

4 files changed

+258
-10
lines changed

4 files changed

+258
-10
lines changed

src/components/file/helpers.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,15 @@ const REGEX_TSV_BOOK_ABBREVIATION = /^\w*_(\w*)\.tsv$/i;
8080
export const manifestFileComparer = ({
8181
repository, item1, item2,
8282
}) => {
83+
const item1Path = item1?.path;
84+
const item2Path = item2?.path;
85+
8386
let compare = 0;
8487

85-
if (item1 && item2 && repository && repository.books)
88+
if (item1Path && item2Path && repository && repository.books)
8689
{
87-
const book1Matches = item1.match(REGEX_TSV_BOOK_ABBREVIATION);
88-
const book2Matches = item2.match(REGEX_TSV_BOOK_ABBREVIATION);
90+
const book1Matches = item1Path.match(REGEX_TSV_BOOK_ABBREVIATION);
91+
const book2Matches = item2Path.match(REGEX_TSV_BOOK_ABBREVIATION);
8992

9093
const isTsvFiles = (book1Matches && book2Matches)?true:false;
9194
if (isTsvFiles)
@@ -134,7 +137,7 @@ export const manifestFileComparer = ({
134137
}
135138
else
136139
{
137-
compare = item1.localeCompare(item2);
140+
compare = item1Path.localeCompare(item2Path);
138141
}
139142
}
140143
}

src/components/tree-blob/TreeObject.md

+29-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,33 @@ import { TreeObject } from 'gitea-react-toolkit';
3939

4040
### URL + Sorting Example
4141

42+
```js
43+
import { Paper } from '@material-ui/core';
44+
import { TreeObject } from 'gitea-react-toolkit';
45+
import {manifestFileComparer} from '../file/helpers';
46+
47+
import repository from './mocks/repositoryData-twl.json';
48+
49+
const tsvManifestFileComparer = ((item1,item2) => {
50+
// Repository instance can be passed from application.
51+
return manifestFileComparer({repository, item1, item2});
52+
});
53+
54+
<Paper>
55+
<TreeObject
56+
path=""
57+
type="tree"
58+
selected
59+
pathSelected="LICENSE.md"
60+
url="https://qa.door43.org/api/v1/repos/unfoldingWord/en_twl/git/trees/master?recursive=true"
61+
onBlob={(data) => alert(JSON.stringify(data, null, 2))}
62+
comparer={tsvManifestFileComparer}
63+
/>
64+
</Paper>
65+
```
66+
67+
### URL + Custom Sorting Example
68+
4269
```js
4370
import { Paper } from '@material-ui/core';
4471
import { TreeObject } from 'gitea-react-toolkit';
@@ -53,9 +80,9 @@ import { TreeObject } from 'gitea-react-toolkit';
5380
onBlob={(data) => alert(JSON.stringify(data, null, 2))}
5481
comparer={(item1,item2)=>{
5582
if (item1.path < item2.path)
56-
return 1;
57-
if ( item1.path > item2.path)
5883
return -1;
84+
if ( item1.path > item2.path)
85+
return 1;
5986
return 0;
6087
}}
6188
/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
{
2+
"id": 63385,
3+
"owner": {
4+
"id": 4598,
5+
"login": "Door43-Catalog",
6+
"full_name": "Door43 Resource Catalog",
7+
"email": "[email protected]",
8+
"avatar_url": "https://qa.door43.org/user/avatar/Door43-Catalog/-1",
9+
"language": "",
10+
"is_admin": false,
11+
"last_login": "0001-01-01T00:00:00Z",
12+
"created": "2016-10-18T19:03:36Z",
13+
"repo_languages": [
14+
"am",
15+
"ar",
16+
"as",
17+
"bn",
18+
"ceb",
19+
"el-x-koine",
20+
"en",
21+
"es",
22+
"es-419",
23+
"fa",
24+
"fr",
25+
"gof",
26+
"gu",
27+
"guq",
28+
"ha",
29+
"hbo",
30+
"hi",
31+
"hmr",
32+
"hr",
33+
"id",
34+
"ilo",
35+
"kn",
36+
"lo",
37+
"lpx",
38+
"lus",
39+
"ml",
40+
"mr",
41+
"nag",
42+
"ne",
43+
"or",
44+
"pa",
45+
"plt",
46+
"pt-br",
47+
"rmy-x-bsa",
48+
"rmy-x-vc",
49+
"rmy-x-vg",
50+
"rmy-x-vwa",
51+
"ru",
52+
"sgj",
53+
"sr-Latn",
54+
"sw",
55+
"ta",
56+
"tdj",
57+
"te",
58+
"th",
59+
"tl",
60+
"tpi",
61+
"tr",
62+
"ur",
63+
"ur-deva",
64+
"vi"
65+
],
66+
"repo_subjects": [
67+
"Aligned Bible",
68+
"Bible",
69+
"Greek New Testament",
70+
"Hebrew Old Testament",
71+
"OBS Study Notes",
72+
"OBS Study Questions",
73+
"OBS Translation Notes",
74+
"OBS Translation Questions",
75+
"Open Bible Stories",
76+
"Translation Academy",
77+
"Translation Notes",
78+
"Translation Questions",
79+
"Translation Words",
80+
"TSV OBS Translation Words Links",
81+
"TSV Translation Notes",
82+
"TSV Translation Questions",
83+
"TSV Translation Words Links"
84+
],
85+
"restricted": false,
86+
"username": "Door43-Catalog"
87+
},
88+
"name": "en_twl",
89+
"full_name": "Door43-Catalog/en_twl",
90+
"description": "Links from the original language words to Translation Words articles. Previously customized links in UHB and UGNT were used (but that didn't enable them to be customized for Gateway Languages).",
91+
"empty": false,
92+
"private": false,
93+
"fork": false,
94+
"template": false,
95+
"parent": null,
96+
"mirror": false,
97+
"size": 1934,
98+
"html_url": "https://qa.door43.org/Door43-Catalog/en_twl",
99+
"ssh_url": "[email protected]:Door43-Catalog/en_twl.git",
100+
"clone_url": "https://qa.door43.org/Door43-Catalog/en_twl.git",
101+
"original_url": "",
102+
"website": "",
103+
"stars_count": 0,
104+
"forks_count": 0,
105+
"watchers_count": 0,
106+
"open_issues_count": 0,
107+
"open_pr_counter": 0,
108+
"release_counter": 0,
109+
"default_branch": "master",
110+
"archived": false,
111+
"created_at": "2021-03-21T23:48:24Z",
112+
"updated_at": "2021-03-21T23:55:02Z",
113+
"permissions": {
114+
"admin": false,
115+
"push": false,
116+
"pull": true
117+
},
118+
"has_issues": true,
119+
"internal_tracker": {
120+
"enable_time_tracker": true,
121+
"allow_only_contributors_to_track_time": true,
122+
"enable_issue_dependencies": true
123+
},
124+
"has_wiki": true,
125+
"has_pull_requests": true,
126+
"has_projects": false,
127+
"ignore_whitespace_conflicts": false,
128+
"allow_merge_commits": true,
129+
"allow_rebase": true,
130+
"allow_rebase_explicit": true,
131+
"allow_squash_merge": true,
132+
"avatar_url": "",
133+
"internal": false,
134+
"language": "en",
135+
"subject": "TSV Translation Words Links",
136+
"books": [
137+
"gen",
138+
"exo",
139+
"lev",
140+
"num",
141+
"deu",
142+
"jos",
143+
"jdg",
144+
"rut",
145+
"1sa",
146+
"2sa",
147+
"1ki",
148+
"2ki",
149+
"1ch",
150+
"2ch",
151+
"ezr",
152+
"neh",
153+
"est",
154+
"job",
155+
"psa",
156+
"pro",
157+
"ecc",
158+
"sng",
159+
"isa",
160+
"jer",
161+
"lam",
162+
"ezk",
163+
"dan",
164+
"hos",
165+
"jol",
166+
"amo",
167+
"oba",
168+
"jon",
169+
"mic",
170+
"nam",
171+
"hab",
172+
"zep",
173+
"hag",
174+
"zec",
175+
"mal",
176+
"mat",
177+
"mrk",
178+
"luk",
179+
"jhn",
180+
"act",
181+
"rom",
182+
"1co",
183+
"2co",
184+
"gal",
185+
"eph",
186+
"php",
187+
"col",
188+
"1th",
189+
"2th",
190+
"1ti",
191+
"2ti",
192+
"tit",
193+
"phm",
194+
"heb",
195+
"jas",
196+
"1pe",
197+
"2pe",
198+
"1jn",
199+
"2jn",
200+
"3jn",
201+
"jud",
202+
"rev"
203+
],
204+
"title": "unfoldingWord® Translation Words Links",
205+
"checking_level": "3",
206+
"catalog": {
207+
"prod": null,
208+
"preprod": null,
209+
"draft": null,
210+
"latest": {
211+
"branch_or_tag_name": "master",
212+
"release_url": null,
213+
"released": "2021-03-21T23:54:27Z",
214+
"zipball_url": "https://qa.door43.org/Door43-Catalog/en_twl/archive/master.zip",
215+
"tarball_url": "https://qa.door43.org/Door43-Catalog/en_twl/archive/master.tar.gz"
216+
}
217+
},
218+
"mirror_interval": "",
219+
"tree_url": "api/v1/repos/Door43-Catalog/en_twl/git/trees/master"
220+
}

src/components/tree-blob/useBlob.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ function useBlob({
3030
}, [update]);
3131

3232
const tsvManifestFileComparer = useCallback((item1,item2) => {
33-
const item1Path = item1?.path;
34-
const item2Path = item2?.path;
35-
return manifestFileComparer({repository, item1: item1Path, item2: item2Path});
33+
return manifestFileComparer({repository, item1, item2});
3634
}, [manifestFileComparer]);
37-
35+
3836
const browse = useMemo(() => {
3937
return (tree || url) ? (
4038
<Tree

0 commit comments

Comments
 (0)