Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
frontend
Commits
ad8c07d9
Commit
ad8c07d9
authored
Sep 14, 2022
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
link small fixes
parent
7cebfd81
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
+10
-8
link.ts
lib/link/link.ts
+10
-4
useLink.ts
lib/link/useLink.ts
+0
-4
No files found.
lib/link/link.ts
View file @
ad8c07d9
...
...
@@ -6,15 +6,15 @@ import type { RouteName } from './routes';
const
PATH_PARAM_REGEXP
=
/
\/\[(\w
+
)\]
/g
;
export
function
link
(
routeName
:
RouteName
,
urlParams
?:
Record
<
string
,
string
|
undefined
>
,
queryParams
?:
Record
<
string
,
string
>
):
string
{
export
function
link
(
routeName
:
RouteName
,
urlParams
?:
Record
<
string
,
Array
<
string
>
|
string
|
undefined
>
,
queryParams
?:
Record
<
string
,
string
>
):
string
{
const
route
=
ROUTES
[
routeName
];
if
(
!
route
)
{
return
''
;
}
const
network
=
findNetwork
({
network_type
:
urlParams
?.
network_type
||
''
,
network_sub_type
:
urlParams
?.
network_sub_type
,
network_type
:
typeof
urlParams
?.
network_type
===
'
string
'
?
urlParams
?.
network_type
:
''
,
network_sub_type
:
typeof
urlParams
?.
network_sub_type
===
'
string
'
?
urlParams
?.
network_sub_type
:
undefined
,
});
const
path
=
route
.
pattern
.
replace
(
PATH_PARAM_REGEXP
,
(
_
,
paramName
:
string
)
=>
{
...
...
@@ -22,7 +22,13 @@ export function link(routeName: RouteName, urlParams?: Record<string, string | u
return
''
;
}
const
paramValue
=
urlParams
?.[
paramName
];
let
paramValue
=
urlParams
?.[
paramName
];
if
(
Array
.
isArray
(
paramValue
))
{
// FIXME we don't have yet params as array, but typescript says that we could
// dun't know how to manage it, fix me if you find an issue
paramValue
=
paramValue
.
join
(
'
,
'
);
}
return
paramValue
?
`/
${
paramValue
}
`
:
''
;
});
...
...
lib/link/useLink.ts
View file @
ad8c07d9
...
...
@@ -11,10 +11,6 @@ export default function useLink() {
const
networkSubType
=
router
.
query
.
network_sub_type
;
return
React
.
useCallback
((...
args
:
LinkBuilderParams
)
=>
{
if
(
typeof
networkType
!==
'
string
'
||
typeof
networkSubType
!==
'
string
'
)
{
return
''
;
}
return
link
(
args
[
0
],
{
network_type
:
networkType
,
network_sub_type
:
networkSubType
,
...
args
[
1
]
},
args
[
2
]);
},
[
networkType
,
networkSubType
]);
}
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