Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
parity-signer
Commits
12a7624f
Unverified
Commit
12a7624f
authored
Jul 13, 2020
by
Hanwen Cheng
Committed by
GitHub
Jul 13, 2020
Browse files
reorder the paths and pathsGroups (#653)
parent
8640340c
Pipeline
#100305
failed with stages
in 3 minutes and 19 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/utils/identitiesUtils.ts
View file @
12a7624f
...
...
@@ -341,6 +341,39 @@ export const getPathName = (
return
extractSubPathName
(
path
);
};
const
_comparePathGroups
=
(
a
:
PathGroup
,
b
:
PathGroup
):
number
=>
{
const
isSingleGroupA
=
a
.
paths
.
length
===
1
;
const
isSingleGroupB
=
b
.
paths
.
length
===
1
;
if
(
isSingleGroupA
&&
isSingleGroupB
)
{
return
a
.
paths
[
0
].
length
-
b
.
paths
[
0
].
length
;
}
if
(
isSingleGroupA
!==
isSingleGroupB
)
{
return
isSingleGroupA
?
-
1
:
1
;
}
return
a
.
title
.
localeCompare
(
b
.
title
);
};
const
_comparePathsInGroup
=
(
a
:
string
,
b
:
string
):
number
=>
{
const
pathFragmentsA
=
a
.
match
(
pathsRegex
.
allPath
)
!
;
const
pathFragmentsB
=
b
.
match
(
pathsRegex
.
allPath
)
!
;
if
(
pathFragmentsA
.
length
!==
pathFragmentsB
.
length
)
{
return
pathFragmentsA
.
length
-
pathFragmentsB
.
length
;
}
const
lastFragmentA
=
pathFragmentsA
[
pathFragmentsA
.
length
-
1
];
const
lastFragmentB
=
pathFragmentsB
[
pathFragmentsB
.
length
-
1
];
const
numberA
=
parseInt
(
removeSlash
(
lastFragmentA
),
10
);
const
numberB
=
parseInt
(
removeSlash
(
lastFragmentB
),
10
);
const
isNumberA
=
!
isNaN
(
numberA
);
const
isNumberB
=
!
isNaN
(
numberB
);
if
(
isNumberA
&&
isNumberB
)
{
return
numberA
-
numberB
;
}
if
(
isNumberA
!==
isNumberB
)
{
return
isNumberA
?
-
1
:
1
;
}
return
lastFragmentA
.
localeCompare
(
lastFragmentB
);
};
/**
* This function decides how to group the list of derivation paths in the display based on the following rules.
* If the network is unknown: group by the first subpath, e.g. '/random' of '/random//derivation/1'
...
...
@@ -359,7 +392,7 @@ export const groupPaths = (paths: string[]): PathGroup[] => {
const
existedItem
=
pathGroup
.
find
(
p
=>
p
.
title
===
groupName
);
if
(
existedItem
)
{
existedItem
.
paths
.
push
(
fullPath
);
existedItem
.
paths
.
sort
();
existedItem
.
paths
.
sort
(
_comparePathsInGroup
);
}
else
{
pathGroup
.
push
({
paths
:
[
fullPath
],
title
:
groupName
});
}
...
...
@@ -399,12 +432,7 @@ export const groupPaths = (paths: string[]): PathGroup[] => {
},
[]
);
return
groupedPaths
.
sort
((
a
,
b
)
=>
{
if
(
a
.
paths
.
length
===
1
&&
b
.
paths
.
length
===
1
)
{
return
a
.
paths
[
0
].
length
-
b
.
paths
[
0
].
length
;
}
return
a
.
paths
.
length
-
b
.
paths
.
length
;
});
return
groupedPaths
.
sort
(
_comparePathGroups
);
};
export
const
getMetadata
=
(
networkKey
:
string
):
string
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment