-
Notifications
You must be signed in to change notification settings - Fork 13
feat: add endpoint to connect to db code snippets #2198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {prepareEndpoint} from '../utils'; | ||
|
||
describe('prepareEndpoint', () => { | ||
test('should remove all search params', () => { | ||
const input = 'grpc://example.com:2139/?database=/root/test¶m=value'; | ||
const expected = 'grpc://example.com:2139'; | ||
expect(prepareEndpoint(input)).toBe(expected); | ||
}); | ||
test('should handle URL without path or params', () => { | ||
const input = 'grpc://example.com:2139'; | ||
const expected = 'grpc://example.com:2139'; | ||
expect(prepareEndpoint(input)).toBe(expected); | ||
}); | ||
test('should remove trailing slash from path', () => { | ||
const input = 'grpc://example.com:2139/'; | ||
const expected = 'grpc://example.com:2139'; | ||
expect(prepareEndpoint(input)).toBe(expected); | ||
}); | ||
test('should handle complex paths', () => { | ||
const input = 'grpc://example.com:2139/multi/level/path/?database=/root/test'; | ||
const expected = 'grpc://example.com:2139/multi/level/path'; | ||
expect(prepareEndpoint(input)).toBe(expected); | ||
}); | ||
test('should handle empty string', () => { | ||
expect(prepareEndpoint('')).toBeUndefined(); | ||
}); | ||
test('should handle undefined input', () => { | ||
expect(prepareEndpoint()).toBeUndefined(); | ||
}); | ||
test('should return undefined for invalid URL', () => { | ||
const input = 'invalid-url'; | ||
expect(prepareEndpoint(input)).toBeUndefined(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// We have endpoint in format grpc://example.com:2139/?database=/root/test | ||
// We need it to be like grpc://example.com:2139 to make code in snippets work | ||
// We pass database to snippets as a separate param | ||
export function prepareEndpoint(connectionString = '') { | ||
try { | ||
const urlObj = new URL(connectionString); | ||
urlObj.search = ''; | ||
|
||
let endpoint = urlObj.toString(); | ||
|
||
// Remove trailing slash if present | ||
if (endpoint.endsWith('/')) { | ||
endpoint = endpoint.slice(0, -1); | ||
} | ||
|
||
return endpoint; | ||
} catch { | ||
return undefined; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,7 @@ import {schemaApi} from '../../../../store/reducers/schema/schema'; | |
import {tableSchemaDataApi} from '../../../../store/reducers/tableSchemaData'; | ||
import type {EPathType, TEvDescribeSchemeResult} from '../../../../types/api/schema'; | ||
import {valueIsDefined} from '../../../../utils'; | ||
import { | ||
useQueryExecutionSettings, | ||
useTypedDispatch, | ||
useTypedSelector, | ||
} from '../../../../utils/hooks'; | ||
import {useTypedDispatch, useTypedSelector} from '../../../../utils/hooks'; | ||
import {getConfirmation} from '../../../../utils/hooks/withConfirmation/useChangeInputWithConfirmation'; | ||
import {getSchemaControls} from '../../utils/controls'; | ||
import { | ||
|
@@ -48,7 +44,6 @@ export function SchemaTree(props: SchemaTreeProps) { | |
{currentData: actionsSchemaData, isFetching: isActionsDataFetching}, | ||
] = tableSchemaDataApi.useLazyGetTableSchemaDataQuery(); | ||
|
||
const [querySettings] = useQueryExecutionSettings(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was used only in hook dependencies |
||
const [createDirectoryOpen, setCreateDirectoryOpen] = React.useState(false); | ||
const [parentPath, setParentPath] = React.useState(''); | ||
const setSchemaTreeKey = useDispatchTreeKey(); | ||
|
@@ -144,8 +139,8 @@ export function SchemaTree(props: SchemaTreeProps) { | |
dispatch, | ||
input, | ||
isActionsDataFetching, | ||
isDirty, | ||
onActivePathUpdate, | ||
querySettings, | ||
rootPath, | ||
]); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import {createSelector, createSlice} from '@reduxjs/toolkit'; | ||
import type {Dispatch, PayloadAction} from '@reduxjs/toolkit'; | ||
import {skipToken} from '@reduxjs/toolkit/query'; | ||
import {StringParam, useQueryParam} from 'use-query-params'; | ||
|
||
import type {ClusterTab} from '../../../containers/Cluster/utils'; | ||
import {clusterTabsIds, isClusterTab} from '../../../containers/Cluster/utils'; | ||
|
@@ -10,6 +9,7 @@ import {isClusterInfoV2} from '../../../types/api/cluster'; | |
import type {TClusterInfo} from '../../../types/api/cluster'; | ||
import type {TTabletStateInfo} from '../../../types/api/tablet'; | ||
import {CLUSTER_DEFAULT_TITLE, DEFAULT_CLUSTER_TAB_KEY} from '../../../utils/constants'; | ||
import {useClusterNameFromQuery} from '../../../utils/hooks/useDatabaseFromQuery'; | ||
import {isQueryErrorResponse} from '../../../utils/query'; | ||
import type {RootState} from '../../defaultStore'; | ||
import {api} from '../api'; | ||
|
@@ -136,16 +136,24 @@ export const clusterApi = api.injectEndpoints({ | |
}); | ||
|
||
export function useClusterBaseInfo() { | ||
const [clusterName] = useQueryParam('clusterName', StringParam); | ||
const clusterNameFromQuery = useClusterNameFromQuery(); | ||
|
||
const {currentData} = clusterApi.useGetClusterBaseInfoQuery(clusterName ?? skipToken); | ||
const {currentData} = clusterApi.useGetClusterBaseInfoQuery(clusterNameFromQuery ?? skipToken); | ||
|
||
const {solomon: monitoring, name, trace_view: traceView, ...data} = currentData || {}; | ||
const {solomon: monitoring, name, title, trace_view: traceView, ...data} = currentData || {}; | ||
|
||
// name is used for requests, title is used for display | ||
// Example: | ||
// Name: ydb_vla_dev02 | ||
// Title: YDB DEV VLA02 | ||
const clusterName = name ?? clusterNameFromQuery ?? undefined; | ||
const clusterTitle = title ?? clusterName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a little refactoring to make code more clear |
||
|
||
return { | ||
...data, | ||
...parseTraceFields({traceView}), | ||
name: name ?? clusterName ?? undefined, | ||
name: clusterName, | ||
title: clusterTitle, | ||
monitoring, | ||
}; | ||
} | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left
endpoint
in props to make possible to use dialog in Databases table, where we know all the params from table data and do not need to request them additionally