From b1faf76b4fc203033ff6418a832adbc0c6e43a67 Mon Sep 17 00:00:00 2001 From: Wroud Date: Fri, 19 Mar 2021 13:19:40 +0300 Subject: [PATCH] fix(plugin-data-viewer): CB-751 hide empty value panel --- .../plugin-data-viewer/src/DataPresentationService.ts | 10 +++++++--- .../TablePresentationBar/TablePresentationBar.tsx | 10 +++++++++- .../plugin-data-viewer/src/TableViewer/TableViewer.tsx | 2 ++ .../TableViewer/ValuePanel/DataValuePanelService.ts | 7 ++++++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/webapp/packages/plugin-data-viewer/src/DataPresentationService.ts b/webapp/packages/plugin-data-viewer/src/DataPresentationService.ts index a05e63832f..7c888c1f50 100644 --- a/webapp/packages/plugin-data-viewer/src/DataPresentationService.ts +++ b/webapp/packages/plugin-data-viewer/src/DataPresentationService.ts @@ -74,17 +74,18 @@ export class DataPresentationService { getSupportedList( type: DataPresentationType, - dataFormat: ResultDataFormat[], + supportedDataFormats: ResultDataFormat[], + dataFormat: ResultDataFormat, model: IDatabaseDataModel, resultIndex: number, ): IDataPresentation[] { return Array.from(this.dataPresentations.values()).filter(presentation => { - if (presentation.type !== type || presentation.hidden?.(null, model, resultIndex)) { + if (presentation.type !== type || presentation.hidden?.(dataFormat, model, resultIndex)) { return false; } return presentation.dataFormat === undefined - || dataFormat.includes(presentation.dataFormat); + || supportedDataFormats.includes(presentation.dataFormat); }); } @@ -99,6 +100,9 @@ export class DataPresentationService { const presentation = this.dataPresentations.get(presentationId); if (presentation) { + if (presentation.hidden?.(dataFormat, model, resultIndex)) { + return null; + } return presentation; } } diff --git a/webapp/packages/plugin-data-viewer/src/TableViewer/TablePresentationBar/TablePresentationBar.tsx b/webapp/packages/plugin-data-viewer/src/TableViewer/TablePresentationBar/TablePresentationBar.tsx index c5b73053b4..8690c7e9cc 100644 --- a/webapp/packages/plugin-data-viewer/src/TableViewer/TablePresentationBar/TablePresentationBar.tsx +++ b/webapp/packages/plugin-data-viewer/src/TableViewer/TablePresentationBar/TablePresentationBar.tsx @@ -50,6 +50,7 @@ const styles = composes( interface Props { type: DataPresentationType; presentationId: string | null | undefined; + dataFormat: ResultDataFormat; supportedDataFormat: ResultDataFormat[]; model: IDatabaseDataModel; resultIndex: number; @@ -61,6 +62,7 @@ export const TablePresentationBar = observer(function TablePresentationBar({ type, presentationId, supportedDataFormat, + dataFormat, model, resultIndex, className, @@ -68,7 +70,13 @@ export const TablePresentationBar = observer(function TablePresentationBar({ }: Props) { const style = useStyles(styles, verticalRotatedTabStyles); const dataPresentationService = useService(DataPresentationService); - const presentations = dataPresentationService.getSupportedList(type, supportedDataFormat, model, resultIndex); + const presentations = dataPresentationService.getSupportedList( + type, + supportedDataFormat, + dataFormat, + model, + resultIndex + ); const Tab = PresentationTab; // alias for styles matching const changePresentation = ({ tabId }: ITabData) => onPresentationChange(tabId); diff --git a/webapp/packages/plugin-data-viewer/src/TableViewer/TableViewer.tsx b/webapp/packages/plugin-data-viewer/src/TableViewer/TableViewer.tsx index 7d1ef87f37..3fc790f5ba 100644 --- a/webapp/packages/plugin-data-viewer/src/TableViewer/TableViewer.tsx +++ b/webapp/packages/plugin-data-viewer/src/TableViewer/TableViewer.tsx @@ -205,6 +205,7 @@ export const TableViewer = observer(function TableViewer({ ): Array, IDataValuePanelOptions>> { - return this.tabs.getDisplayed(props); + return this.tabs.getDisplayed(props).filter( + info => ( + (props?.dataFormat === undefined || props.dataFormat === null) + || info.options?.dataFormat.includes(props.dataFormat) + ) + ); } add(tabInfo: ITabInfoOptions, IDataValuePanelOptions>): void {