Skip to content

Commit 1990103

Browse files
feat: pass database to whoami (#1860)
1 parent 613bbf6 commit 1990103

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed

src/containers/App/Content.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {authenticationApi} from '../../store/reducers/authentication/authenticat
1515
import {useCapabilitiesLoaded, useCapabilitiesQuery} from '../../store/reducers/capabilities/hooks';
1616
import {nodesListApi} from '../../store/reducers/nodesList';
1717
import {cn} from '../../utils/cn';
18+
import {useDatabaseFromQuery} from '../../utils/hooks/useDatabaseFromQuery';
1819
import {lazyComponent} from '../../utils/lazyComponent';
1920
import Authentication from '../Authentication/Authentication';
2021
import {getClusterPath} from '../Cluster/utils';
@@ -184,7 +185,8 @@ function DataWrapper({children}: {children: React.ReactNode}) {
184185
}
185186

186187
function GetUser({children}: {children: React.ReactNode}) {
187-
const {isLoading, error} = authenticationApi.useWhoamiQuery(undefined);
188+
const database = useDatabaseFromQuery();
189+
const {isLoading, error} = authenticationApi.useWhoamiQuery({database});
188190

189191
return (
190192
<LoaderWrapper loading={isLoading} size="l">

src/services/api/viewer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ export class ViewerAPI extends BaseYdbAPI {
434434
);
435435
}
436436

437-
whoami() {
438-
return this.get<TUserToken>(this.getPath('/viewer/json/whoami'), {});
437+
whoami({database}: {database?: string}) {
438+
return this.get<TUserToken>(this.getPath('/viewer/json/whoami'), {database});
439439
}
440440

441441
autocomplete(params: {database: string; prefix?: string; limit?: number; table?: string[]}) {

src/store/reducers/authentication/authentication.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export const {selectIsUserAllowedToMakeChanges, selectUser} = slice.selectors;
5050
export const authenticationApi = api.injectEndpoints({
5151
endpoints: (build) => ({
5252
whoami: build.query({
53-
queryFn: async (_, {dispatch}) => {
53+
queryFn: async ({database}: {database?: string}, {dispatch}) => {
5454
try {
55-
const data = await window.api.viewer.whoami();
55+
const data = await window.api.viewer.whoami({database});
5656
dispatch(setUser(data));
5757
return {data};
5858
} catch (error) {

src/store/reducers/capabilities/hooks.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
1-
import {StringParam, useQueryParam} from 'use-query-params';
2-
31
import type {Capability} from '../../../types/api/capabilities';
42
import {useTypedSelector} from '../../../utils/hooks';
3+
import {useDatabaseFromQuery} from '../../../utils/hooks/useDatabaseFromQuery';
54

65
import {capabilitiesApi, selectCapabilityVersion, selectDatabaseCapabilities} from './capabilities';
76

8-
function useDatabaseFromQuery() {
9-
const [database] = useQueryParam('database', StringParam);
10-
11-
// Remove null from database type
12-
return database ?? undefined;
13-
}
14-
157
export function useCapabilitiesQuery() {
168
const database = useDatabaseFromQuery();
179

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {StringParam, useQueryParam} from 'use-query-params';
2+
3+
export function useDatabaseFromQuery() {
4+
const [database] = useQueryParam('database', StringParam);
5+
6+
// Remove null from database type
7+
return database ?? undefined;
8+
}

0 commit comments

Comments
 (0)