/
alt3rmann
/
cloudbeaver
Обзор
Документация
Войти
/
alt3rmann
/
cloudbeaver
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
devel
webapp/packages/plugin-data-viewer/src/DataPresentationService.ts
131 строка
4 KB
Alexey Potsetsuev
dbeaver/pro#6744 refactor: migration to `@wroud/di` (#3704)
29 авг 2025, 13:22
Не верифицирован
29 авг 2025, 13:22
80f258b
Код
Авторство
О чём код?
/* * CloudBeaver - Cloud Database Manager * Copyright (C) 2020-2025 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 type { HTMLAttributes } from 'react'; import { injectable } from '@cloudbeaver/core-di'; import type { ResultDataFormat } from '@cloudbeaver/core-sdk'; import type { TabProps } from '@cloudbeaver/core-ui'; import type { IDatabaseDataModel } from './DatabaseDataModel/IDatabaseDataModel.js'; import type { IDataTableActions } from './TableViewer/IDataTableActions.js'; export interface IDataPresentationProps extends HTMLAttributes<HTMLDivElement> { dataFormat: ResultDataFormat; model: IDatabaseDataModel; actions: IDataTableActions; resultIndex: number; simple: boolean; className?: string; } export enum DataPresentationType { main, toolsPanel, } export type DataPresentationComponent = React.FunctionComponent<IDataPresentationProps>; export type PresentationTabProps = TabProps & { presentation: IDataPresentationOptions; model: IDatabaseDataModel; }; export type PresentationTabComponent = React.FunctionComponent<PresentationTabProps>; export interface IDataPresentationOptions { id: string; dataFormat?: ResultDataFormat; type?: DataPresentationType; title?: string; icon?: string; order?: number; hidden?: (dataFormat: ResultDataFormat | null, model: IDatabaseDataModel, resultIndex: number) => boolean; getPresentationComponent: () => DataPresentationComponent; getTabComponent?: () => PresentationTabComponent; onActivate?: () => void; } export interface IDataPresentation extends IDataPresentationOptions { type: DataPresentationType; order: number; } @injectable() export class DataPresentationService { private get orderedPresentations(): IDataPresentation[] { return Array.from(this.dataPresentations.values()).sort((a, b) => b.order - a.order); } private readonly dataPresentations: Map<string, IDataPresentation>; constructor() { this.dataPresentations = new Map(); } get(id: string): IDataPresentation | undefined { return this.dataPresentations.get(id); } getSupportedList( type: DataPresentationType, supportedDataFormats: ResultDataFormat[], dataFormat: ResultDataFormat, model: IDatabaseDataModel, resultIndex: number, ): IDataPresentation[] { return this.orderedPresentations.filter(presentation => { if (presentation.dataFormat !== undefined && !supportedDataFormats.includes(presentation.dataFormat)) { return false; } if (presentation.type !== type || presentation.hidden?.(dataFormat, model, resultIndex)) { return false; } return true; }); } getSupported( type: DataPresentationType, dataFormat: ResultDataFormat, presentationId: string | undefined, model: IDatabaseDataModel, resultIndex: number, ): IDataPresentation | null { if (presentationId) { const presentation = this.dataPresentations.get(presentationId); if (presentation) { if (presentation.hidden?.(dataFormat, model, resultIndex)) { return null; } return presentation; } } for (const presentation of this.orderedPresentations) { if ( (presentation.dataFormat === undefined || presentation.dataFormat === dataFormat) && presentation.type === type && !presentation.hidden?.(dataFormat, model, resultIndex) ) { return presentation; } } return null; } add(options: IDataPresentationOptions): void { this.dataPresentations.set(options.id, { ...options, type: options.type || DataPresentationType.main, order: options.order || Number.MAX_SAFE_INTEGER, }); } }