mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-10-29 19:19:39 +08:00
* CB-3372 feat: codemirror6 autocomplete * CB-3372 feat: autocomplete icons * CB-3371 feat: sql editor syntax highlight * CB-3371 fix: syntax highlight blinking * CB-3371 fix: editor extensions state * CB-3372 chore: code cleanup * CB-3372 fix: remove useSqlDIalectAutocompletion * CB-3372 fix: add useSqlDIalectAutocompletion * CB-3372 feat: experimental context menu * CB-3372 feat: use new sql editor * CB-3372 chore: remove sql script parser * CB-3372 fix: rounded menu * CB-3372 fix: event preventDefault on dialog * CB-3372 fix: context menu styles * CB-3372 feat: remove old codemirror * CB-3372 fix: numbers completion & extensions caching * CB-3372 fix: table display * CB-3372 fix: decrease sql editor font size * CB-3372 fix: copy in readonly mode & autocompletion in safari on MacOS * CB-3372 fix: value panel styles * CB-3372 fix: menu bar styles * CB-3372 fix: menu bar and inline editor styles * CB-3372 fix: menu and inline editor styles * CB-3372 chore: update bundle --------- Co-authored-by: dariamarutkina <125263541+dariamarutkina@users.noreply.github.com>
79 lines
1.8 KiB
TypeScript
79 lines
1.8 KiB
TypeScript
/*
|
|
* CloudBeaver - Cloud Database Manager
|
|
* Copyright (C) 2020-2023 DBeaver Corp and others
|
|
*
|
|
* Licensed under the Apache License, Version 2.0.
|
|
* you may not use this file except in compliance with the License.
|
|
*/
|
|
|
|
import { LoadingError } from '@cloudbeaver/core-utils';
|
|
|
|
export interface IComplexLoaderData<T> {
|
|
promise: Promise<T> | undefined;
|
|
data: T | undefined;
|
|
error: Error | undefined;
|
|
loader: () => Promise<T>;
|
|
refresh: () => void;
|
|
}
|
|
|
|
export interface ComplexLoaderProps<T> {
|
|
loader: IComplexLoaderData<T>;
|
|
children: (content: T) => JSX.Element;
|
|
}
|
|
|
|
export function useComplexLoader<T>(loader: IComplexLoaderData<T>): T {
|
|
if (loader.error) {
|
|
throw loader.error;
|
|
}
|
|
if (loader.data) {
|
|
return loader.data;
|
|
}
|
|
throw loader.loader();
|
|
}
|
|
|
|
export const ComplexLoader: React.FC<ComplexLoaderProps<any>> = function ComplexLoader(props) {
|
|
if (props.loader.error) {
|
|
throw props.loader.error;
|
|
}
|
|
if (props.loader.data) {
|
|
return props.children(props.loader.data);
|
|
}
|
|
throw props.loader.loader();
|
|
};
|
|
|
|
export function createComplexLoader<T>(loader: () => Promise<T>): IComplexLoaderData<T> {
|
|
return {
|
|
promise: undefined,
|
|
data: undefined,
|
|
error: undefined,
|
|
async loader() {
|
|
if (this.data !== undefined) {
|
|
return this.data;
|
|
}
|
|
|
|
if (this.error) {
|
|
throw this.error;
|
|
}
|
|
|
|
if (this.promise) {
|
|
return await this.promise;
|
|
}
|
|
|
|
this.promise = loader();
|
|
|
|
try {
|
|
this.data = await this.promise;
|
|
return this.data;
|
|
} catch (cause: any) {
|
|
this.error = new LoadingError(() => this.refresh(), 'Can\'t load element', { cause });
|
|
throw this.error;
|
|
}
|
|
},
|
|
refresh() {
|
|
this.promise = undefined;
|
|
this.data = undefined;
|
|
this.error = undefined;
|
|
},
|
|
};
|
|
}
|