Move Explorer._refreshNotebooksEnabledStateForAccount into React

This commit is contained in:
sunilyadav840
2021-04-29 17:51:05 +05:30
parent 531df811da
commit b8ed534c90
7 changed files with 69 additions and 64 deletions

View File

@@ -223,7 +223,6 @@ exports[`SettingsComponent renders 1`] = `
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -464,7 +463,7 @@ exports[`SettingsComponent renders 1`] = `
"isSchemaEnabled": [Function], "isSchemaEnabled": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -481,6 +480,7 @@ exports[`SettingsComponent renders 1`] = `
}, },
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],
@@ -738,7 +738,6 @@ exports[`SettingsComponent renders 1`] = `
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -979,7 +978,7 @@ exports[`SettingsComponent renders 1`] = `
"isSchemaEnabled": [Function], "isSchemaEnabled": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -996,6 +995,7 @@ exports[`SettingsComponent renders 1`] = `
}, },
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],
@@ -1266,7 +1266,6 @@ exports[`SettingsComponent renders 1`] = `
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -1507,7 +1506,7 @@ exports[`SettingsComponent renders 1`] = `
"isSchemaEnabled": [Function], "isSchemaEnabled": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -1524,6 +1523,7 @@ exports[`SettingsComponent renders 1`] = `
}, },
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],
@@ -1781,7 +1781,6 @@ exports[`SettingsComponent renders 1`] = `
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -2022,7 +2021,7 @@ exports[`SettingsComponent renders 1`] = `
"isSchemaEnabled": [Function], "isSchemaEnabled": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -2039,6 +2038,7 @@ exports[`SettingsComponent renders 1`] = `
}, },
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],

View File

