mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-27 13:44:12 +00:00
Compare commits
12 Commits
copilot/su
...
users/nish
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e1e695edad | ||
|
|
6d0d9ba68b | ||
|
|
f7d3dc198e | ||
|
|
2998f14d52 | ||
|
|
05407b3e0f | ||
|
|
703218debf | ||
|
|
f83a2c4442 | ||
|
|
2ff01c6379 | ||
|
|
31385950dd | ||
|
|
6dce2632c8 | ||
|
|
14ed7454fc | ||
|
|
387575ae46 |
4
.github/workflows/cleanup.yml
vendored
4
.github/workflows/cleanup.yml
vendored
@@ -6,8 +6,8 @@ on:
|
|||||||
# Allows you to run this workflow manually from the Actions tab
|
# Allows you to run this workflow manually from the Actions tab
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
# Once every two hours
|
# Once every day at 7 AM PST
|
||||||
- cron: "0 */2 * * *"
|
- cron: "0 13 * * *"
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
id-token: write
|
id-token: write
|
||||||
|
|||||||
@@ -7,16 +7,27 @@ import { HttpStatusCodes } from "./Constants";
|
|||||||
import { logError } from "./Logger";
|
import { logError } from "./Logger";
|
||||||
import { sendMessage } from "./MessageHandler";
|
import { sendMessage } from "./MessageHandler";
|
||||||
|
|
||||||
export const handleError = (error: string | ARMError | Error, area: string, consoleErrorPrefix?: string): void => {
|
export interface HandleErrorOptions {
|
||||||
|
/** Optional redacted error to use for telemetry logging instead of the original error */
|
||||||
|
redactedError?: string | ARMError | Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const handleError = (
|
||||||
|
error: string | ARMError | Error,
|
||||||
|
area: string,
|
||||||
|
consoleErrorPrefix?: string,
|
||||||
|
options?: HandleErrorOptions,
|
||||||
|
): void => {
|
||||||
const errorMessage = getErrorMessage(error);
|
const errorMessage = getErrorMessage(error);
|
||||||
const errorCode = error instanceof ARMError ? error.code : undefined;
|
const errorCode = error instanceof ARMError ? error.code : undefined;
|
||||||
|
|
||||||
// logs error to data explorer console
|
// logs error to data explorer console (always shows original, non-redacted message)
|
||||||
const consoleErrorMessage = consoleErrorPrefix ? `${consoleErrorPrefix}:\n ${errorMessage}` : errorMessage;
|
const consoleErrorMessage = consoleErrorPrefix ? `${consoleErrorPrefix}:\n ${errorMessage}` : errorMessage;
|
||||||
logConsoleError(consoleErrorMessage);
|
logConsoleError(consoleErrorMessage);
|
||||||
|
|
||||||
// logs error to both app insight and kusto
|
// logs error to both app insight and kusto (use redacted message if provided)
|
||||||
logError(errorMessage, area, errorCode);
|
const telemetryErrorMessage = options?.redactedError ? getErrorMessage(options.redactedError) : errorMessage;
|
||||||
|
logError(telemetryErrorMessage, area, errorCode);
|
||||||
|
|
||||||
// checks for errors caused by firewall and sends them to portal to handle
|
// checks for errors caused by firewall and sends them to portal to handle
|
||||||
sendNotificationForError(errorMessage, errorCode);
|
sendNotificationForError(errorMessage, errorCode);
|
||||||
|
|||||||
72
src/Common/SearchableDropdown.styles.ts
Normal file
72
src/Common/SearchableDropdown.styles.ts
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
import { IButtonStyles, IStackStyles, ITextStyles } from "@fluentui/react";
|
||||||
|
import * as React from "react";
|
||||||
|
|
||||||
|
export const getDropdownButtonStyles = (disabled: boolean): IButtonStyles => ({
|
||||||
|
root: {
|
||||||
|
width: "100%",
|
||||||
|
height: "32px",
|
||||||
|
padding: "0 28px 0 8px",
|
||||||
|
border: "1px solid #8a8886",
|
||||||
|
background: "#fff",
|
||||||
|
color: "#323130",
|
||||||
|
textAlign: "left",
|
||||||
|
cursor: disabled ? "not-allowed" : "pointer",
|
||||||
|
position: "relative",
|
||||||
|
},
|
||||||
|
flexContainer: {
|
||||||
|
justifyContent: "flex-start",
|
||||||
|
},
|
||||||
|
label: {
|
||||||
|
fontWeight: "normal",
|
||||||
|
fontSize: "14px",
|
||||||
|
textAlign: "left",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const buttonLabelStyles: ITextStyles = {
|
||||||
|
root: {
|
||||||
|
overflow: "hidden",
|
||||||
|
textOverflow: "ellipsis",
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
display: "block",
|
||||||
|
textAlign: "left",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const chevronStyles: React.CSSProperties = {
|
||||||
|
position: "absolute",
|
||||||
|
right: "8px",
|
||||||
|
top: "50%",
|
||||||
|
transform: "translateY(-50%)",
|
||||||
|
pointerEvents: "none",
|
||||||
|
};
|
||||||
|
|
||||||
|
export const calloutContentStyles: IStackStyles = {
|
||||||
|
root: {
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const listContainerStyles: IStackStyles = {
|
||||||
|
root: {
|
||||||
|
maxHeight: "300px",
|
||||||
|
overflowY: "auto",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getItemStyles = (isSelected: boolean): React.CSSProperties => ({
|
||||||
|
padding: "8px 12px",
|
||||||
|
cursor: "pointer",
|
||||||
|
fontSize: "14px",
|
||||||
|
backgroundColor: isSelected ? "#e6e6e6" : "transparent",
|
||||||
|
textAlign: "left",
|
||||||
|
});
|
||||||
|
|
||||||
|
export const emptyMessageStyles: ITextStyles = {
|
||||||
|
root: {
|
||||||
|
padding: "8px 12px",
|
||||||
|
color: "#605e5c",
|
||||||
|
textAlign: "left",
|
||||||
|
},
|
||||||
|
};
|
||||||
200
src/Common/SearchableDropdown.test.tsx
Normal file
200
src/Common/SearchableDropdown.test.tsx
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
import { fireEvent, render, screen } from "@testing-library/react";
|
||||||
|
import "@testing-library/jest-dom";
|
||||||
|
import React from "react";
|
||||||
|
import { SearchableDropdown } from "./SearchableDropdown";
|
||||||
|
|
||||||
|
interface TestItem {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
describe("SearchableDropdown", () => {
|
||||||
|
const mockItems: TestItem[] = [
|
||||||
|
{ id: "1", name: "Item One" },
|
||||||
|
{ id: "2", name: "Item Two" },
|
||||||
|
{ id: "3", name: "Item Three" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const defaultProps = {
|
||||||
|
label: "Test Label",
|
||||||
|
items: mockItems,
|
||||||
|
selectedItem: null as TestItem | null,
|
||||||
|
onSelect: jest.fn(),
|
||||||
|
getKey: (item: TestItem) => item.id,
|
||||||
|
getDisplayText: (item: TestItem) => item.name,
|
||||||
|
placeholder: "Select an item",
|
||||||
|
filterPlaceholder: "Filter items",
|
||||||
|
className: "test-dropdown",
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should render with label and placeholder", () => {
|
||||||
|
render(<SearchableDropdown {...defaultProps} />);
|
||||||
|
expect(screen.getByText("Test Label")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Select an item")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should display selected item", () => {
|
||||||
|
const propsWithSelection = {
|
||||||
|
...defaultProps,
|
||||||
|
selectedItem: mockItems[0],
|
||||||
|
};
|
||||||
|
render(<SearchableDropdown {...propsWithSelection} />);
|
||||||
|
expect(screen.getByText("Item One")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should show 'No items found' when items array is empty", () => {
|
||||||
|
const propsWithEmptyItems = {
|
||||||
|
...defaultProps,
|
||||||
|
items: [] as TestItem[],
|
||||||
|
};
|
||||||
|
render(<SearchableDropdown {...propsWithEmptyItems} />);
|
||||||
|
expect(screen.getByText("No Test Labels Found")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should open dropdown when button is clicked", () => {
|
||||||
|
render(<SearchableDropdown {...defaultProps} />);
|
||||||
|
const button = screen.getByText("Select an item");
|
||||||
|
fireEvent.click(button);
|
||||||
|
expect(screen.getByPlaceholderText("Filter items")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should filter items based on search text", () => {
|
||||||
|
render(<SearchableDropdown {...defaultProps} />);
|
||||||
|
const button = screen.getByText("Select an item");
|
||||||
|
fireEvent.click(button);
|
||||||
|
|
||||||
|
const searchBox = screen.getByPlaceholderText("Filter items");
|
||||||
|
fireEvent.change(searchBox, { target: { value: "Two" } });
|
||||||
|
|
||||||
|
expect(screen.getByText("Item Two")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Item One")).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Item Three")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should call onSelect when an item is clicked", () => {
|
||||||
|
const onSelectMock = jest.fn();
|
||||||
|
const propsWithMock = {
|
||||||
|
...defaultProps,
|
||||||
|
onSelect: onSelectMock,
|
||||||
|
};
|
||||||
|
render(<SearchableDropdown {...propsWithMock} />);
|
||||||
|
|
||||||
|
const button = screen.getByText("Select an item");
|
||||||
|
fireEvent.click(button);
|
||||||
|
|
||||||
|
const item = screen.getByText("Item Two");
|
||||||
|
fireEvent.click(item);
|
||||||
|
|
||||||
|
expect(onSelectMock).toHaveBeenCalledWith(mockItems[1]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should close dropdown after selecting an item", () => {
|
||||||
|
render(<SearchableDropdown {...defaultProps} />);
|
||||||
|
|
||||||
|
const button = screen.getByText("Select an item");
|
||||||
|
fireEvent.click(button);
|
||||||
|
|
||||||
|
expect(screen.getByPlaceholderText("Filter items")).toBeInTheDocument();
|
||||||
|
|
||||||
|
const item = screen.getByText("Item One");
|
||||||
|
fireEvent.click(item);
|
||||||
|
|
||||||
|
expect(screen.queryByPlaceholderText("Filter items")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should disable button when disabled prop is true", () => {
|
||||||
|
const propsWithDisabled = {
|
||||||
|
...defaultProps,
|
||||||
|
disabled: true,
|
||||||
|
};
|
||||||
|
render(<SearchableDropdown {...propsWithDisabled} />);
|
||||||
|
|
||||||
|
const button = screen.getByRole("button");
|
||||||
|
expect(button).toBeDisabled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not open dropdown when disabled", () => {
|
||||||
|
const propsWithDisabled = {
|
||||||
|
...defaultProps,
|
||||||
|
disabled: true,
|
||||||
|
};
|
||||||
|
render(<SearchableDropdown {...propsWithDisabled} />);
|
||||||
|
|
||||||
|
const button = screen.getByRole("button");
|
||||||
|
fireEvent.click(button);
|
||||||
|
|
||||||
|
expect(screen.queryByPlaceholderText("Filter items")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should show 'No items found' when search yields no results", () => {
|
||||||
|
render(<SearchableDropdown {...defaultProps} />);
|
||||||
|
|
||||||
|
const button = screen.getByText("Select an item");
|
||||||
|
fireEvent.click(button);
|
||||||
|
|
||||||
|
const searchBox = screen.getByPlaceholderText("Filter items");
|
||||||
|
fireEvent.change(searchBox, { target: { value: "Nonexistent" } });
|
||||||
|
|
||||||
|
expect(screen.getByText("No items found")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle case-insensitive filtering", () => {
|
||||||
|
render(<SearchableDropdown {...defaultProps} />);
|
||||||
|
|
||||||
|
const button = screen.getByText("Select an item");
|
||||||
|
fireEvent.click(button);
|
||||||
|
|
||||||
|
const searchBox = screen.getByPlaceholderText("Filter items");
|
||||||
|
fireEvent.change(searchBox, { target: { value: "two" } });
|
||||||
|
|
||||||
|
expect(screen.getByText("Item Two")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Item One")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should clear filter text when dropdown is closed and reopened", () => {
|
||||||
|
render(<SearchableDropdown {...defaultProps} />);
|
||||||
|
|
||||||
|
const button = screen.getByText("Select an item");
|
||||||
|
fireEvent.click(button);
|
||||||
|
|
||||||
|
const searchBox = screen.getByPlaceholderText("Filter items");
|
||||||
|
fireEvent.change(searchBox, { target: { value: "Two" } });
|
||||||
|
|
||||||
|
// Close dropdown by selecting an item
|
||||||
|
const item = screen.getByText("Item Two");
|
||||||
|
fireEvent.click(item);
|
||||||
|
|
||||||
|
// Reopen dropdown
|
||||||
|
fireEvent.click(button);
|
||||||
|
|
||||||
|
// Filter text should be cleared
|
||||||
|
const reopenedSearchBox = screen.getByPlaceholderText("Filter items");
|
||||||
|
expect(reopenedSearchBox).toHaveValue("");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should use custom placeholder text", () => {
|
||||||
|
const propsWithCustomPlaceholder = {
|
||||||
|
...defaultProps,
|
||||||
|
placeholder: "Choose an option",
|
||||||
|
};
|
||||||
|
render(<SearchableDropdown {...propsWithCustomPlaceholder} />);
|
||||||
|
expect(screen.getByText("Choose an option")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should use custom filter placeholder text", () => {
|
||||||
|
const propsWithCustomFilterPlaceholder = {
|
||||||
|
...defaultProps,
|
||||||
|
filterPlaceholder: "Search here",
|
||||||
|
};
|
||||||
|
render(<SearchableDropdown {...propsWithCustomFilterPlaceholder} />);
|
||||||
|
|
||||||
|
const button = screen.getByText("Select an item");
|
||||||
|
fireEvent.click(button);
|
||||||
|
|
||||||
|
expect(screen.getByPlaceholderText("Search here")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
155
src/Common/SearchableDropdown.tsx
Normal file
155
src/Common/SearchableDropdown.tsx
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
import {
|
||||||
|
Callout,
|
||||||
|
DefaultButton,
|
||||||
|
DirectionalHint,
|
||||||
|
ISearchBoxStyles,
|
||||||
|
Label,
|
||||||
|
SearchBox,
|
||||||
|
Stack,
|
||||||
|
Text,
|
||||||
|
} from "@fluentui/react";
|
||||||
|
import * as React from "react";
|
||||||
|
import { useCallback, useMemo, useRef, useState } from "react";
|
||||||
|
import {
|
||||||
|
buttonLabelStyles,
|
||||||
|
calloutContentStyles,
|
||||||
|
chevronStyles,
|
||||||
|
emptyMessageStyles,
|
||||||
|
getDropdownButtonStyles,
|
||||||
|
getItemStyles,
|
||||||
|
listContainerStyles,
|
||||||
|
} from "./SearchableDropdown.styles";
|
||||||
|
|
||||||
|
interface SearchableDropdownProps<T> {
|
||||||
|
label: string;
|
||||||
|
items: T[];
|
||||||
|
selectedItem: T | null;
|
||||||
|
onSelect: (item: T) => void;
|
||||||
|
getKey: (item: T) => string;
|
||||||
|
getDisplayText: (item: T) => string;
|
||||||
|
placeholder?: string;
|
||||||
|
filterPlaceholder?: string;
|
||||||
|
className?: string;
|
||||||
|
disabled?: boolean;
|
||||||
|
onDismiss?: () => void;
|
||||||
|
searchBoxStyles?: Partial<ISearchBoxStyles>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const SearchableDropdown = <T,>({
|
||||||
|
label,
|
||||||
|
items,
|
||||||
|
selectedItem,
|
||||||
|
onSelect,
|
||||||
|
getKey,
|
||||||
|
getDisplayText,
|
||||||
|
placeholder = "Select an item",
|
||||||
|
filterPlaceholder = "Filter items",
|
||||||
|
className,
|
||||||
|
disabled = false,
|
||||||
|
onDismiss,
|
||||||
|
searchBoxStyles: customSearchBoxStyles,
|
||||||
|
}: SearchableDropdownProps<T>): React.ReactElement => {
|
||||||
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
|
const [filterText, setFilterText] = useState("");
|
||||||
|
const buttonRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
const closeDropdown = useCallback(() => {
|
||||||
|
setIsOpen(false);
|
||||||
|
setFilterText("");
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const filteredItems = useMemo(
|
||||||
|
() => items?.filter((item) => getDisplayText(item).toLowerCase().includes(filterText.toLowerCase())),
|
||||||
|
[items, filterText, getDisplayText],
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleDismiss = useCallback(() => {
|
||||||
|
closeDropdown();
|
||||||
|
onDismiss?.();
|
||||||
|
}, [closeDropdown, onDismiss]);
|
||||||
|
|
||||||
|
const handleButtonClick = useCallback(() => {
|
||||||
|
if (disabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsOpen(!isOpen);
|
||||||
|
}, [isOpen, disabled]);
|
||||||
|
|
||||||
|
const handleSelect = useCallback(
|
||||||
|
(item: T) => {
|
||||||
|
onSelect(item);
|
||||||
|
closeDropdown();
|
||||||
|
},
|
||||||
|
[onSelect, closeDropdown],
|
||||||
|
);
|
||||||
|
|
||||||
|
const buttonLabel = selectedItem
|
||||||
|
? getDisplayText(selectedItem)
|
||||||
|
: items?.length === 0
|
||||||
|
? `No ${label}s Found`
|
||||||
|
: placeholder;
|
||||||
|
|
||||||
|
const buttonId = `${className}-button`;
|
||||||
|
const buttonStyles = getDropdownButtonStyles(disabled);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Stack>
|
||||||
|
<Label htmlFor={buttonId}>{label}</Label>
|
||||||
|
<div ref={buttonRef}>
|
||||||
|
<DefaultButton
|
||||||
|
id={buttonId}
|
||||||
|
className={className}
|
||||||
|
onClick={handleButtonClick}
|
||||||
|
styles={buttonStyles}
|
||||||
|
disabled={disabled}
|
||||||
|
>
|
||||||
|
<Text styles={buttonLabelStyles}>{buttonLabel}</Text>
|
||||||
|
<span style={chevronStyles}>▼</span>
|
||||||
|
</DefaultButton>
|
||||||
|
</div>
|
||||||
|
{isOpen && (
|
||||||
|
<Callout
|
||||||
|
target={buttonRef.current}
|
||||||
|
onDismiss={handleDismiss}
|
||||||
|
directionalHint={DirectionalHint.bottomLeftEdge}
|
||||||
|
isBeakVisible={false}
|
||||||
|
gapSpace={0}
|
||||||
|
setInitialFocus
|
||||||
|
>
|
||||||
|
<Stack styles={calloutContentStyles} style={{ width: buttonRef.current?.offsetWidth || 300 }}>
|
||||||
|
<SearchBox
|
||||||
|
placeholder={filterPlaceholder}
|
||||||
|
value={filterText}
|
||||||
|
onChange={(_, newValue) => setFilterText(newValue || "")}
|
||||||
|
styles={customSearchBoxStyles}
|
||||||
|
/>
|
||||||
|
<Stack styles={listContainerStyles}>
|
||||||
|
{filteredItems && filteredItems.length > 0 ? (
|
||||||
|
filteredItems.map((item) => {
|
||||||
|
const key = getKey(item);
|
||||||
|
const isSelected = selectedItem ? getKey(selectedItem) === key : false;
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
key={key}
|
||||||
|
onClick={() => handleSelect(item)}
|
||||||
|
style={getItemStyles(isSelected)}
|
||||||
|
onMouseEnter={(e) => (e.currentTarget.style.backgroundColor = "#f3f2f1")}
|
||||||
|
onMouseLeave={(e) =>
|
||||||
|
(e.currentTarget.style.backgroundColor = isSelected ? "#e6e6e6" : "transparent")
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Text>{getDisplayText(item)}</Text>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})
|
||||||
|
) : (
|
||||||
|
<Text styles={emptyMessageStyles}>No items found</Text>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Callout>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -44,7 +44,8 @@ export const deleteDocuments = async (
|
|||||||
documentIds: DocumentId[],
|
documentIds: DocumentId[],
|
||||||
abortSignal: AbortSignal,
|
abortSignal: AbortSignal,
|
||||||
): Promise<IBulkDeleteResult[]> => {
|
): Promise<IBulkDeleteResult[]> => {
|
||||||
const clearMessage = logConsoleProgress(`Deleting ${documentIds.length} ${getEntityName(true)}`);
|
const totalCount = documentIds.length;
|
||||||
|
const clearMessage = logConsoleProgress(`Deleting ${totalCount} ${getEntityName(true)}`);
|
||||||
try {
|
try {
|
||||||
const v2Container = await client().database(collection.databaseId).container(collection.id());
|
const v2Container = await client().database(collection.databaseId).container(collection.id());
|
||||||
|
|
||||||
@@ -83,11 +84,7 @@ export const deleteDocuments = async (
|
|||||||
const flatAllResult = Array.prototype.concat.apply([], allResult);
|
const flatAllResult = Array.prototype.concat.apply([], allResult);
|
||||||
return flatAllResult;
|
return flatAllResult;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(
|
handleError(error, "DeleteDocuments", `Error while deleting ${totalCount} ${getEntityName(totalCount > 1)}`);
|
||||||
error,
|
|
||||||
"DeleteDocuments",
|
|
||||||
`Error while deleting ${documentIds.length} ${getEntityName(documentIds.length > 1)}`,
|
|
||||||
);
|
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
clearMessage();
|
clearMessage();
|
||||||
|
|||||||
171
src/Common/dataAccess/queryDocumentsPage.test.ts
Normal file
171
src/Common/dataAccess/queryDocumentsPage.test.ts
Normal file
@@ -0,0 +1,171 @@
|
|||||||
|
import { redactSyntaxErrorMessage } from "./queryDocumentsPage";
|
||||||
|
|
||||||
|
/* Typical error to redact looks like this (the message property contains a JSON string with nested structure):
|
||||||
|
{
|
||||||
|
"message": "{\"code\":\"BadRequest\",\"message\":\"{\\\"errors\\\":[{\\\"severity\\\":\\\"Error\\\",\\\"location\\\":{\\\"start\\\":0,\\\"end\\\":5},\\\"code\\\":\\\"SC1001\\\",\\\"message\\\":\\\"Syntax error, incorrect syntax near 'Crazy'.\\\"}]}\\r\\nActivityId: d5424e10-51bd-46f7-9aec-7b40bed36f17, Windows/10.0.20348 cosmos-netstandard-sdk/3.18.0\"}"
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Helper to create the nested error structure that matches what the SDK returns
|
||||||
|
const createNestedError = (
|
||||||
|
errors: Array<{ severity?: string; location?: { start: number; end: number }; code: string; message: string }>,
|
||||||
|
activityId: string = "test-activity-id",
|
||||||
|
): { message: string } => {
|
||||||
|
const innerErrorsJson = JSON.stringify({ errors });
|
||||||
|
const innerMessage = `${innerErrorsJson}\r\n${activityId}`;
|
||||||
|
const outerJson = JSON.stringify({ code: "BadRequest", message: innerMessage });
|
||||||
|
return { message: outerJson };
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper to parse the redacted result
|
||||||
|
const parseRedactedResult = (result: { message: string }) => {
|
||||||
|
const outerParsed = JSON.parse(result.message);
|
||||||
|
const [innerErrorsJson, activityIdPart] = outerParsed.message.split("\r\n");
|
||||||
|
const innerErrors = JSON.parse(innerErrorsJson);
|
||||||
|
return { outerParsed, innerErrors, activityIdPart };
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("redactSyntaxErrorMessage", () => {
|
||||||
|
it("should redact SC1001 error message", () => {
|
||||||
|
const error = createNestedError(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
severity: "Error",
|
||||||
|
location: { start: 0, end: 5 },
|
||||||
|
code: "SC1001",
|
||||||
|
message: "Syntax error, incorrect syntax near 'Crazy'.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"ActivityId: d5424e10-51bd-46f7-9aec-7b40bed36f17",
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as { message: string };
|
||||||
|
const { outerParsed, innerErrors, activityIdPart } = parseRedactedResult(result);
|
||||||
|
|
||||||
|
expect(outerParsed.code).toBe("BadRequest");
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
expect(activityIdPart).toContain("ActivityId: d5424e10-51bd-46f7-9aec-7b40bed36f17");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should redact SC2001 error message", () => {
|
||||||
|
const error = createNestedError(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
severity: "Error",
|
||||||
|
location: { start: 0, end: 10 },
|
||||||
|
code: "SC2001",
|
||||||
|
message: "Some sensitive syntax error message.",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"ActivityId: abc123",
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as { message: string };
|
||||||
|
const { outerParsed, innerErrors, activityIdPart } = parseRedactedResult(result);
|
||||||
|
|
||||||
|
expect(outerParsed.code).toBe("BadRequest");
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
expect(activityIdPart).toContain("ActivityId: abc123");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should redact multiple errors with SC1001 and SC2001 codes", () => {
|
||||||
|
const error = createNestedError(
|
||||||
|
[
|
||||||
|
{ severity: "Error", code: "SC1001", message: "First error" },
|
||||||
|
{ severity: "Error", code: "SC2001", message: "Second error" },
|
||||||
|
],
|
||||||
|
"ActivityId: xyz",
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as { message: string };
|
||||||
|
const { innerErrors } = parseRedactedResult(result);
|
||||||
|
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
expect(innerErrors.errors[1].message).toBe("__REDACTED__");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not redact errors with other codes", () => {
|
||||||
|
const error = createNestedError(
|
||||||
|
[{ severity: "Error", code: "SC9999", message: "This should not be redacted." }],
|
||||||
|
"ActivityId: test123",
|
||||||
|
);
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
expect(result).toBe(error); // Should return original error unchanged
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should not modify non-BadRequest errors", () => {
|
||||||
|
const innerMessage = JSON.stringify({ errors: [{ code: "SC1001", message: "Should not be redacted" }] });
|
||||||
|
const error = {
|
||||||
|
message: JSON.stringify({ code: "NotFound", message: innerMessage }),
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
expect(result).toBe(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle errors without message property", () => {
|
||||||
|
const error = { code: "BadRequest" };
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
expect(result).toBe(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle non-object errors", () => {
|
||||||
|
const stringError = "Simple string error";
|
||||||
|
const nullError: null = null;
|
||||||
|
const undefinedError: undefined = undefined;
|
||||||
|
|
||||||
|
expect(redactSyntaxErrorMessage(stringError)).toBe(stringError);
|
||||||
|
expect(redactSyntaxErrorMessage(nullError)).toBe(nullError);
|
||||||
|
expect(redactSyntaxErrorMessage(undefinedError)).toBe(undefinedError);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle malformed JSON in message", () => {
|
||||||
|
const error = {
|
||||||
|
message: "not valid json",
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
expect(result).toBe(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should handle message without ActivityId suffix", () => {
|
||||||
|
const innerErrorsJson = JSON.stringify({
|
||||||
|
errors: [{ severity: "Error", code: "SC1001", message: "Syntax error near something." }],
|
||||||
|
});
|
||||||
|
const error = {
|
||||||
|
message: JSON.stringify({ code: "BadRequest", message: innerErrorsJson + "\r\n" }),
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as { message: string };
|
||||||
|
const { innerErrors } = parseRedactedResult(result);
|
||||||
|
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should preserve other error properties", () => {
|
||||||
|
const baseError = createNestedError([{ code: "SC1001", message: "Error" }], "ActivityId: test");
|
||||||
|
const error = {
|
||||||
|
...baseError,
|
||||||
|
statusCode: 400,
|
||||||
|
additionalInfo: "extra data",
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = redactSyntaxErrorMessage(error) as {
|
||||||
|
message: string;
|
||||||
|
statusCode: number;
|
||||||
|
additionalInfo: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result.statusCode).toBe(400);
|
||||||
|
expect(result.additionalInfo).toBe("extra data");
|
||||||
|
|
||||||
|
const { innerErrors } = parseRedactedResult(result);
|
||||||
|
expect(innerErrors.errors[0].message).toBe("__REDACTED__");
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -4,6 +4,51 @@ import { getEntityName } from "../DocumentUtility";
|
|||||||
import { handleError } from "../ErrorHandlingUtils";
|
import { handleError } from "../ErrorHandlingUtils";
|
||||||
import { MinimalQueryIterator, nextPage } from "../IteratorUtilities";
|
import { MinimalQueryIterator, nextPage } from "../IteratorUtilities";
|
||||||
|
|
||||||
|
// Redact sensitive information from BadRequest errors with specific codes
|
||||||
|
export const redactSyntaxErrorMessage = (error: unknown): unknown => {
|
||||||
|
const codesToRedact = ["SC1001", "SC2001"];
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Handle error objects with a message property
|
||||||
|
if (error && typeof error === "object" && "message" in error) {
|
||||||
|
const errorObj = error as { code?: string; message?: string };
|
||||||
|
if (typeof errorObj.message === "string") {
|
||||||
|
// Parse the inner JSON from the message
|
||||||
|
const innerJson = JSON.parse(errorObj.message);
|
||||||
|
if (innerJson.code === "BadRequest" && typeof innerJson.message === "string") {
|
||||||
|
const [innerErrorsJson, activityIdPart] = innerJson.message.split("\r\n");
|
||||||
|
const innerErrorsObj = JSON.parse(innerErrorsJson);
|
||||||
|
if (Array.isArray(innerErrorsObj.errors)) {
|
||||||
|
let modified = false;
|
||||||
|
innerErrorsObj.errors = innerErrorsObj.errors.map((err: { code?: string; message?: string }) => {
|
||||||
|
if (err.code && codesToRedact.includes(err.code)) {
|
||||||
|
modified = true;
|
||||||
|
return { ...err, message: "__REDACTED__" };
|
||||||
|
}
|
||||||
|
return err;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (modified) {
|
||||||
|
// Reconstruct the message with the redacted content
|
||||||
|
const redactedMessage = JSON.stringify(innerErrorsObj) + `\r\n${activityIdPart}`;
|
||||||
|
const redactedError = {
|
||||||
|
...error,
|
||||||
|
message: JSON.stringify({ ...innerJson, message: redactedMessage }),
|
||||||
|
body: undefined as unknown, // Clear body to avoid sensitive data
|
||||||
|
};
|
||||||
|
return redactedError;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// If parsing fails, return the original error
|
||||||
|
}
|
||||||
|
|
||||||
|
return error;
|
||||||
|
};
|
||||||
|
|
||||||
export const queryDocumentsPage = async (
|
export const queryDocumentsPage = async (
|
||||||
resourceName: string,
|
resourceName: string,
|
||||||
documentsIterator: MinimalQueryIterator,
|
documentsIterator: MinimalQueryIterator,
|
||||||
@@ -18,7 +63,12 @@ export const queryDocumentsPage = async (
|
|||||||
logConsoleInfo(`Successfully fetched ${itemCount} ${entityName} for container ${resourceName}`);
|
logConsoleInfo(`Successfully fetched ${itemCount} ${entityName} for container ${resourceName}`);
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
handleError(error, "QueryDocumentsPage", `Failed to query ${entityName} for container ${resourceName}`);
|
// Redact sensitive information for telemetry while showing original in console
|
||||||
|
const redactedError = redactSyntaxErrorMessage(error);
|
||||||
|
|
||||||
|
handleError(error, "QueryDocumentsPage", `Failed to query ${entityName} for container ${resourceName}`, {
|
||||||
|
redactedError: redactedError as Error,
|
||||||
|
});
|
||||||
throw error;
|
throw error;
|
||||||
} finally {
|
} finally {
|
||||||
clearMessage();
|
clearMessage();
|
||||||
|
|||||||
@@ -11,9 +11,17 @@ jest.mock("../../Actions/CopyJobActions", () => ({
|
|||||||
|
|
||||||
jest.mock("./CopyJobColumns", () => ({
|
jest.mock("./CopyJobColumns", () => ({
|
||||||
getColumns: jest.fn(() => [
|
getColumns: jest.fn(() => [
|
||||||
|
{
|
||||||
|
key: "LastUpdatedTime",
|
||||||
|
name: "Date & time",
|
||||||
|
fieldName: "LastUpdatedTime",
|
||||||
|
minWidth: 140,
|
||||||
|
maxWidth: 300,
|
||||||
|
isResizable: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
key: "Name",
|
key: "Name",
|
||||||
name: "Name",
|
name: "Job name",
|
||||||
fieldName: "Name",
|
fieldName: "Name",
|
||||||
minWidth: 140,
|
minWidth: 140,
|
||||||
maxWidth: 300,
|
maxWidth: 300,
|
||||||
@@ -165,6 +173,165 @@ describe("CopyJobsList", () => {
|
|||||||
expect(screen.getByTestId("action-menu-job-2")).toBeInTheDocument();
|
expect(screen.getByTestId("action-menu-job-2")).toBeInTheDocument();
|
||||||
expect(screen.getByTestId("action-menu-job-3")).toBeInTheDocument();
|
expect(screen.getByTestId("action-menu-job-3")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("renders filter TextField with data-test attribute", () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterTextField = document.querySelector('[data-test="CopyJobsList/FilterTextField"]');
|
||||||
|
expect(filterTextField).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders search TextField with correct placeholder", () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const searchInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
expect(searchInput).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("Filtering", () => {
|
||||||
|
it("filters jobs by Name when text is entered", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Job 1" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 3")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters jobs case-insensitively", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "test job 1" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows all jobs when filter text is empty", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Job 1" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
fireEvent.change(filterInput, { target: { value: "" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 2")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 3")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters jobs by Status across all columns", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: CopyJobStatusType.Running } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 3")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters jobs by Mode across all columns", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Offline" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.queryByText("Test Job 1")).not.toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 2")).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 3")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("shows no results when filter matches no jobs", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "NonExistentJob" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.queryByText("Test Job 1")).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 2")).not.toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("Test Job 3")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("filters by partial text match", async () => {
|
||||||
|
render(<CopyJobsList jobs={mockJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Test" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 2")).toBeInTheDocument();
|
||||||
|
expect(screen.getByText("Test Job 3")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("resets pagination when filter changes", async () => {
|
||||||
|
const manyJobs: CopyJobType[] = Array.from({ length: 25 }, (_, i) => ({
|
||||||
|
...mockJobs[0],
|
||||||
|
ID: `job-${i + 1}`,
|
||||||
|
Name: `Test Job ${i + 1}`,
|
||||||
|
}));
|
||||||
|
|
||||||
|
render(<CopyJobsList jobs={manyJobs} handleActionClick={mockHandleActionClick} pageSize={10} />);
|
||||||
|
|
||||||
|
// Navigate to page 2
|
||||||
|
fireEvent.click(screen.getByLabelText("Go to next page"));
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Showing 11 - 20 of 25 items")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Apply filter - should reset to page 1
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Job 1" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
// Filtered results show from the beginning
|
||||||
|
expect(screen.getByText("Test Job 1")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates filtered count in pager", async () => {
|
||||||
|
const manyJobs: CopyJobType[] = Array.from({ length: 25 }, (_, i) => ({
|
||||||
|
...mockJobs[0],
|
||||||
|
ID: `job-${i + 1}`,
|
||||||
|
Name: i < 5 ? `Alpha Job ${i + 1}` : `Beta Job ${i + 1}`,
|
||||||
|
}));
|
||||||
|
|
||||||
|
render(<CopyJobsList jobs={manyJobs} handleActionClick={mockHandleActionClick} pageSize={10} />);
|
||||||
|
|
||||||
|
expect(screen.getByText("Showing 1 - 10 of 25 items")).toBeInTheDocument();
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Alpha" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.queryByText("Showing 1 - 10 of 25 items")).not.toBeInTheDocument();
|
||||||
|
// Pager should not be visible since filtered results (5) are less than page size (10)
|
||||||
|
expect(screen.queryByLabelText("Go to next page")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("Pagination", () => {
|
describe("Pagination", () => {
|
||||||
@@ -342,7 +509,7 @@ describe("CopyJobsList", () => {
|
|||||||
|
|
||||||
describe("Component Props", () => {
|
describe("Component Props", () => {
|
||||||
it("uses default page size when not provided", () => {
|
it("uses default page size when not provided", () => {
|
||||||
const manyJobs: CopyJobType[] = Array.from({ length: 12 }, (_, i) => ({
|
const manyJobs: CopyJobType[] = Array.from({ length: 20 }, (_, i) => ({
|
||||||
...mockJobs[0],
|
...mockJobs[0],
|
||||||
ID: `job-${i + 1}`,
|
ID: `job-${i + 1}`,
|
||||||
Name: `Test Job ${i + 1}`,
|
Name: `Test Job ${i + 1}`,
|
||||||
@@ -351,7 +518,7 @@ describe("CopyJobsList", () => {
|
|||||||
render(<CopyJobsList jobs={manyJobs} handleActionClick={mockHandleActionClick} />);
|
render(<CopyJobsList jobs={manyJobs} handleActionClick={mockHandleActionClick} />);
|
||||||
|
|
||||||
expect(screen.getByLabelText("Go to next page")).toBeInTheDocument();
|
expect(screen.getByLabelText("Go to next page")).toBeInTheDocument();
|
||||||
expect(screen.getByText("Showing 1 - 10 of 12 items")).toBeInTheDocument();
|
expect(screen.getByText("Showing 1 - 15 of 20 items")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("passes correct props to getColumns function", async () => {
|
it("passes correct props to getColumns function", async () => {
|
||||||
@@ -440,7 +607,33 @@ describe("CopyJobsList", () => {
|
|||||||
render(<CopyJobsList jobs={largeJobsList} handleActionClick={mockHandleActionClick} />);
|
render(<CopyJobsList jobs={largeJobsList} handleActionClick={mockHandleActionClick} />);
|
||||||
}).not.toThrow();
|
}).not.toThrow();
|
||||||
|
|
||||||
expect(screen.getByText("Showing 1 - 10 of 1000 items")).toBeInTheDocument();
|
expect(screen.getByText("Showing 1 - 15 of 1000 items")).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("handles filtering with null or undefined values gracefully", async () => {
|
||||||
|
const jobsWithNullValues: CopyJobType[] = [
|
||||||
|
{
|
||||||
|
...mockJobs[0],
|
||||||
|
ID: "job-with-values",
|
||||||
|
Name: "Valid Job",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
...mockJobs[1],
|
||||||
|
ID: "job-null-name",
|
||||||
|
Name: undefined as unknown as string,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
render(<CopyJobsList jobs={jobsWithNullValues} handleActionClick={mockHandleActionClick} />);
|
||||||
|
}).not.toThrow();
|
||||||
|
|
||||||
|
const filterInput = screen.getByPlaceholderText("Search jobs...");
|
||||||
|
fireEvent.change(filterInput, { target: { value: "Valid" } });
|
||||||
|
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(screen.getByText("Valid Job")).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
Sticky,
|
Sticky,
|
||||||
StickyPositionType,
|
StickyPositionType,
|
||||||
|
TextField,
|
||||||
} from "@fluentui/react";
|
} from "@fluentui/react";
|
||||||
import React, { useEffect } from "react";
|
import React, { useEffect, useMemo } from "react";
|
||||||
import Pager from "../../../../Common/Pager";
|
import Pager from "../../../../Common/Pager";
|
||||||
import { useThemeStore } from "../../../../hooks/useTheme";
|
import { useThemeStore } from "../../../../hooks/useTheme";
|
||||||
import { getThemeTokens } from "../../../Theme/ThemeUtil";
|
import { getThemeTokens } from "../../../Theme/ThemeUtil";
|
||||||
@@ -30,9 +31,15 @@ interface CopyJobsListProps {
|
|||||||
const styles = {
|
const styles = {
|
||||||
container: { height: "100%" } as React.CSSProperties,
|
container: { height: "100%" } as React.CSSProperties,
|
||||||
stackItem: { position: "relative", marginBottom: "20px" } as React.CSSProperties,
|
stackItem: { position: "relative", marginBottom: "20px" } as React.CSSProperties,
|
||||||
|
filterContainer: {
|
||||||
|
margin: "15px 5px",
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const PAGE_SIZE = 10;
|
const PAGE_SIZE = 15;
|
||||||
|
|
||||||
|
// Columns to search across
|
||||||
|
const searchableFields = ["Name", "Status", "LastUpdatedTime", "Mode"];
|
||||||
|
|
||||||
const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pageSize = PAGE_SIZE }) => {
|
const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pageSize = PAGE_SIZE }) => {
|
||||||
const isDarkMode = useThemeStore((state) => state.isDarkMode);
|
const isDarkMode = useThemeStore((state) => state.isDarkMode);
|
||||||
@@ -41,6 +48,23 @@ const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pa
|
|||||||
const [sortedJobs, setSortedJobs] = React.useState<CopyJobType[]>(jobs);
|
const [sortedJobs, setSortedJobs] = React.useState<CopyJobType[]>(jobs);
|
||||||
const [sortedColumnKey, setSortedColumnKey] = React.useState<string | undefined>(undefined);
|
const [sortedColumnKey, setSortedColumnKey] = React.useState<string | undefined>(undefined);
|
||||||
const [isSortedDescending, setIsSortedDescending] = React.useState<boolean>(false);
|
const [isSortedDescending, setIsSortedDescending] = React.useState<boolean>(false);
|
||||||
|
const [filterText, setFilterText] = React.useState<string>("");
|
||||||
|
|
||||||
|
const filteredJobs = useMemo(() => {
|
||||||
|
if (!filterText) {
|
||||||
|
return sortedJobs;
|
||||||
|
}
|
||||||
|
const lowerFilterText = filterText.toLowerCase();
|
||||||
|
return sortedJobs.filter((job: any) => {
|
||||||
|
return searchableFields.some((field) => {
|
||||||
|
const value = job[field];
|
||||||
|
if (value === undefined || value === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return String(value).toLowerCase().includes(lowerFilterText);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, [sortedJobs, filterText]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setSortedJobs(jobs);
|
setSortedJobs(jobs);
|
||||||
@@ -64,7 +88,15 @@ const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pa
|
|||||||
setStartIndex(0);
|
setStartIndex(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
const columns: IColumn[] = getColumns(handleSort, handleActionClick, sortedColumnKey, isSortedDescending);
|
const sortableColumns: IColumn[] = getColumns(handleSort, handleActionClick, sortedColumnKey, isSortedDescending);
|
||||||
|
|
||||||
|
const handleFilterTextChange = (
|
||||||
|
_event: React.FormEvent<HTMLInputElement | HTMLTextAreaElement>,
|
||||||
|
newValue?: string,
|
||||||
|
) => {
|
||||||
|
setFilterText(newValue || "");
|
||||||
|
setStartIndex(0);
|
||||||
|
};
|
||||||
|
|
||||||
const _handleRowClick = (job: CopyJobType) => {
|
const _handleRowClick = (job: CopyJobType) => {
|
||||||
openCopyJobDetailsPanel(job);
|
openCopyJobDetailsPanel(job);
|
||||||
@@ -81,14 +113,25 @@ const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pa
|
|||||||
return (
|
return (
|
||||||
<div style={styles.container}>
|
<div style={styles.container}>
|
||||||
<Stack verticalFill={true}>
|
<Stack verticalFill={true}>
|
||||||
|
<Stack.Item>
|
||||||
|
<div style={styles.filterContainer}>
|
||||||
|
<TextField
|
||||||
|
data-test="CopyJobsList/FilterTextField"
|
||||||
|
placeholder="Search jobs..."
|
||||||
|
ariaLabel="Search jobs"
|
||||||
|
value={filterText}
|
||||||
|
onChange={handleFilterTextChange}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Stack.Item>
|
||||||
<Stack.Item verticalFill={true} grow={1} shrink={1} style={styles.stackItem}>
|
<Stack.Item verticalFill={true} grow={1} shrink={1} style={styles.stackItem}>
|
||||||
<ScrollablePane scrollbarVisibility={ScrollbarVisibility.auto}>
|
<ScrollablePane scrollbarVisibility={ScrollbarVisibility.auto}>
|
||||||
<ShimmeredDetailsList
|
<ShimmeredDetailsList
|
||||||
className="CopyJobListContainer"
|
className="CopyJobListContainer"
|
||||||
onRenderRow={_onRenderRow}
|
onRenderRow={_onRenderRow}
|
||||||
checkboxVisibility={2}
|
checkboxVisibility={2}
|
||||||
columns={columns}
|
columns={sortableColumns}
|
||||||
items={sortedJobs.slice(startIndex, startIndex + pageSize)}
|
items={filteredJobs.slice(startIndex, startIndex + pageSize)}
|
||||||
enableShimmer={false}
|
enableShimmer={false}
|
||||||
constrainMode={ConstrainMode.unconstrained}
|
constrainMode={ConstrainMode.unconstrained}
|
||||||
layoutMode={DetailsListLayoutMode.justified}
|
layoutMode={DetailsListLayoutMode.justified}
|
||||||
@@ -117,12 +160,12 @@ const CopyJobsList: React.FC<CopyJobsListProps> = ({ jobs, handleActionClick, pa
|
|||||||
/>
|
/>
|
||||||
</ScrollablePane>
|
</ScrollablePane>
|
||||||
</Stack.Item>
|
</Stack.Item>
|
||||||
{sortedJobs.length > pageSize && (
|
{filteredJobs.length > pageSize && (
|
||||||
<Stack.Item>
|
<Stack.Item>
|
||||||
<Pager
|
<Pager
|
||||||
disabled={false}
|
disabled={false}
|
||||||
startIndex={startIndex}
|
startIndex={startIndex}
|
||||||
totalCount={sortedJobs.length}
|
totalCount={filteredJobs.length}
|
||||||
pageSize={pageSize}
|
pageSize={pageSize}
|
||||||
onLoadPage={(startIdx /* pageSize */) => {
|
onLoadPage={(startIdx /* pageSize */) => {
|
||||||
setStartIndex(startIdx);
|
setStartIndex(startIdx);
|
||||||
|
|||||||
@@ -1,5 +1,27 @@
|
|||||||
@import "../../../less/Common/Constants.less";
|
@import "../../../less/Common/Constants.less";
|
||||||
|
|
||||||
|
.themedTextFieldStyles() {
|
||||||
|
.ms-TextField {
|
||||||
|
.ms-TextField-fieldGroup {
|
||||||
|
background-color: var(--colorNeutralBackground1);
|
||||||
|
border-color: var(--colorNeutralStroke1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-TextField-field {
|
||||||
|
color: var(--colorNeutralForeground1);
|
||||||
|
background-color: var(--colorNeutralBackground1);
|
||||||
|
|
||||||
|
&::placeholder {
|
||||||
|
color: var(--colorNeutralForeground4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.ms-Label {
|
||||||
|
color: var(--colorNeutralForeground1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Common theme-aware classes
|
// Common theme-aware classes
|
||||||
.themeText {
|
.themeText {
|
||||||
color: var(--colorNeutralForeground1);
|
color: var(--colorNeutralForeground1);
|
||||||
@@ -119,25 +141,8 @@
|
|||||||
filter: invert(1);
|
filter: invert(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.ms-TextField {
|
.themedTextFieldStyles();
|
||||||
.ms-TextField-fieldGroup {
|
|
||||||
background-color: var(--colorNeutralBackground1);
|
|
||||||
border-color: var(--colorNeutralStroke1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.ms-TextField-field {
|
|
||||||
color: var(--colorNeutralForeground1);
|
|
||||||
background-color: var(--colorNeutralBackground1);
|
|
||||||
|
|
||||||
&::placeholder {
|
|
||||||
color: var(--colorNeutralForeground4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.ms-Label {
|
|
||||||
color: var(--colorNeutralForeground1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.migrationTypeDescription {
|
.migrationTypeDescription {
|
||||||
p {
|
p {
|
||||||
color: var(--colorNeutralForeground1);
|
color: var(--colorNeutralForeground1);
|
||||||
@@ -173,6 +178,11 @@
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
|
|
||||||
|
body.isDarkMode & {
|
||||||
|
.themedTextFieldStyles();
|
||||||
|
}
|
||||||
|
|
||||||
.ms-DetailsList {
|
.ms-DetailsList {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
|||||||
@@ -105,9 +105,12 @@ const App = (): JSX.Element => {
|
|||||||
// Scenario-based health tracking: start ApplicationLoad and complete phases.
|
// Scenario-based health tracking: start ApplicationLoad and complete phases.
|
||||||
const { startScenario, completePhase } = useMetricScenario();
|
const { startScenario, completePhase } = useMetricScenario();
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
startScenario(MetricScenario.ApplicationLoad);
|
// Only start scenario after config is initialized to avoid race conditions
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// with message handlers that depend on configContext.platform
|
||||||
}, []);
|
if (config) {
|
||||||
|
startScenario(MetricScenario.ApplicationLoad);
|
||||||
|
}
|
||||||
|
}, [config, startScenario]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (explorer) {
|
if (explorer) {
|
||||||
|
|||||||
@@ -1,88 +0,0 @@
|
|||||||
import { initializeIcons } from "@fluentui/react";
|
|
||||||
import "bootstrap/dist/css/bootstrap.css";
|
|
||||||
import React from "react";
|
|
||||||
import * as ReactDOM from "react-dom";
|
|
||||||
import { configContext, initializeConfiguration } from "../ConfigContext";
|
|
||||||
import { GalleryHeaderComponent } from "../Explorer/Controls/Header/GalleryHeaderComponent";
|
|
||||||
import { GalleryTab } from "../Explorer/Controls/NotebookGallery/GalleryViewerComponent";
|
|
||||||
import {
|
|
||||||
NotebookViewerComponent,
|
|
||||||
NotebookViewerComponentProps,
|
|
||||||
} from "../Explorer/Controls/NotebookViewer/NotebookViewerComponent";
|
|
||||||
import * as FileSystemUtil from "../Explorer/Notebook/FileSystemUtil";
|
|
||||||
import { IGalleryItem, JunoClient } from "../Juno/JunoClient";
|
|
||||||
import * as GalleryUtils from "../Utils/GalleryUtils";
|
|
||||||
|
|
||||||
const onInit = async () => {
|
|
||||||
initializeIcons();
|
|
||||||
await initializeConfiguration();
|
|
||||||
const galleryViewerProps = GalleryUtils.getGalleryViewerProps(window.location.search);
|
|
||||||
const notebookViewerProps = GalleryUtils.getNotebookViewerProps(window.location.search);
|
|
||||||
let backNavigationText: string;
|
|
||||||
let onBackClick: () => void;
|
|
||||||
if (galleryViewerProps.selectedTab !== undefined) {
|
|
||||||
backNavigationText = GalleryUtils.getTabTitle(galleryViewerProps.selectedTab);
|
|
||||||
onBackClick = () =>
|
|
||||||
(window.location.href = `${configContext.hostedExplorerURL}gallery.html?tab=${
|
|
||||||
GalleryTab[galleryViewerProps.selectedTab]
|
|
||||||
}`);
|
|
||||||
}
|
|
||||||
const hideInputs = notebookViewerProps.hideInputs;
|
|
||||||
|
|
||||||
const notebookUrl = decodeURIComponent(notebookViewerProps.notebookUrl);
|
|
||||||
|
|
||||||
const galleryItemId = notebookViewerProps.galleryItemId;
|
|
||||||
let galleryItem: IGalleryItem;
|
|
||||||
|
|
||||||
if (galleryItemId) {
|
|
||||||
const junoClient = new JunoClient();
|
|
||||||
const galleryItemJunoResponse = await junoClient.getNotebookInfo(galleryItemId);
|
|
||||||
galleryItem = galleryItemJunoResponse.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// The main purpose of hiding the prompt is to hide everything when hiding inputs.
|
|
||||||
// It is generally not very useful to just hide the prompt.
|
|
||||||
const hidePrompts = hideInputs;
|
|
||||||
|
|
||||||
render(notebookUrl, backNavigationText, hideInputs, hidePrompts, galleryItem, onBackClick);
|
|
||||||
};
|
|
||||||
|
|
||||||
const render = (
|
|
||||||
notebookUrl: string,
|
|
||||||
backNavigationText: string,
|
|
||||||
hideInputs?: boolean,
|
|
||||||
hidePrompts?: boolean,
|
|
||||||
galleryItem?: IGalleryItem,
|
|
||||||
onBackClick?: () => void,
|
|
||||||
) => {
|
|
||||||
const props: NotebookViewerComponentProps = {
|
|
||||||
junoClient: galleryItem ? new JunoClient() : undefined,
|
|
||||||
notebookUrl,
|
|
||||||
galleryItem,
|
|
||||||
backNavigationText,
|
|
||||||
hideInputs,
|
|
||||||
hidePrompts,
|
|
||||||
onBackClick: onBackClick,
|
|
||||||
onTagClick: undefined,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (galleryItem) {
|
|
||||||
document.title = FileSystemUtil.stripExtension(galleryItem.name, "ipynb");
|
|
||||||
}
|
|
||||||
|
|
||||||
const element = (
|
|
||||||
<>
|
|
||||||
<header>
|
|
||||||
<GalleryHeaderComponent />
|
|
||||||
</header>
|
|
||||||
<div style={{ marginLeft: 120, marginRight: 120 }}>
|
|
||||||
<NotebookViewerComponent {...props} />
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
|
|
||||||
ReactDOM.render(element, document.getElementById("notebookContent"));
|
|
||||||
};
|
|
||||||
|
|
||||||
// Entry point
|
|
||||||
window.addEventListener("load", onInit);
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Dropdown } from "@fluentui/react";
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { FunctionComponent } from "react";
|
import { FunctionComponent } from "react";
|
||||||
|
import { SearchableDropdown } from "../../../Common/SearchableDropdown";
|
||||||
import { DatabaseAccount } from "../../../Contracts/DataModels";
|
import { DatabaseAccount } from "../../../Contracts/DataModels";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -17,23 +17,18 @@ export const SwitchAccount: FunctionComponent<Props> = ({
|
|||||||
dismissMenu,
|
dismissMenu,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
return (
|
return (
|
||||||
<Dropdown
|
<SearchableDropdown<DatabaseAccount>
|
||||||
label="Cosmos DB Account Name"
|
label="Cosmos DB Account Name"
|
||||||
|
items={accounts}
|
||||||
|
selectedItem={selectedAccount}
|
||||||
|
onSelect={(account) => setSelectedAccountName(account.name)}
|
||||||
|
getKey={(account) => account.name}
|
||||||
|
getDisplayText={(account) => account.name}
|
||||||
|
placeholder="Select an Account"
|
||||||
|
filterPlaceholder="Filter accounts"
|
||||||
className="accountSwitchAccountDropdown"
|
className="accountSwitchAccountDropdown"
|
||||||
options={accounts?.map((account) => ({
|
disabled={!accounts || accounts.length === 0}
|
||||||
key: account.name,
|
onDismiss={dismissMenu}
|
||||||
text: account.name,
|
|
||||||
data: account,
|
|
||||||
}))}
|
|
||||||
onChange={(_, option) => {
|
|
||||||
setSelectedAccountName(String(option?.key));
|
|
||||||
dismissMenu();
|
|
||||||
}}
|
|
||||||
defaultSelectedKey={selectedAccount?.name}
|
|
||||||
placeholder={accounts && accounts.length === 0 ? "No Accounts Found" : "Select an Account"}
|
|
||||||
styles={{
|
|
||||||
callout: "accountSwitchAccountDropdownMenu",
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Dropdown } from "@fluentui/react";
|
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { FunctionComponent } from "react";
|
import { FunctionComponent } from "react";
|
||||||
|
import { SearchableDropdown } from "../../../Common/SearchableDropdown";
|
||||||
import { Subscription } from "../../../Contracts/DataModels";
|
import { Subscription } from "../../../Contracts/DataModels";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -15,24 +15,16 @@ export const SwitchSubscription: FunctionComponent<Props> = ({
|
|||||||
selectedSubscription,
|
selectedSubscription,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
return (
|
return (
|
||||||
<Dropdown
|
<SearchableDropdown<Subscription>
|
||||||
label="Subscription"
|
label="Subscription"
|
||||||
|
items={subscriptions}
|
||||||
|
selectedItem={selectedSubscription}
|
||||||
|
onSelect={(sub) => setSelectedSubscriptionId(sub.subscriptionId)}
|
||||||
|
getKey={(sub) => sub.subscriptionId}
|
||||||
|
getDisplayText={(sub) => sub.displayName}
|
||||||
|
placeholder="Select a Subscription"
|
||||||
|
filterPlaceholder="Filter subscriptions"
|
||||||
className="accountSwitchSubscriptionDropdown"
|
className="accountSwitchSubscriptionDropdown"
|
||||||
options={subscriptions?.map((sub) => {
|
|
||||||
return {
|
|
||||||
key: sub.subscriptionId,
|
|
||||||
text: sub.displayName,
|
|
||||||
data: sub,
|
|
||||||
};
|
|
||||||
})}
|
|
||||||
onChange={(_, option) => {
|
|
||||||
setSelectedSubscriptionId(String(option?.key));
|
|
||||||
}}
|
|
||||||
defaultSelectedKey={selectedSubscription?.subscriptionId}
|
|
||||||
placeholder={subscriptions && subscriptions.length === 0 ? "No Subscriptions Found" : "Select a Subscription"}
|
|
||||||
styles={{
|
|
||||||
callout: "accountSwitchSubscriptionDropdownMenu",
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ export function extractFeatures(given = new URLSearchParams(window.location.sear
|
|||||||
notebookBasePath: get("notebookbasepath"),
|
notebookBasePath: get("notebookbasepath"),
|
||||||
notebookServerToken: get("notebookservertoken"),
|
notebookServerToken: get("notebookservertoken"),
|
||||||
notebookServerUrl: get("notebookserverurl"),
|
notebookServerUrl: get("notebookserverurl"),
|
||||||
sandboxNotebookOutputs: "true" === get("sandboxnotebookoutputs", "true"),
|
sandboxNotebookOutputs: true,
|
||||||
selfServeType: get("selfservetype"),
|
selfServeType: get("selfservetype"),
|
||||||
showMinRUSurvey: "true" === get("showminrusurvey"),
|
showMinRUSurvey: "true" === get("showminrusurvey"),
|
||||||
ttl90Days: "true" === get("ttl90days"),
|
ttl90Days: "true" === get("ttl90days"),
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ describe("AuthorizationUtils", () => {
|
|||||||
enableKoResourceTree: false,
|
enableKoResourceTree: false,
|
||||||
enableThroughputBuckets: false,
|
enableThroughputBuckets: false,
|
||||||
hostedDataExplorer: false,
|
hostedDataExplorer: false,
|
||||||
sandboxNotebookOutputs: false,
|
sandboxNotebookOutputs: true,
|
||||||
showMinRUSurvey: false,
|
showMinRUSurvey: false,
|
||||||
ttl90Days: false,
|
ttl90Days: false,
|
||||||
enableThroughputCap: false,
|
enableThroughputCap: false,
|
||||||
|
|||||||
13
test/fx.ts
13
test/fx.ts
@@ -378,9 +378,11 @@ type PanelOpenOptions = {
|
|||||||
|
|
||||||
export enum CommandBarButton {
|
export enum CommandBarButton {
|
||||||
Save = "Save",
|
Save = "Save",
|
||||||
|
Delete = "Delete",
|
||||||
Execute = "Execute",
|
Execute = "Execute",
|
||||||
ExecuteQuery = "Execute Query",
|
ExecuteQuery = "Execute Query",
|
||||||
UploadItem = "Upload Item",
|
UploadItem = "Upload Item",
|
||||||
|
NewDocument = "New Document",
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper class that provides locator methods for DataExplorer components, on top of a Frame */
|
/** Helper class that provides locator methods for DataExplorer components, on top of a Frame */
|
||||||
@@ -478,7 +480,7 @@ export class DataExplorer {
|
|||||||
return await this.waitForNode(`${databaseId}/${containerId}/Documents`);
|
return await this.waitForNode(`${databaseId}/${containerId}/Documents`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForCommandBarButton(label: string, timeout?: number): Promise<Locator> {
|
async waitForCommandBarButton(label: CommandBarButton, timeout?: number): Promise<Locator> {
|
||||||
const commandBar = this.commandBarButton(label);
|
const commandBar = this.commandBarButton(label);
|
||||||
await commandBar.waitFor({ state: "visible", timeout });
|
await commandBar.waitFor({ state: "visible", timeout });
|
||||||
return commandBar;
|
return commandBar;
|
||||||
@@ -515,15 +517,6 @@ export class DataExplorer {
|
|||||||
const containerNode = await this.waitForContainerNode(context.database.id, context.container.id);
|
const containerNode = await this.waitForContainerNode(context.database.id, context.container.id);
|
||||||
await containerNode.expand();
|
await containerNode.expand();
|
||||||
|
|
||||||
// refresh tree to remove deleted database
|
|
||||||
const consoleMessages = await this.getNotificationConsoleMessages();
|
|
||||||
const refreshButton = this.frame.getByTestId("Sidebar/RefreshButton");
|
|
||||||
await refreshButton.click();
|
|
||||||
await expect(consoleMessages).toContainText("Successfully refreshed databases", {
|
|
||||||
timeout: ONE_MINUTE_MS,
|
|
||||||
});
|
|
||||||
await this.collapseNotificationConsole();
|
|
||||||
|
|
||||||
const scaleAndSettingsButton = this.frame.getByTestId(
|
const scaleAndSettingsButton = this.frame.getByTestId(
|
||||||
`TreeNode:${context.database.id}/${context.container.id}/Scale & Settings`,
|
`TreeNode:${context.database.id}/${context.container.id}/Scale & Settings`,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { expect, test } from "@playwright/test";
|
import { expect, test } from "@playwright/test";
|
||||||
|
|
||||||
import { setupCORSBypass } from "../CORSBypass";
|
import { setupCORSBypass } from "../CORSBypass";
|
||||||
import { DataExplorer, DocumentsTab, TestAccount } from "../fx";
|
import { CommandBarButton, DataExplorer, DocumentsTab, TestAccount } from "../fx";
|
||||||
import { retry, serializeMongoToJson, setPartitionKeys } from "../testData";
|
import { retry, serializeMongoToJson, setPartitionKeys } from "../testData";
|
||||||
import { documentTestCases } from "./testCases";
|
import { documentTestCases } from "./testCases";
|
||||||
|
|
||||||
@@ -48,19 +48,20 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
|||||||
expect(resultData?._id).not.toBeNull();
|
expect(resultData?._id).not.toBeNull();
|
||||||
expect(resultData?._id).toEqual(docId);
|
expect(resultData?._id).toEqual(docId);
|
||||||
});
|
});
|
||||||
test(`should be able to create and delete new document from ${docId}`, async () => {
|
test(`should be able to create and delete new document from ${docId}`, async ({ page }) => {
|
||||||
const span = documentsTab.documentsListPane.getByText(docId, { exact: true }).nth(0);
|
const span = documentsTab.documentsListPane.getByText(docId, { exact: true }).nth(0);
|
||||||
await span.waitFor();
|
await span.waitFor();
|
||||||
await expect(span).toBeVisible();
|
await expect(span).toBeVisible();
|
||||||
|
|
||||||
await span.click();
|
await span.click();
|
||||||
|
await page.waitForTimeout(5000); // wait for 5 seconds to ensure document is fully loaded. waitforTimeout is not recommended generally but here we are working around flakiness in the test env
|
||||||
|
|
||||||
let newDocumentId;
|
let newDocumentId;
|
||||||
await retry(async () => {
|
await retry(async () => {
|
||||||
const newDocumentButton = await explorer.waitForCommandBarButton("New Document", 5000);
|
const newDocumentButton = await explorer.waitForCommandBarButton(CommandBarButton.NewDocument, 5000);
|
||||||
await expect(newDocumentButton).toBeVisible();
|
await expect(newDocumentButton).toBeVisible();
|
||||||
await expect(newDocumentButton).toBeEnabled();
|
await expect(newDocumentButton).toBeEnabled();
|
||||||
await newDocumentButton.click();
|
await newDocumentButton.click();
|
||||||
|
|
||||||
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
||||||
|
|
||||||
newDocumentId = `${Date.now().toString()}-delete`;
|
newDocumentId = `${Date.now().toString()}-delete`;
|
||||||
@@ -71,8 +72,9 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await documentsTab.resultsEditor.setText(JSON.stringify(newDocument));
|
await documentsTab.resultsEditor.setText(JSON.stringify(newDocument));
|
||||||
const saveButton = await explorer.waitForCommandBarButton("Save", 5000);
|
const saveButton = await explorer.waitForCommandBarButton(CommandBarButton.Save, 5000);
|
||||||
await saveButton.click({ timeout: 5000 });
|
await saveButton.click({ timeout: 5000 });
|
||||||
|
|
||||||
await expect(saveButton).toBeHidden({ timeout: 5000 });
|
await expect(saveButton).toBeHidden({ timeout: 5000 });
|
||||||
}, 3);
|
}, 3);
|
||||||
|
|
||||||
@@ -84,7 +86,7 @@ for (const { name, databaseId, containerId, documents } of documentTestCases) {
|
|||||||
await newSpan.click();
|
await newSpan.click();
|
||||||
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
await expect(documentsTab.resultsEditor.locator).toBeAttached({ timeout: 60 * 1000 });
|
||||||
|
|
||||||
const deleteButton = await explorer.waitForCommandBarButton("Delete", 5000);
|
const deleteButton = await explorer.waitForCommandBarButton(CommandBarButton.Delete, 5000);
|
||||||
await deleteButton.click();
|
await deleteButton.click();
|
||||||
|
|
||||||
const deleteDialogButton = await explorer.waitForDialogButton("Delete", 5000);
|
const deleteDialogButton = await explorer.waitForDialogButton("Delete", 5000);
|
||||||
|
|||||||
@@ -246,13 +246,17 @@ test.describe("Container Copy - Offline Migration", () => {
|
|||||||
expect(response.ok()).toBe(true);
|
expect(response.ok()).toBe(true);
|
||||||
|
|
||||||
// Verify panel closes and job appears in the list
|
// Verify panel closes and job appears in the list
|
||||||
await expect(panel).not.toBeVisible({ timeout: 5000 });
|
await expect(panel).not.toBeVisible();
|
||||||
|
|
||||||
|
const filterTextField = wrapper.getByTestId("CopyJobsList/FilterTextField");
|
||||||
|
await filterTextField.waitFor({ state: "visible" });
|
||||||
|
await filterTextField.fill(validJobName);
|
||||||
|
|
||||||
const jobsListContainer = wrapper.locator(".CopyJobListContainer .ms-DetailsList-contentWrapper .ms-List-page");
|
const jobsListContainer = wrapper.locator(".CopyJobListContainer .ms-DetailsList-contentWrapper .ms-List-page");
|
||||||
await jobsListContainer.waitFor({ state: "visible", timeout: 5000 });
|
await jobsListContainer.waitFor({ state: "visible" });
|
||||||
|
|
||||||
const jobItem = jobsListContainer.getByText(validJobName);
|
const jobItem = jobsListContainer.getByText(validJobName);
|
||||||
await jobItem.waitFor({ state: "visible", timeout: 5000 });
|
await jobItem.waitFor({ state: "visible" });
|
||||||
await expect(jobItem).toBeVisible();
|
await expect(jobItem).toBeVisible();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -120,18 +120,22 @@ test.describe("Container Copy - Online Migration", () => {
|
|||||||
expect(response.ok()).toBe(true);
|
expect(response.ok()).toBe(true);
|
||||||
|
|
||||||
// Verify panel closes and job appears in the list
|
// Verify panel closes and job appears in the list
|
||||||
await expect(panel).not.toBeVisible({ timeout: 5000 });
|
await expect(panel).not.toBeVisible();
|
||||||
|
|
||||||
|
const filterTextField = wrapper.getByTestId("CopyJobsList/FilterTextField");
|
||||||
|
await filterTextField.waitFor({ state: "visible" });
|
||||||
|
await filterTextField.fill(onlineMigrationJobName);
|
||||||
|
|
||||||
const jobsListContainer = wrapper.locator(".CopyJobListContainer .ms-DetailsList-contentWrapper .ms-List-page");
|
const jobsListContainer = wrapper.locator(".CopyJobListContainer .ms-DetailsList-contentWrapper .ms-List-page");
|
||||||
await jobsListContainer.waitFor({ state: "visible", timeout: 5000 });
|
await jobsListContainer.waitFor({ state: "visible" });
|
||||||
|
|
||||||
let jobRow, statusCell, actionMenuButton;
|
let jobRow, statusCell, actionMenuButton;
|
||||||
jobRow = jobsListContainer.locator(".ms-DetailsRow", { hasText: onlineMigrationJobName });
|
jobRow = jobsListContainer.locator(".ms-DetailsRow", { hasText: onlineMigrationJobName });
|
||||||
statusCell = jobRow.locator("[data-automationid='DetailsRowCell'][data-automation-key='CopyJobStatus']");
|
statusCell = jobRow.locator("[data-automationid='DetailsRowCell'][data-automation-key='CopyJobStatus']");
|
||||||
await jobRow.waitFor({ state: "visible", timeout: 5000 });
|
await jobRow.waitFor({ state: "visible" });
|
||||||
|
|
||||||
// Verify job status changes to queued state
|
// Verify job status changes to queued state
|
||||||
await expect(statusCell).toContainText(/running|queued|pending/i, { timeout: 5000 });
|
await expect(statusCell).toContainText(/running|queued|pending/i);
|
||||||
|
|
||||||
// Test job lifecycle management through action menu
|
// Test job lifecycle management through action menu
|
||||||
actionMenuButton = wrapper.getByTestId(`CopyJobActionMenu/Button:${onlineMigrationJobName}`);
|
actionMenuButton = wrapper.getByTestId(`CopyJobActionMenu/Button:${onlineMigrationJobName}`);
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
|
|
||||||
const pitrBtn = accordionPanel.getByTestId("pointInTimeRestore:PrimaryBtn");
|
const pitrBtn = accordionPanel.getByTestId("pointInTimeRestore:PrimaryBtn");
|
||||||
await expect(pitrBtn).toBeVisible();
|
await expect(pitrBtn).toBeVisible();
|
||||||
await pitrBtn.click();
|
await pitrBtn.click({ force: true });
|
||||||
|
|
||||||
// Verify new page opens with correct URL pattern
|
// Verify new page opens with correct URL pattern
|
||||||
page.context().on("page", async (newPage) => {
|
page.context().on("page", async (newPage) => {
|
||||||
@@ -246,7 +246,7 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
|
|
||||||
const toggleButton = crossAccordionPanel.getByTestId("btn-toggle");
|
const toggleButton = crossAccordionPanel.getByTestId("btn-toggle");
|
||||||
await expect(toggleButton).toBeVisible();
|
await expect(toggleButton).toBeVisible();
|
||||||
await toggleButton.click();
|
await toggleButton.click({ force: true });
|
||||||
|
|
||||||
// Verify popover functionality
|
// Verify popover functionality
|
||||||
const popover = frame.locator("[data-test='popover-container']");
|
const popover = frame.locator("[data-test='popover-container']");
|
||||||
@@ -257,7 +257,7 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
await expect(yesButton).toBeVisible();
|
await expect(yesButton).toBeVisible();
|
||||||
await expect(noButton).toBeVisible();
|
await expect(noButton).toBeVisible();
|
||||||
|
|
||||||
await yesButton.click();
|
await yesButton.click({ force: true });
|
||||||
|
|
||||||
// Verify loading states
|
// Verify loading states
|
||||||
await expect(loadingOverlay).toBeVisible();
|
await expect(loadingOverlay).toBeVisible();
|
||||||
@@ -265,6 +265,6 @@ test.describe("Container Copy - Permission Screen Verification", () => {
|
|||||||
await expect(popover).toBeHidden({ timeout: 10 * 1000 });
|
await expect(popover).toBeHidden({ timeout: 10 * 1000 });
|
||||||
|
|
||||||
// Cancel the panel to clean up
|
// Cancel the panel to clean up
|
||||||
await panel.getByRole("button", { name: "Cancel" }).click();
|
await panel.getByRole("button", { name: "Cancel" }).click({ force: true });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -136,9 +136,7 @@ test.describe.serial("Upload Item", () => {
|
|||||||
if (existsSync(uploadDocumentDirPath)) {
|
if (existsSync(uploadDocumentDirPath)) {
|
||||||
rmdirSync(uploadDocumentDirPath);
|
rmdirSync(uploadDocumentDirPath);
|
||||||
}
|
}
|
||||||
if (!process.env.CI) {
|
await context?.dispose();
|
||||||
await context?.dispose();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test.afterEach("Close Upload Items panel if still open", async () => {
|
test.afterEach("Close Upload Items panel if still open", async () => {
|
||||||
|
|||||||
@@ -30,12 +30,9 @@ test.beforeEach("Open new query tab", async ({ page }) => {
|
|||||||
await explorer.frame.getByTestId("NotificationConsole/Contents").waitFor();
|
await explorer.frame.getByTestId("NotificationConsole/Contents").waitFor();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Delete database only if not running in CI
|
test.afterAll("Delete Test Database", async () => {
|
||||||
if (!process.env.CI) {
|
await context?.dispose();
|
||||||
test.afterAll("Delete Test Database", async () => {
|
});
|
||||||
await context?.dispose();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test("Query results", async () => {
|
test("Query results", async () => {
|
||||||
// Run the query and verify the results
|
// Run the query and verify the results
|
||||||
|
|||||||
@@ -23,12 +23,9 @@ test.describe("Change Partition Key", () => {
|
|||||||
await PartitionKeyTab.click();
|
await PartitionKeyTab.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Delete database only if not running in CI
|
test.afterEach("Delete Test Database", async () => {
|
||||||
if (!process.env.CI) {
|
await context?.dispose();
|
||||||
test.afterEach("Delete Test Database", async () => {
|
});
|
||||||
await context?.dispose();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test("Change partition key path", async ({ page }) => {
|
test("Change partition key path", async ({ page }) => {
|
||||||
await expect(explorer.frame.getByText("/partitionKey")).toBeVisible();
|
await expect(explorer.frame.getByText("/partitionKey")).toBeVisible();
|
||||||
|
|||||||
@@ -118,7 +118,5 @@ async function openScaleTab(browser: Browser): Promise<SetupResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function cleanup({ context }: Partial<SetupResult>) {
|
async function cleanup({ context }: Partial<SetupResult>) {
|
||||||
if (!process.env.CI) {
|
await context?.dispose();
|
||||||
await context?.dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,9 @@ test.describe("Settings under Scale & Settings", () => {
|
|||||||
await settingsTab.click();
|
await settingsTab.click();
|
||||||
});
|
});
|
||||||
|
|
||||||
// Delete database only if not running in CI
|
test.afterAll("Delete Test Database", async () => {
|
||||||
if (!process.env.CI) {
|
await context?.dispose();
|
||||||
test.afterAll("Delete Test Database", async () => {
|
});
|
||||||
await context?.dispose();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test("Update TTL to On (no default)", async () => {
|
test("Update TTL to On (no default)", async () => {
|
||||||
const ttlOnNoDefaultRadioButton = explorer.frame.getByRole("radio", { name: "ttl-on-no-default-option" });
|
const ttlOnNoDefaultRadioButton = explorer.frame.getByRole("radio", { name: "ttl-on-no-default-option" });
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ test.describe("Stored Procedures", () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Execute stored procedure
|
// Execute stored procedure
|
||||||
const executeButton = explorer.commandBarButton(CommandBarButton.Execute);
|
const executeButton = explorer.commandBarButton(CommandBarButton.Execute).first();
|
||||||
await executeButton.click();
|
await executeButton.click();
|
||||||
const executeSidePanelButton = explorer.frame.getByTestId("Panel/OkButton");
|
const executeSidePanelButton = explorer.frame.getByTestId("Panel/OkButton");
|
||||||
await executeSidePanelButton.click();
|
await executeSidePanelButton.click();
|
||||||
|
|||||||
@@ -26,11 +26,9 @@ test.describe("Triggers", () => {
|
|||||||
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!process.env.CI) {
|
test.afterAll("Delete Test Database", async () => {
|
||||||
test.afterAll("Delete Test Database", async () => {
|
await context?.dispose();
|
||||||
await context?.dispose();
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test("Add and delete trigger", async ({ page }, testInfo) => {
|
test("Add and delete trigger", async ({ page }, testInfo) => {
|
||||||
// Open container context menu and click New Trigger
|
// Open container context menu and click New Trigger
|
||||||
|
|||||||
@@ -19,11 +19,9 @@ test.describe("User Defined Functions", () => {
|
|||||||
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!process.env.CI) {
|
test.afterAll("Delete Test Database", async () => {
|
||||||
test.afterAll("Delete Test Database", async () => {
|
await context?.dispose();
|
||||||
await context?.dispose();
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test("Add, execute, and delete user defined function", async ({ page }, testInfo) => {
|
test("Add, execute, and delete user defined function", async ({ page }, testInfo) => {
|
||||||
// Open container context menu and click New UDF
|
// Open container context menu and click New UDF
|
||||||
|
|||||||
Reference in New Issue
Block a user