mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
Handle no azdata API in data-workspace extension gracefully (#15871)
This commit is contained in:
@@ -3,23 +3,23 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import type * as azdataType from 'azdata';
|
||||
import { IDashboardColumnInfo, IDashboardTable, IProjectAction, IProjectActionGroup, IProjectProvider, WorkspaceTreeItem } from 'dataworkspace';
|
||||
import * as path from 'path';
|
||||
import * as vscode from 'vscode';
|
||||
import * as constants from '../common/constants';
|
||||
import { IconPathHelper } from '../common/iconHelper';
|
||||
import { IWorkspaceService } from '../common/interfaces';
|
||||
import { fileExist } from '../common/utils';
|
||||
import { fileExist, getAzdataApi } from '../common/utils';
|
||||
|
||||
export class ProjectDashboard {
|
||||
|
||||
private dashboard: azdata.window.ModelViewDashboard | undefined;
|
||||
private modelView: azdata.ModelView | undefined;
|
||||
private dashboard: azdataType.window.ModelViewDashboard | undefined;
|
||||
private modelView: azdataType.ModelView | undefined;
|
||||
private projectProvider: IProjectProvider | undefined;
|
||||
private overviewTab: azdata.DashboardTab | undefined;
|
||||
private rootContainer: azdata.FlexContainer | undefined;
|
||||
private tableContainer: azdata.Component | undefined;
|
||||
private overviewTab: azdataType.DashboardTab | undefined;
|
||||
private rootContainer: azdataType.FlexContainer | undefined;
|
||||
private tableContainer: azdataType.Component | undefined;
|
||||
|
||||
constructor(private _workspaceService: IWorkspaceService, private _treeItem: WorkspaceTreeItem) {
|
||||
}
|
||||
@@ -45,8 +45,8 @@ export class ProjectDashboard {
|
||||
}
|
||||
|
||||
private async createDashboard(title: string, projectFilePath: string): Promise<void> {
|
||||
this.dashboard = azdata.window.createModelViewDashboard(title, 'ProjectDashboard', { alwaysShowTabs: false });
|
||||
this.dashboard.registerTabs(async (modelView: azdata.ModelView) => {
|
||||
this.dashboard = getAzdataApi()!.window.createModelViewDashboard(title, 'ProjectDashboard', { alwaysShowTabs: false });
|
||||
this.dashboard.registerTabs(async (modelView: azdataType.ModelView) => {
|
||||
this.modelView = modelView;
|
||||
|
||||
this.overviewTab = {
|
||||
@@ -61,11 +61,11 @@ export class ProjectDashboard {
|
||||
});
|
||||
}
|
||||
|
||||
private createToolbarContainer(projectFilePath: string): azdata.ToolbarContainer {
|
||||
private createToolbarContainer(projectFilePath: string): azdataType.ToolbarContainer {
|
||||
const projectActions: (IProjectAction | IProjectActionGroup)[] = this.projectProvider!.projectToolbarActions;
|
||||
|
||||
// Add actions as buttons
|
||||
const buttons: azdata.ToolbarComponent[] = [];
|
||||
const buttons: azdataType.ToolbarComponent[] = [];
|
||||
|
||||
const projectActionsLength = projectActions.length;
|
||||
|
||||
@@ -84,7 +84,7 @@ export class ProjectDashboard {
|
||||
});
|
||||
|
||||
const refreshButton = this.modelView!.modelBuilder.button()
|
||||
.withProperties<azdata.ButtonProperties>({
|
||||
.withProperties<azdataType.ButtonProperties>({
|
||||
label: constants.Refresh,
|
||||
iconPath: IconPathHelper.refresh,
|
||||
height: '20px'
|
||||
@@ -108,9 +108,9 @@ export class ProjectDashboard {
|
||||
return obj.id !== undefined;
|
||||
}
|
||||
|
||||
private createButton(projectAction: IProjectAction): azdata.ButtonComponent {
|
||||
private createButton(projectAction: IProjectAction): azdataType.ButtonComponent {
|
||||
let button = this.modelView!.modelBuilder.button()
|
||||
.withProperties<azdata.ButtonProperties>({
|
||||
.withProperties<azdataType.ButtonProperties>({
|
||||
label: projectAction.id,
|
||||
iconPath: projectAction.icon,
|
||||
height: '20px'
|
||||
@@ -123,7 +123,7 @@ export class ProjectDashboard {
|
||||
return button;
|
||||
}
|
||||
|
||||
private createContainer(title: string, projectFilePath: string): azdata.FlexContainer {
|
||||
private createContainer(title: string, projectFilePath: string): azdataType.FlexContainer {
|
||||
this.rootContainer = this.modelView!.modelBuilder.flexContainer().withLayout(
|
||||
{
|
||||
flexFlow: 'column',
|
||||
@@ -143,7 +143,7 @@ export class ProjectDashboard {
|
||||
/**
|
||||
* Create header with title, location and background
|
||||
*/
|
||||
private createHeader(title: string, location: string): azdata.Component {
|
||||
private createHeader(title: string, location: string): azdataType.Component {
|
||||
const headerContainer = this.modelView!.modelBuilder.flexContainer().withLayout(
|
||||
{
|
||||
flexFlow: 'column',
|
||||
@@ -159,13 +159,13 @@ export class ProjectDashboard {
|
||||
}).component();
|
||||
|
||||
const titleLabel = this.modelView!.modelBuilder.text()
|
||||
.withProperties<azdata.TextComponentProperties>({ value: title, CSSStyles: { 'margin-block-start': '20px', 'margin-block-end': '0px' } })
|
||||
.withProperties<azdataType.TextComponentProperties>({ value: title, CSSStyles: { 'margin-block-start': '20px', 'margin-block-end': '0px' } })
|
||||
.component();
|
||||
header.addItem(titleLabel, { CSSStyles: { 'padding-left': '34px', 'padding-top': '15px', 'font-size': '36px', 'font-weight': '400' } });
|
||||
|
||||
const projectFolderPath = path.dirname(location);
|
||||
const locationLabel = this.modelView!.modelBuilder.text()
|
||||
.withProperties<azdata.TextComponentProperties>({ value: projectFolderPath, CSSStyles: { 'margin-block-start': '20px', 'margin-block-end': '0px' } })
|
||||
.withProperties<azdataType.TextComponentProperties>({ value: projectFolderPath, CSSStyles: { 'margin-block-start': '20px', 'margin-block-end': '0px' } })
|
||||
.component();
|
||||
header.addItem(locationLabel, { CSSStyles: { 'padding-left': '34px', 'padding-top': '15px', 'padding-bottom': '50px', 'font-size': '16px' } });
|
||||
|
||||
@@ -188,7 +188,7 @@ export class ProjectDashboard {
|
||||
/**
|
||||
* Adds all the tables to the container
|
||||
*/
|
||||
private createTables(projectFile: string): azdata.Component {
|
||||
private createTables(projectFile: string): azdataType.Component {
|
||||
const dashboardData: IDashboardTable[] = this.projectProvider!.getDashboardComponents(projectFile);
|
||||
|
||||
const tableContainer = this.modelView!.modelBuilder.flexContainer().withLayout(
|
||||
@@ -200,22 +200,22 @@ export class ProjectDashboard {
|
||||
|
||||
dashboardData.forEach(info => {
|
||||
const tableNameLabel = this.modelView!.modelBuilder.text()
|
||||
.withProperties<azdata.TextComponentProperties>({ value: info.name, CSSStyles: { 'margin-block-start': '30px', 'margin-block-end': '0px' } })
|
||||
.withProperties<azdataType.TextComponentProperties>({ value: info.name, CSSStyles: { 'margin-block-start': '30px', 'margin-block-end': '0px' } })
|
||||
.component();
|
||||
tableContainer.addItem(tableNameLabel, { CSSStyles: { 'padding-left': '25px', 'padding-bottom': '20px', ...constants.cssStyles.title } });
|
||||
|
||||
if (info.data.length === 0) {
|
||||
const noDataText = constants.noPreviousData(info.name.toLocaleLowerCase());
|
||||
const noDataLabel = this.modelView!.modelBuilder.text()
|
||||
.withProperties<azdata.TextComponentProperties>({ value: noDataText })
|
||||
.withProperties<azdataType.TextComponentProperties>({ value: noDataText })
|
||||
.component();
|
||||
tableContainer.addItem(noDataLabel, { CSSStyles: { 'padding-left': '25px', 'padding-bottom': '20px' } });
|
||||
} else {
|
||||
const columns: azdata.DeclarativeTableColumn[] = [];
|
||||
const columns: azdataType.DeclarativeTableColumn[] = [];
|
||||
info.columns.forEach((column: IDashboardColumnInfo) => {
|
||||
let col = {
|
||||
displayName: column.displayName,
|
||||
valueType: column.type === 'icon' ? azdata.DeclarativeDataType.component : azdata.DeclarativeDataType.string,
|
||||
valueType: column.type === 'icon' ? getAzdataApi()!.DeclarativeDataType.component : getAzdataApi()!.DeclarativeDataType.string,
|
||||
isReadOnly: true,
|
||||
width: column.width,
|
||||
headerCssStyles: {
|
||||
@@ -229,21 +229,21 @@ export class ProjectDashboard {
|
||||
columns.push(col);
|
||||
});
|
||||
|
||||
const data: azdata.DeclarativeTableCellValue[][] = [];
|
||||
const data: azdataType.DeclarativeTableCellValue[][] = [];
|
||||
info.data.forEach(values => {
|
||||
const columnValue: azdata.DeclarativeTableCellValue[] = [];
|
||||
const columnValue: azdataType.DeclarativeTableCellValue[] = [];
|
||||
values.forEach(val => {
|
||||
if (typeof val === 'string') {
|
||||
columnValue.push({ value: val });
|
||||
} else {
|
||||
const iconComponent = this.modelView!.modelBuilder.image().withProperties<azdata.ImageComponentProperties>({
|
||||
const iconComponent = this.modelView!.modelBuilder.image().withProperties<azdataType.ImageComponentProperties>({
|
||||
iconPath: val.icon,
|
||||
width: '15px',
|
||||
height: '15px',
|
||||
iconHeight: '15px',
|
||||
iconWidth: '15px'
|
||||
}).component();
|
||||
const stringComponent = this.modelView!.modelBuilder.text().withProperties<azdata.TextComponentProperties>({
|
||||
const stringComponent = this.modelView!.modelBuilder.text().withProperties<azdataType.TextComponentProperties>({
|
||||
value: val.text,
|
||||
CSSStyles: { 'margin-block-start': 'auto', 'block-size': 'auto', 'margin-block-end': '0px' }
|
||||
}).component();
|
||||
@@ -256,7 +256,7 @@ export class ProjectDashboard {
|
||||
});
|
||||
|
||||
const table = this.modelView!.modelBuilder.declarativeTable()
|
||||
.withProperties<azdata.DeclarativeTableProperties>({ columns: columns, dataValues: data, ariaLabel: info.name, CSSStyles: { 'margin-left': '30px' } }).component();
|
||||
.withProperties<azdataType.DeclarativeTableProperties>({ columns: columns, dataValues: data, ariaLabel: info.name, CSSStyles: { 'margin-left': '30px' } }).component();
|
||||
|
||||
tableContainer.addItem(table);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user