Skip to content

Commit 799a05f

Browse files
authored
feat: add YQL autocomplete (#755)
1 parent 9928ee2 commit 799a05f

File tree

8 files changed

+1289
-4
lines changed

8 files changed

+1289
-4
lines changed

package-lock.json

Lines changed: 43 additions & 0 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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"@gravity-ui/paranoid": "^1.4.0",
2121
"@gravity-ui/react-data-table": "^1.2.0",
2222
"@gravity-ui/uikit": "^5.30.1",
23+
"@gravity-ui/websql-autocomplete": "^8.0.2",
2324
"@reduxjs/toolkit": "^2.2.1",
2425
"axios": "^1.6.7",
2526
"bem-cn-lite": "^4.1.0",

src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const b = cn('object-general');
1919

2020
interface ObjectGeneralProps {
2121
type: EPathType;
22+
tenantName: string;
2223
additionalTenantProps?: AdditionalTenantsProps;
2324
additionalNodesProps?: AdditionalNodesProps;
2425
}
@@ -30,13 +31,13 @@ function ObjectGeneral(props: ObjectGeneralProps) {
3031
const [initialPage] = useSetting<string>(TENANT_INITIAL_PAGE_KEY);
3132

3233
const queryParams = parseQuery(location);
33-
const {name: tenantName, tenantPage = initialPage} = queryParams;
34+
const {tenantPage = initialPage} = queryParams;
3435

3536
const renderTabContent = () => {
36-
const {type, additionalTenantProps, additionalNodesProps} = props;
37+
const {type, additionalTenantProps, additionalNodesProps, tenantName} = props;
3738
switch (tenantPage) {
3839
case TENANT_PAGES_IDS.query: {
39-
return <Query path={tenantName as string} theme={theme} type={type} />;
40+
return <Query path={tenantName} theme={theme} type={type} />;
4041
}
4142
default: {
4243
return (
@@ -51,6 +52,7 @@ function ObjectGeneral(props: ObjectGeneralProps) {
5152
};
5253

5354
const renderContent = () => {
55+
const {tenantName} = props;
5456
if (!tenantName) {
5557
return null;
5658
}

src/containers/Tenant/Tenant.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useEffect, useReducer} from 'react';
1+
import {useEffect, useReducer, useRef} from 'react';
22
import cn from 'bem-cn-lite';
33
import {useLocation} from 'react-router';
44
import qs from 'qs';
@@ -11,6 +11,7 @@ import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../.
1111
import {useTypedSelector, useTypedDispatch} from '../../utils/hooks';
1212
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
1313
import {disableAutorefresh, getSchema} from '../../store/reducers/schema/schema';
14+
import {registerYQLCompletionItemProvider} from '../../utils/monaco';
1415

1516
import SplitPane from '../../components/SplitPane';
1617
import {AccessDenied} from '../../components/Errors/403';
@@ -49,6 +50,7 @@ function Tenant(props: TenantProps) {
4950
undefined,
5051
getTenantSummaryState,
5152
);
53+
const previousTenant = useRef<string>();
5254

5355
const {currentSchemaPath, currentSchema: currentItem = {}} = useTypedSelector(
5456
(state) => state.schema,
@@ -77,6 +79,11 @@ function Tenant(props: TenantProps) {
7779
const {name} = queryParams;
7880
const tenantName = name as string;
7981

82+
if (tenantName && typeof tenantName === 'string' && previousTenant.current !== tenantName) {
83+
registerYQLCompletionItemProvider(tenantName);
84+
previousTenant.current = tenantName;
85+
}
86+
8087
useEffect(() => {
8188
dispatch(getSchema({path: tenantName}));
8289
}, [tenantName, dispatch]);
@@ -140,6 +147,7 @@ function Tenant(props: TenantProps) {
140147
type={preloadedPathType || currentPathType}
141148
additionalTenantProps={props.additionalTenantProps}
142149
additionalNodesProps={props.additionalNodesProps}
150+
tenantName={tenantName}
143151
/>
144152
</SplitPane>
145153
)}

src/utils/monaco.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as monaco from 'monaco-editor';
2+
import {createProvideSuggestionsFunction} from './yqlSuggestions/yqlSuggestions';
23

34
export const LANGUAGE_S_EXPRESSION_ID = 's-expression';
45

@@ -64,6 +65,22 @@ function registerSExpressionLanguage() {
6465
});
6566
}
6667

68+
let completionProvider: monaco.IDisposable | undefined;
69+
70+
function disableCodeSuggestions(): void {
71+
if (completionProvider) {
72+
completionProvider.dispose();
73+
}
74+
}
75+
76+
export function registerYQLCompletionItemProvider(database: string) {
77+
disableCodeSuggestions();
78+
completionProvider = monaco.languages.registerCompletionItemProvider('sql', {
79+
triggerCharacters: [' ', '\n', '', ',', '.', '`', '('],
80+
provideCompletionItems: createProvideSuggestionsFunction(database),
81+
});
82+
}
83+
6784
export function registerLanguages() {
6885
registerSExpressionLanguage();
6986
}

0 commit comments

Comments
 (0)