Skip to content
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

feat: add YQL autocomplete #755

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@gravity-ui/paranoid": "^1.4.0",
"@gravity-ui/react-data-table": "^1.2.0",
"@gravity-ui/uikit": "^5.30.1",
"@gravity-ui/websql-autocomplete": "^8.0.2",
"@reduxjs/toolkit": "^2.2.1",
"axios": "^1.6.7",
"bem-cn-lite": "^4.1.0",
Expand Down
8 changes: 5 additions & 3 deletions src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const b = cn('object-general');

interface ObjectGeneralProps {
type: EPathType;
tenantName: string;
additionalTenantProps?: AdditionalTenantsProps;
additionalNodesProps?: AdditionalNodesProps;
}
Expand All @@ -30,13 +31,13 @@ function ObjectGeneral(props: ObjectGeneralProps) {
const [initialPage] = useSetting<string>(TENANT_INITIAL_PAGE_KEY);

const queryParams = parseQuery(location);
const {name: tenantName, tenantPage = initialPage} = queryParams;
const {tenantPage = initialPage} = queryParams;

const renderTabContent = () => {
const {type, additionalTenantProps, additionalNodesProps} = props;
const {type, additionalTenantProps, additionalNodesProps, tenantName} = props;
switch (tenantPage) {
case TENANT_PAGES_IDS.query: {
return <Query path={tenantName as string} theme={theme} type={type} />;
return <Query path={tenantName} theme={theme} type={type} />;
}
default: {
return (
Expand All @@ -51,6 +52,7 @@ function ObjectGeneral(props: ObjectGeneralProps) {
};

const renderContent = () => {
const {tenantName} = props;
if (!tenantName) {
return null;
}
Expand Down
10 changes: 9 additions & 1 deletion src/containers/Tenant/Tenant.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useEffect, useReducer} from 'react';
import {useEffect, useReducer, useRef} from 'react';
import cn from 'bem-cn-lite';
import {useLocation} from 'react-router';
import qs from 'qs';
Expand All @@ -11,6 +11,7 @@ import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../.
import {useTypedSelector, useTypedDispatch} from '../../utils/hooks';
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
import {disableAutorefresh, getSchema} from '../../store/reducers/schema/schema';
import {registerYQLCompletionItemProvider} from '../../utils/monaco';

import SplitPane from '../../components/SplitPane';
import {AccessDenied} from '../../components/Errors/403';
Expand Down Expand Up @@ -49,6 +50,7 @@ function Tenant(props: TenantProps) {
undefined,
getTenantSummaryState,
);
const previousTenant = useRef<string>();

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

if (tenantName && typeof tenantName === 'string' && previousTenant.current !== tenantName) {
registerYQLCompletionItemProvider(tenantName);
previousTenant.current = tenantName;
}

useEffect(() => {
dispatch(getSchema({path: tenantName}));
}, [tenantName, dispatch]);
Expand Down Expand Up @@ -140,6 +147,7 @@ function Tenant(props: TenantProps) {
type={preloadedPathType || currentPathType}
additionalTenantProps={props.additionalTenantProps}
additionalNodesProps={props.additionalNodesProps}
tenantName={tenantName}
/>
</SplitPane>
)}
Expand Down
17 changes: 17 additions & 0 deletions src/utils/monaco.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as monaco from 'monaco-editor';
import {createProvideSuggestionsFunction} from './yqlSuggestions/yqlSuggestions';

export const LANGUAGE_S_EXPRESSION_ID = 's-expression';

Expand Down Expand Up @@ -64,6 +65,22 @@ function registerSExpressionLanguage() {
});
}

let completionProvider: monaco.IDisposable | undefined;

function disableCodeSuggestions(): void {
if (completionProvider) {
completionProvider.dispose();
}
}

export function registerYQLCompletionItemProvider(database: string) {
disableCodeSuggestions();
completionProvider = monaco.languages.registerCompletionItemProvider('sql', {
triggerCharacters: [' ', '\n', '', ',', '.', '`', '('],
provideCompletionItems: createProvideSuggestionsFunction(database),
});
}

export function registerLanguages() {
registerSExpressionLanguage();
}
Loading
Loading