@@ -94,6 +94,8 @@ export interface ExplorerParams {
closeDialog: () => void; closeDialog: () => void;
openDialog: (props: DialogProps) => void; openDialog: (props: DialogProps) => void;
tabsManager: TabsManager; tabsManager: TabsManager;
refreshSparkEnabledStateForAccount: () => void;
isSparkEnabledForAccount: boolean;
} }
export default class Explorer { export default class Explorer {
@@ -186,7 +188,6 @@ export default class Explorer {
public notebookWorkspaceManager: NotebookWorkspaceManager; public notebookWorkspaceManager: NotebookWorkspaceManager;
public sparkClusterConnectionInfo: ko.Observable<DataModels.SparkClusterConnectionInfo>; public sparkClusterConnectionInfo: ko.Observable<DataModels.SparkClusterConnectionInfo>;
public isSparkEnabled: ko.Observable<boolean>; public isSparkEnabled: ko.Observable<boolean>;
public isSparkEnabledForAccount: ko.Observable<boolean>;
public arcadiaToken: ko.Observable<string>; public arcadiaToken: ko.Observable<string>;
public arcadiaWorkspaces: ko.ObservableArray<ArcadiaWorkspaceItem>; public arcadiaWorkspaces: ko.ObservableArray<ArcadiaWorkspaceItem>;
public hasStorageAnalyticsAfecFeature: ko.Observable<boolean>; public hasStorageAnalyticsAfecFeature: ko.Observable<boolean>;
@@ -205,6 +206,10 @@ export default class Explorer {
content: string; content: string;
}; };
// Refresh spark
public refreshSparkEnabledStateForAccount: () => void;
public isSparkEnabledForAccount: boolean;
// React adapters // React adapters
private commandBarComponentAdapter: CommandBarComponentAdapter; private commandBarComponentAdapter: CommandBarComponentAdapter;
@@ -218,6 +223,8 @@ export default class Explorer {
this.closeSidePanel = params?.closeSidePanel; this.closeSidePanel = params?.closeSidePanel;
this.closeDialog = params?.closeDialog; this.closeDialog = params?.closeDialog;
this.openDialog = params?.openDialog; this.openDialog = params?.openDialog;
this.refreshSparkEnabledStateForAccount = params?.refreshSparkEnabledStateForAccount;
this.isSparkEnabledForAccount = params?.isSparkEnabledForAccount;
const startKey: number = TelemetryProcessor.traceStart(Action.InitializeDataExplorer, { const startKey: number = TelemetryProcessor.traceStart(Action.InitializeDataExplorer, {
dataExplorerArea: Constants.Areas.ResourceTree, dataExplorerArea: Constants.Areas.ResourceTree,
@@ -244,8 +251,7 @@ export default class Explorer {
}); });
this.isNotebooksEnabledForAccount = ko.observable(false); this.isNotebooksEnabledForAccount = ko.observable(false);
this.isNotebooksEnabledForAccount.subscribe((isEnabledForAccount: boolean) => this.refreshCommandBarButtons()); this.isNotebooksEnabledForAccount.subscribe((isEnabledForAccount: boolean) => this.refreshCommandBarButtons());
this.isSparkEnabledForAccount = ko.observable(false); // this.isSparkEnabledForAccount.subscribe((isEnabledForAccount: boolean) => this.refreshCommandBarButtons());
this.isSparkEnabledForAccount.subscribe((isEnabledForAccount: boolean) => this.refreshCommandBarButtons());
this.hasStorageAnalyticsAfecFeature = ko.observable(false); this.hasStorageAnalyticsAfecFeature = ko.observable(false);
this.hasStorageAnalyticsAfecFeature.subscribe((enabled: boolean) => this.refreshCommandBarButtons()); this.hasStorageAnalyticsAfecFeature.subscribe((enabled: boolean) => this.refreshCommandBarButtons());
this.isSynapseLinkUpdating = ko.observable<boolean>(false); this.isSynapseLinkUpdating = ko.observable<boolean>(false);
@@ -261,7 +267,7 @@ export default class Explorer {
this._isAfecFeatureRegistered(Constants.AfecFeatures.StorageAnalytics).then((isRegistered) => this._isAfecFeatureRegistered(Constants.AfecFeatures.StorageAnalytics).then((isRegistered) =>
this.hasStorageAnalyticsAfecFeature(isRegistered) this.hasStorageAnalyticsAfecFeature(isRegistered)
); );
Promise.all([this._refreshNotebooksEnabledStateForAccount(), this._refreshSparkEnabledStateForAccount()]).then( Promise.all([this._refreshNotebooksEnabledStateForAccount(), this.refreshSparkEnabledStateForAccount()]).then(
async () => { async () => {
this.isNotebookEnabled( this.isNotebookEnabled(
userContext.authType !== AuthType.ResourceToken && userContext.authType !== AuthType.ResourceToken &&
@@ -284,7 +290,7 @@ export default class Explorer {
this.isSparkEnabled( this.isSparkEnabled(
(this.isNotebookEnabled() && (this.isNotebookEnabled() &&
this.isSparkEnabledForAccount() && this.isSparkEnabledForAccount &&
this.arcadiaWorkspaces() && this.arcadiaWorkspaces() &&
this.arcadiaWorkspaces().length > 0) || this.arcadiaWorkspaces().length > 0) ||
userContext.features.enableSpark userContext.features.enableSpark
@@ -372,16 +378,6 @@ export default class Explorer {
direction: SplitterDirection.Vertical, direction: SplitterDirection.Vertical,
}); });
this.defaultExperience = ko.observable<string>(); this.defaultExperience = ko.observable<string>();
// this.databaseAccount.subscribe((databaseAccount) => {
// const defaultExperience: string = DefaultExperienceUtility.getDefaultExperienceFromDatabaseAccount(
// databaseAccount
// );
// this.defaultExperience(defaultExperience);
// // TODO. Remove this entirely
// updateUserContext({
// apiType: DefaultExperienceUtility.mapDefaultExperienceStringToEnum(defaultExperience),
// });
// });
this.isFixedCollectionWithSharedThroughputSupported = ko.computed(() => { this.isFixedCollectionWithSharedThroughputSupported = ko.computed(() => {
if (userContext.features.enableFixedCollectionWithSharedThroughput) { if (userContext.features.enableFixedCollectionWithSharedThroughput) {
@@ -1659,35 +1655,6 @@ export default class Explorer {
} }
} }
public _refreshSparkEnabledStateForAccount = async (): Promise<void> => {
const subscriptionId = userContext.subscriptionId;
const armEndpoint = configContext.ARM_ENDPOINT;
const authType = userContext.authType;
if (!subscriptionId || !armEndpoint || authType === AuthType.EncryptedToken) {
// explorer is not aware of the database account yet
this.isSparkEnabledForAccount(false);
return;
}
const featureUri = `subscriptions/${subscriptionId}/providers/Microsoft.Features/providers/Microsoft.DocumentDb/features/${Constants.AfecFeatures.Spark}`;
const resourceProviderClient = new ResourceProviderClientFactory().getOrCreate(featureUri);
try {
const sparkNotebooksFeature: DataModels.AfecFeature = await resourceProviderClient.getAsync(
featureUri,
Constants.ArmApiVersions.armFeatures
);
const isEnabled =
(sparkNotebooksFeature &&
sparkNotebooksFeature.properties &&
sparkNotebooksFeature.properties.state === "Registered") ||
false;
this.isSparkEnabledForAccount(isEnabled);
} catch (error) {
Logger.logError(getErrorMessage(error), "Explorer/isSparkEnabledForAccount");
this.isSparkEnabledForAccount(false);
}
};
public _isAfecFeatureRegistered = async (featureName: string): Promise<boolean> => { public _isAfecFeatureRegistered = async (featureName: string): Promise<boolean> => {
const subscriptionId = userContext.subscriptionId; const subscriptionId = userContext.subscriptionId;
const armEndpoint = configContext.ARM_ENDPOINT; const armEndpoint = configContext.ARM_ENDPOINT;

View File

@@ -199,7 +199,6 @@ exports[`Settings Pane should render Default properly 1`] = `
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -440,7 +439,7 @@ exports[`Settings Pane should render Default properly 1`] = `
"isSchemaEnabled": [Function], "isSchemaEnabled": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -457,6 +456,7 @@ exports[`Settings Pane should render Default properly 1`] = `
}, },
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],
@@ -837,7 +837,6 @@ exports[`Settings Pane should render Gremlin properly 1`] = `
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -1078,7 +1077,7 @@ exports[`Settings Pane should render Gremlin properly 1`] = `
"isSchemaEnabled": [Function], "isSchemaEnabled": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -1095,6 +1094,7 @@ exports[`Settings Pane should render Gremlin properly 1`] = `
}, },
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],

View File

@@ -202,7 +202,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = `
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -443,7 +442,7 @@ exports[`StringInput Pane should render Create new directory properly 1`] = `
"isSchemaEnabled": [Function], "isSchemaEnabled": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -460,6 +459,7 @@ exports[`StringInput Pane should render Create new directory properly 1`] = `
}, },
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],
@@ -716,7 +716,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = `
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -957,7 +956,7 @@ exports[`StringInput Pane should render Create new directory properly 1`] = `
"isSchemaEnabled": [Function], "isSchemaEnabled": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -974,6 +973,7 @@ exports[`StringInput Pane should render Create new directory properly 1`] = `
}, },
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],

View File

@@ -199,7 +199,6 @@ exports[`Upload Items Pane should render Default properly 1`] = `
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -440,7 +439,7 @@ exports[`Upload Items Pane should render Default properly 1`] = `
"isSchemaEnabled": [Function], "isSchemaEnabled": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -457,6 +456,7 @@ exports[`Upload Items Pane should render Default properly 1`] = `
}, },
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],

View File

@@ -200,7 +200,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database
"visible": [Function], "visible": [Function],
}, },
], ],
"_refreshSparkEnabledStateForAccount": [Function],
"_resetNotebookWorkspace": [Function], "_resetNotebookWorkspace": [Function],
"addCollectionPane": AddCollectionPane { "addCollectionPane": AddCollectionPane {
"_isSynapseLinkEnabled": [Function], "_isSynapseLinkEnabled": [Function],
@@ -444,7 +443,7 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database
"isSelectedDatabaseShared": [Function], "isSelectedDatabaseShared": [Function],
"isServerlessEnabled": [Function], "isServerlessEnabled": [Function],
"isSparkEnabled": [Function], "isSparkEnabled": [Function],
"isSparkEnabledForAccount": [Function], "isSparkEnabledForAccount": undefined,
"isSynapseLinkUpdating": [Function], "isSynapseLinkUpdating": [Function],
"isTabsContentExpanded": [Function], "isTabsContentExpanded": [Function],
"memoryUsageInfo": [Function], "memoryUsageInfo": [Function],
@@ -462,6 +461,7 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database
"refreshAllDatabases": [Function], "refreshAllDatabases": [Function],
"refreshDatabaseAccount": [Function], "refreshDatabaseAccount": [Function],
"refreshNotebookList": [Function], "refreshNotebookList": [Function],
"refreshSparkEnabledStateForAccount": undefined,
"refreshTreeTitle": [Function], "refreshTreeTitle": [Function],
"resourceTokenCollection": [Function], "resourceTokenCollection": [Function],
"resourceTokenCollectionId": [Function], "resourceTokenCollectionId": [Function],

View File

@@ -28,6 +28,11 @@ import "../less/TableStyles/fulldatatables.less";
import "../less/TableStyles/queryBuilder.less"; import "../less/TableStyles/queryBuilder.less";
import "../less/tree.less"; import "../less/tree.less";
import { AuthType } from "./AuthType"; import { AuthType } from "./AuthType";
import { AfecFeatures, ArmApiVersions } from "./Common/Constants";
import { getErrorMessage } from "./Common/ErrorHandlingUtils";
import { logError } from "./Common/Logger";
import { configContext } from "./ConfigContext";
import { AfecFeature } from "./Contracts/DataModels";
import "./Explorer/Controls/Accordion/AccordionComponent.less"; import "./Explorer/Controls/Accordion/AccordionComponent.less";
import "./Explorer/Controls/CollapsiblePanel/CollapsiblePanelComponent.less"; import "./Explorer/Controls/CollapsiblePanel/CollapsiblePanelComponent.less";
import { Dialog, DialogProps } from "./Explorer/Controls/Dialog"; import { Dialog, DialogProps } from "./Explorer/Controls/Dialog";
@@ -55,6 +60,7 @@ import { useSidePanel } from "./hooks/useSidePanel";
import { useTabs } from "./hooks/useTabs"; import { useTabs } from "./hooks/useTabs";
import { KOCommentEnd, KOCommentIfStart } from "./koComment"; import { KOCommentEnd, KOCommentIfStart } from "./koComment";
import "./Libs/jquery"; import "./Libs/jquery";
import { ResourceProviderClientFactory } from "./ResourceProvider/ResourceProviderClientFactory";
import "./Shared/appInsights"; import "./Shared/appInsights";
import { userContext } from "./UserContext"; import { userContext } from "./UserContext";
@@ -68,6 +74,36 @@ const App: React.FunctionComponent = () => {
const [dialogProps, setDialogProps] = useState<DialogProps>(); const [dialogProps, setDialogProps] = useState<DialogProps>();
const [showDialog, setShowDialog] = useState<boolean>(false); const [showDialog, setShowDialog] = useState<boolean>(false);
const [isSparkEnabledForAccount, setIsSparkEnabledForAccount] = useState<boolean>(false);
const refreshSparkEnabledStateForAccount = async (): Promise<void> => {
const subscriptionId = userContext.subscriptionId;
const armEndpoint = configContext.ARM_ENDPOINT;
const authType = userContext.authType;
if (!subscriptionId || !armEndpoint || authType === AuthType.EncryptedToken) {
// explorer is not aware of the database account yet
setIsSparkEnabledForAccount(false);
return;
}
const featureUri = `subscriptions/${subscriptionId}/providers/Microsoft.Features/providers/Microsoft.DocumentDb/features/${AfecFeatures.Spark}`;
const resourceProviderClient = new ResourceProviderClientFactory().getOrCreate(featureUri);
try {
const sparkNotebooksFeature: AfecFeature = await resourceProviderClient.getAsync(
featureUri,
ArmApiVersions.armFeatures
);
const isEnabled =
(sparkNotebooksFeature &&
sparkNotebooksFeature.properties &&
sparkNotebooksFeature.properties.state === "Registered") ||
false;
setIsSparkEnabledForAccount(isEnabled);
} catch (error) {
logError(getErrorMessage(error), "Explorer/isSparkEnabledForAccount");
setIsSparkEnabledForAccount(false);
}
};
const openDialog = (props: DialogProps) => { const openDialog = (props: DialogProps) => {
setDialogProps(props); setDialogProps(props);
@@ -89,6 +125,8 @@ const App: React.FunctionComponent = () => {
openDialog, openDialog,
closeDialog, closeDialog,
tabsManager, tabsManager,
refreshSparkEnabledStateForAccount,
isSparkEnabledForAccount,
}; };
const config = useConfig(); const config = useConfig();