mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-28 06:04:25 +00:00
Compare commits
1 Commits
users/saks
...
users/saks
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c9dea0913 |
@@ -16,7 +16,7 @@ import {
|
||||
import { useIndexingPolicyStore } from "Explorer/Tabs/QueryTab/ResultsView";
|
||||
import { useDatabases } from "Explorer/useDatabases";
|
||||
import { isFabricNative } from "Platform/Fabric/FabricUtil";
|
||||
import { isVectorSearchEnabled } from "Utils/CapabilityUtils";
|
||||
import { isCapabilityEnabled, isVectorSearchEnabled } from "Utils/CapabilityUtils";
|
||||
import { isRunningOnPublicCloud } from "Utils/CloudUtils";
|
||||
import * as React from "react";
|
||||
import DiscardIcon from "../../../../images/discard.svg";
|
||||
@@ -70,7 +70,6 @@ import {
|
||||
getMongoNotification,
|
||||
getTabTitle,
|
||||
hasDatabaseSharedThroughput,
|
||||
isDataMaskingEnabled,
|
||||
isDirty,
|
||||
parseConflictResolutionMode,
|
||||
parseConflictResolutionProcedure,
|
||||
@@ -1074,8 +1073,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
|
||||
|
||||
newCollection.fullTextPolicy = this.state.fullTextPolicy;
|
||||
|
||||
// Only send data masking policy if it was modified (dirty) and data masking is enabled
|
||||
if (this.state.isDataMaskingDirty && isDataMaskingEnabled(this.collection.dataMaskingPolicy?.())) {
|
||||
// Only send data masking policy if it was modified (dirty)
|
||||
if (this.state.isDataMaskingDirty && isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking)) {
|
||||
newCollection.dataMaskingPolicy = this.state.dataMaskingContent;
|
||||
}
|
||||
|
||||
@@ -1464,7 +1463,15 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
|
||||
});
|
||||
}
|
||||
|
||||
if (isDataMaskingEnabled(this.collection.dataMaskingPolicy?.())) {
|
||||
// Check if DDM should be enabled
|
||||
const shouldEnableDDM = (): boolean => {
|
||||
const hasDataMaskingCapability = isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking);
|
||||
const isSqlAccount = userContext.apiType === "SQL";
|
||||
|
||||
return isSqlAccount && hasDataMaskingCapability; // Only show for SQL accounts with DDM capability
|
||||
};
|
||||
|
||||
if (shouldEnableDDM()) {
|
||||
const dataMaskingComponentProps: DataMaskingComponentProps = {
|
||||
shouldDiscardDataMasking: this.state.shouldDiscardDataMasking,
|
||||
resetShouldDiscardDataMasking: this.resetShouldDiscardDataMasking,
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { MessageBar, MessageBarType, Stack } from "@fluentui/react";
|
||||
import * as monaco from "monaco-editor";
|
||||
import * as React from "react";
|
||||
import * as Constants from "../../../../Common/Constants";
|
||||
import * as DataModels from "../../../../Contracts/DataModels";
|
||||
import { isCapabilityEnabled } from "../../../../Utils/CapabilityUtils";
|
||||
import { loadMonaco } from "../../../LazyMonaco";
|
||||
import { titleAndInputStackProps, unsavedEditorWarningMessage } from "../SettingsRenderUtils";
|
||||
import { isDataMaskingEnabled, isDirty as isContentDirty } from "../SettingsUtils";
|
||||
import { isDirty as isContentDirty } from "../SettingsUtils";
|
||||
|
||||
export interface DataMaskingComponentProps {
|
||||
shouldDiscardDataMasking: boolean;
|
||||
@@ -138,7 +140,7 @@ export class DataMaskingComponent extends React.Component<DataMaskingComponentPr
|
||||
};
|
||||
|
||||
public render(): JSX.Element {
|
||||
if (!isDataMaskingEnabled(this.props.dataMaskingContent)) {
|
||||
if (!isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ import * as Constants from "../../../Common/Constants";
|
||||
import * as DataModels from "../../../Contracts/DataModels";
|
||||
import * as ViewModels from "../../../Contracts/ViewModels";
|
||||
import { isFabricNative } from "../../../Platform/Fabric/FabricUtil";
|
||||
import { userContext } from "../../../UserContext";
|
||||
import { isCapabilityEnabled } from "../../../Utils/CapabilityUtils";
|
||||
import { MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types";
|
||||
|
||||
const zeroValue = 0;
|
||||
@@ -90,19 +88,6 @@ export const hasDatabaseSharedThroughput = (collection: ViewModels.Collection):
|
||||
return database?.isDatabaseShared() && !collection.offer();
|
||||
};
|
||||
|
||||
export const isDataMaskingEnabled = (dataMaskingPolicy?: DataModels.DataMaskingPolicy): boolean => {
|
||||
const isSqlAccount = userContext.apiType === "SQL";
|
||||
if (!isSqlAccount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const hasDataMaskingCapability = isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking);
|
||||
const hasDataMaskingPolicyFromCollection =
|
||||
dataMaskingPolicy?.includedPaths?.length > 0 || dataMaskingPolicy?.excludedPaths?.length > 0;
|
||||
|
||||
return hasDataMaskingCapability || hasDataMaskingPolicyFromCollection;
|
||||
};
|
||||
|
||||
export const parseConflictResolutionMode = (modeFromBackend: string): DataModels.ConflictResolutionMode => {
|
||||
// Backend can contain different casing as it does case-insensitive comparisson
|
||||
if (!modeFromBackend) {
|
||||
|
||||
@@ -604,60 +604,6 @@ exports[`SettingsComponent renders 1`] = `
|
||||
/>
|
||||
</Stack>
|
||||
</PivotItem>
|
||||
<PivotItem
|
||||
headerButtonProps={
|
||||
{
|
||||
"data-test": "settings-tab-header/DataMaskingTab",
|
||||
}
|
||||
}
|
||||
headerText="Masking Policy (preview)"
|
||||
itemKey="DataMaskingTab"
|
||||
key="DataMaskingTab"
|
||||
style={
|
||||
{
|
||||
"backgroundColor": "var(--colorNeutralBackground1)",
|
||||
"color": "var(--colorNeutralForeground1)",
|
||||
"marginTop": 20,
|
||||
}
|
||||
}
|
||||
>
|
||||
<Stack
|
||||
styles={
|
||||
{
|
||||
"root": {
|
||||
"backgroundColor": "var(--colorNeutralBackground1)",
|
||||
"color": "var(--colorNeutralForeground1)",
|
||||
},
|
||||
}
|
||||
}
|
||||
>
|
||||
<DataMaskingComponent
|
||||
dataMaskingContent={
|
||||
{
|
||||
"excludedPaths": [
|
||||
"/excludedPath",
|
||||
],
|
||||
"includedPaths": [],
|
||||
"isPolicyEnabled": true,
|
||||
}
|
||||
}
|
||||
dataMaskingContentBaseline={
|
||||
{
|
||||
"excludedPaths": [
|
||||
"/excludedPath",
|
||||
],
|
||||
"includedPaths": [],
|
||||
"isPolicyEnabled": true,
|
||||
}
|
||||
}
|
||||
onDataMaskingContentChange={[Function]}
|
||||
onDataMaskingDirtyChange={[Function]}
|
||||
resetShouldDiscardDataMasking={[Function]}
|
||||
shouldDiscardDataMasking={false}
|
||||
validationErrors={[]}
|
||||
/>
|
||||
</Stack>
|
||||
</PivotItem>
|
||||
<PivotItem
|
||||
headerButtonProps={
|
||||
{
|
||||
|
||||
157
test/sql/scaleAndSettings/indexingPolicy.spec.ts
Normal file
157
test/sql/scaleAndSettings/indexingPolicy.spec.ts
Normal file
@@ -0,0 +1,157 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { CommandBarButton, DataExplorer, Editor, ONE_MINUTE_MS, TestAccount } from "../../fx";
|
||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
||||
|
||||
test.describe("Indexing Policy under Scale & Settings", () => {
|
||||
let context: TestContainerContext = null!;
|
||||
let explorer: DataExplorer = null!;
|
||||
|
||||
// Helper function to get the indexing policy editor
|
||||
const getIndexingPolicyEditor = (): Editor => {
|
||||
const editorContainer = explorer.frame.locator(".settingsV2Editor");
|
||||
return new Editor(explorer.frame, editorContainer);
|
||||
};
|
||||
|
||||
test.beforeAll("Create Test Database & Open Indexing Policy tab", async ({ browser }) => {
|
||||
context = await createTestSQLContainer();
|
||||
const page = await browser.newPage();
|
||||
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
||||
|
||||
// Click Scale & Settings and open Indexing Policy tab
|
||||
await explorer.openScaleAndSettings(context);
|
||||
const indexingPolicyTab = explorer.frame.getByTestId("settings-tab-header/IndexingPolicyTab");
|
||||
await indexingPolicyTab.click();
|
||||
});
|
||||
|
||||
test.afterAll("Delete Test Database", async () => {
|
||||
await context?.dispose();
|
||||
});
|
||||
|
||||
test("Verify Indexing Policy tab is visible", async () => {
|
||||
const indexingPolicyTab = explorer.frame.getByTestId("settings-tab-header/IndexingPolicyTab");
|
||||
await expect(indexingPolicyTab).toBeVisible();
|
||||
});
|
||||
|
||||
test("Verify Indexing Policy editor is present", async () => {
|
||||
// The Monaco editor is rendered in a div with class settingsV2Editor
|
||||
const editorContainer = explorer.frame.locator(".settingsV2Editor");
|
||||
await expect(editorContainer).toBeVisible();
|
||||
|
||||
// Verify the editor has content (default indexing policy) using Editor helper
|
||||
const editor = getIndexingPolicyEditor();
|
||||
const editorContent = await editor.text();
|
||||
expect(editorContent).toBeTruthy();
|
||||
});
|
||||
|
||||
test("Update Indexing Policy - Change automatic to false", async () => {
|
||||
// Use helper function to get editor instance
|
||||
const editor = getIndexingPolicyEditor();
|
||||
|
||||
// Verify the Monaco editor is visible
|
||||
const editorElement = explorer.frame.locator(".settingsV2Editor").locator(".monaco-editor");
|
||||
await expect(editorElement).toBeVisible();
|
||||
|
||||
// Get current indexing policy content
|
||||
const currentContent = await editor.text();
|
||||
expect(currentContent).toBeTruthy();
|
||||
const indexingPolicy = JSON.parse(currentContent as string);
|
||||
|
||||
// Verify default policy structure
|
||||
expect(indexingPolicy).toHaveProperty("automatic");
|
||||
expect(indexingPolicy).toHaveProperty("indexingMode");
|
||||
|
||||
// Modify the indexing policy - change automatic to false
|
||||
indexingPolicy.automatic = false;
|
||||
const updatedContent = JSON.stringify(indexingPolicy, null, 4);
|
||||
|
||||
// Set the new content in the editor
|
||||
await editor.setText(updatedContent);
|
||||
|
||||
// Verify the warning message appears for unsaved changes
|
||||
const warningMessage = explorer.frame.locator(".ms-MessageBar--warning");
|
||||
await expect(warningMessage).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Save the changes
|
||||
await explorer.commandBarButton(CommandBarButton.Save).click();
|
||||
|
||||
// Verify success message
|
||||
await expect(explorer.getConsoleHeaderStatus()).toContainText(
|
||||
`Successfully updated container ${context.container.id}`,
|
||||
{
|
||||
timeout: 2 * ONE_MINUTE_MS,
|
||||
},
|
||||
);
|
||||
|
||||
// Verify warning message is no longer visible after save
|
||||
await expect(warningMessage).not.toBeVisible({ timeout: 5000 });
|
||||
});
|
||||
|
||||
test("Update Indexing Policy - Change indexingMode to lazy", async () => {
|
||||
// Use helper function to get editor instance
|
||||
const editor = getIndexingPolicyEditor();
|
||||
|
||||
// Verify the Monaco editor is visible
|
||||
const editorElement = explorer.frame.locator(".settingsV2Editor").locator(".monaco-editor");
|
||||
await expect(editorElement).toBeVisible();
|
||||
|
||||
// Get current indexing policy content
|
||||
const currentContent = await editor.text();
|
||||
expect(currentContent).toBeTruthy();
|
||||
const indexingPolicy = JSON.parse(currentContent as string);
|
||||
|
||||
// Modify the indexing policy - change indexingMode to lazy
|
||||
indexingPolicy.indexingMode = "lazy";
|
||||
const updatedContent = JSON.stringify(indexingPolicy, null, 4);
|
||||
|
||||
// Set the new content in the editor
|
||||
await editor.setText(updatedContent);
|
||||
|
||||
// Verify the warning message appears
|
||||
const warningMessage = explorer.frame.locator(".ms-MessageBar--warning");
|
||||
await expect(warningMessage).toBeVisible({ timeout: 5000 });
|
||||
|
||||
// Save the changes
|
||||
await explorer.commandBarButton(CommandBarButton.Save).click();
|
||||
|
||||
// Verify success message
|
||||
await expect(explorer.getConsoleHeaderStatus()).toContainText(
|
||||
`Successfully updated container ${context.container.id}`,
|
||||
{
|
||||
timeout: 2 * ONE_MINUTE_MS,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test("Update Indexing Policy - Revert automatic to true", async () => {
|
||||
// Use helper function to get editor instance
|
||||
const editor = getIndexingPolicyEditor();
|
||||
|
||||
// Verify the Monaco editor is visible
|
||||
const editorElement = explorer.frame.locator(".settingsV2Editor").locator(".monaco-editor");
|
||||
await expect(editorElement).toBeVisible();
|
||||
|
||||
// Get current indexing policy content
|
||||
const currentContent = await editor.text();
|
||||
expect(currentContent).toBeTruthy();
|
||||
const indexingPolicy = JSON.parse(currentContent as string);
|
||||
|
||||
// Revert the changes - set automatic back to true and indexingMode to consistent
|
||||
indexingPolicy.automatic = true;
|
||||
indexingPolicy.indexingMode = "consistent";
|
||||
const updatedContent = JSON.stringify(indexingPolicy, null, 4);
|
||||
|
||||
// Set the new content in the editor
|
||||
await editor.setText(updatedContent);
|
||||
|
||||
// Save the changes
|
||||
await explorer.commandBarButton(CommandBarButton.Save).click();
|
||||
|
||||
// Verify success message
|
||||
await expect(explorer.getConsoleHeaderStatus()).toContainText(
|
||||
`Successfully updated container ${context.container.id}`,
|
||||
{
|
||||
timeout: 2 * ONE_MINUTE_MS,
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user