Skip to content

Commit 750889e

Browse files
committed
fix: add handling for user and api token
1 parent 84a8494 commit 750889e

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@devtron-labs/devtron-fe-common-lib",
3-
"version": "0.2.6-beta-12",
3+
"version": "0.2.6-beta-13",
44
"description": "Supporting common component library",
55
"type": "module",
66
"main": "dist/index.js",
Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
import { get } from '@Common/index'
1+
import { get, getUrlWithSearchParams } from '@Common/index'
22
import { SelectPickerCustomOptionType } from '@Shared/Components'
33
import { API_TOKEN_PREFIX } from '@Shared/constants'
44
import { stringComparatorBySortOrder } from '@Shared/Helpers'
5-
import { DefaultUserKey } from '@Shared/types'
5+
import { DefaultUserKey, BaseFilterQueryParams } from '@Shared/types'
66
import { GroupBase } from 'react-select'
77

88
// FIXME: Common out the typing and url from dashboard
99
export const getUserAndApiTokenOptions = async (): Promise<GroupBase<SelectPickerCustomOptionType<string>>[]> => {
10-
const [{ result: userResponse }, { result: apiTokenResponse }] = await Promise.all([
11-
get('user/v2'),
12-
get('api-token'),
13-
])
10+
const userUrl = getUrlWithSearchParams('user/v2', {
11+
showAll: true,
12+
} as BaseFilterQueryParams<never>)
1413

15-
return [
16-
{
14+
const [userPromise, apiTokenPromise] = await Promise.allSettled([get(userUrl), get('api-token')])
15+
16+
const options: GroupBase<SelectPickerCustomOptionType<string>>[] = []
17+
18+
if (userPromise.status === 'fulfilled') {
19+
const { result: userResponse } = userPromise.value
20+
21+
options.push({
1722
label: 'Users',
1823
options: (userResponse?.users ?? [])
1924
.sort((a, b) => stringComparatorBySortOrder(a.email_id, b.email_id))
@@ -22,8 +27,13 @@ export const getUserAndApiTokenOptions = async (): Promise<GroupBase<SelectPicke
2227
label: emailId,
2328
value: emailId,
2429
})),
25-
},
26-
{
30+
})
31+
}
32+
33+
if (apiTokenPromise.status === 'fulfilled') {
34+
const { result: apiTokenResponse } = apiTokenPromise.value
35+
36+
options.push({
2737
label: 'API Tokens',
2838
options: (apiTokenResponse ?? [])
2939
.sort((a, b) => stringComparatorBySortOrder(a.userIdentifier, b.userIdentifier))
@@ -32,6 +42,8 @@ export const getUserAndApiTokenOptions = async (): Promise<GroupBase<SelectPicke
3242
label: userIdentifier.startsWith(API_TOKEN_PREFIX) ? userIdentifier.split(':')[1] : userIdentifier,
3343
value: userIdentifier,
3444
})),
35-
},
36-
]
45+
})
46+
}
47+
48+
return options
3749
}

0 commit comments

Comments
 (0)