Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dashboard
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
dashboard
Commits
11e4b579
Commit
11e4b579
authored
8 months ago
by
Konrad Mohrfeldt
Browse files
Options
Downloads
Patches
Plain Diff
refactor: create util namespace
parent
263c5605
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/util/index.ts
+52
-3
52 additions, 3 deletions
src/util/index.ts
with
52 additions
and
3 deletions
src/util.ts
→
src/util
/index
.ts
+
52
−
3
View file @
11e4b579
...
...
@@ -8,6 +8,7 @@ import {
ComputedGetter
,
ComputedRef
,
DebuggerOptions
,
isReadonly
,
MaybeRefOrGetter
,
readonly
,
Ref
,
...
...
@@ -22,6 +23,7 @@ import {
}
from
'
vue
'
import
{
useI18n
}
from
'
@/i18n
'
import
{
SteeringUser
}
from
'
@/stores/auth
'
import
{
APIObject
,
RetrieveMultipleOperation
}
from
'
@rokoli/bnb
'
const
dateFnLocales
=
{
de
:
()
=>
import
(
'
date-fns/locale/de
'
),
...
...
@@ -410,18 +412,18 @@ export function humanJoin(iterable: Iterable<string>, glue: string, lastGlue: st
}
export
function
toQuery
(
query
:
Record
<
string
,
string
|
number
|
null
|
undefined
>
,
query
:
Record
<
string
,
string
|
number
|
boolean
|
Date
|
null
|
undefined
>
,
):
URLSearchParams
{
const
_query
:
Record
<
string
,
string
>
=
{}
for
(
const
[
key
,
value
]
of
Object
.
entries
(
query
))
{
if
(
value
===
null
||
value
===
undefined
)
continue
_query
[
key
]
=
value
.
toString
()
_query
[
key
]
=
value
instanceof
Date
?
value
.
toISOString
()
:
value
.
toString
()
}
return
new
URLSearchParams
(
_query
)
}
export
function
useQuery
(
query
:
MaybeRefOrGetter
<
Record
<
string
,
string
|
number
|
null
|
undefined
>>
,
query
:
MaybeRefOrGetter
<
Record
<
string
,
string
|
number
|
boolean
|
Date
|
null
|
undefined
>>
,
)
{
return
computed
(()
=>
toQuery
(
toValue
(
query
)))
}
...
...
@@ -462,3 +464,50 @@ export function makeRandomString(length: number, options?: { alphabet?: string }
}
return
result
}
export
function
useObjectListFromStore
<
T
extends
APIObject
>
(
ids
:
Ref
<
T
[
'
id
'
][]
>
,
store
:
{
itemMap
:
Map
<
T
[
'
id
'
],
T
>
;
retrieveMultiple
:
RetrieveMultipleOperation
<
T
>
},
):
{
isLoading
:
Readonly
<
Ref
<
boolean
>>
;
objects
:
Ref
<
T
[]
>
}
export
function
useObjectListFromStore
<
T
extends
APIObject
>
(
ids
:
Readonly
<
Ref
<
T
[
'
id
'
][]
>>
|
(()
=>
T
[
'
id
'
][])
|
T
[
'
id
'
][],
store
:
{
itemMap
:
Map
<
T
[
'
id
'
],
T
>
;
retrieveMultiple
:
RetrieveMultipleOperation
<
T
>
},
):
{
isLoading
:
Readonly
<
Ref
<
boolean
>>
;
objects
:
Readonly
<
Ref
<
T
[]
>>
}
export
function
useObjectListFromStore
<
T
extends
APIObject
>
(
ids
:
MaybeRefOrGetter
<
T
[
'
id
'
][]
>
,
store
:
{
itemMap
:
Map
<
T
[
'
id
'
],
T
>
;
retrieveMultiple
:
RetrieveMultipleOperation
<
T
>
},
)
{
const
idsRef
=
toRef
(
ids
)
as
Ref
<
T
[
'
id
'
][]
>
|
Readonly
<
Ref
<
T
[
'
id
'
][]
>>
const
isLoading
=
ref
(
false
)
const
objects
=
computed
({
get
()
{
const
result
=
toValue
(
idsRef
)
.
map
((
id
)
=>
store
.
itemMap
.
get
(
id
))
.
filter
((
item
)
=>
item
!==
undefined
)
return
result
as
T
[]
},
set
(
value
:
T
[])
{
if
(
!
isReadonly
(
idsRef
))
(
idsRef
as
Ref
<
T
[
'
id
'
][]
>
).
value
=
value
.
map
((
obj
)
=>
obj
.
id
)
},
})
watchEffect
(
async
()
=>
{
isLoading
.
value
=
true
try
{
void
(
await
store
.
retrieveMultiple
(
toValue
(
ids
),
{
useCached
:
true
}))
}
finally
{
isLoading
.
value
=
false
}
})
return
{
objects
,
isLoading
:
readonly
(
isLoading
),
}
}
export
function
useMap
<
T
extends
{
id
:
unknown
}
>
(
iterable
:
T
[])
{
return
computed
(()
=>
{
const
map
=
new
Map
<
T
[
'
id
'
],
T
>
()
for
(
const
item
of
iterable
)
map
.
set
(
item
.
id
,
item
)
return
map
})
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment