Skip to content

Commit

Permalink
fix: code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
Raubzeug committed Mar 14, 2024
1 parent 7615856 commit fd479cd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
17 changes: 5 additions & 12 deletions src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {useRef} from 'react';
import {useLocation} from 'react-router';
import cn from 'bem-cn-lite';

Expand All @@ -15,12 +14,12 @@ import {Query} from '../Query/Query';
import Diagnostics from '../Diagnostics/Diagnostics';

import './ObjectGeneral.scss';
import {registerYQLCompletionItemProvider} from '../../../utils/monaco';

const b = cn('object-general');

interface ObjectGeneralProps {
type: EPathType;
tenantName: string;
additionalTenantProps?: AdditionalTenantsProps;
additionalNodesProps?: AdditionalNodesProps;
}
Expand All @@ -29,23 +28,16 @@ function ObjectGeneral(props: ObjectGeneralProps) {
const location = useLocation();
const theme = useThemeValue();

const previousTenant = useRef<string>();

const [initialPage] = useSetting<string>(TENANT_INITIAL_PAGE_KEY);

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

if (tenantName && typeof tenantName === 'string' && previousTenant.current !== tenantName) {
registerYQLCompletionItemProvider(tenantName);
previousTenant.current = tenantName;
}
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 @@ -60,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
9 changes: 8 additions & 1 deletion src/utils/yqlSuggestions/generateSuggestions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ export async function generateColumnsSuggestion(
suggestColumns: YqlAutocompleteResult['suggestColumns'] | undefined,
database: string,
): Promise<monaco.languages.CompletionItem[]> {
if (!suggestColumns?.tables) {
return [];
}
const suggestions: monaco.languages.CompletionItem[] = [];
for (const entity of suggestColumns?.tables ?? []) {
const multi = suggestColumns.tables.length > 1;
for (const entity of suggestColumns.tables ?? []) {
let normalizedEntityName = removeBackticks(entity.name);
// if it's relative entity path
if (!normalizedEntityName.startsWith('/')) {
Expand All @@ -141,6 +145,9 @@ export async function generateColumnsSuggestion(
let columnNameSuggestion = normalizedName;
if (entity.alias) {
columnNameSuggestion = `${entity.alias}.${normalizedName}`;
} else if (multi) {
// no need to wrap entity.name to backticks, because it's already with them if needed
columnNameSuggestion = `${entity.name}.${normalizedName}`;
}
suggestions.push({
label: columnNameSuggestion,
Expand Down

0 comments on commit fd479cd

Please sign in to comment.