Merge branch 'master' of https://github.com/Azure/cosmos-explorer into eslit/fixed-lint-notebook-utils

This commit is contained in:
sunilyadav840 2021-03-09 17:08:04 +05:30
commit efe458da3d
25 changed files with 271 additions and 301 deletions

View File

@ -11,8 +11,6 @@ src/Common/CosmosClient.test.ts
src/Common/CosmosClient.ts src/Common/CosmosClient.ts
src/Common/DataAccessUtilityBase.test.ts src/Common/DataAccessUtilityBase.test.ts
src/Common/DataAccessUtilityBase.ts src/Common/DataAccessUtilityBase.ts
src/Common/DeleteFeedback.ts
src/Common/DocumentClientUtilityBase.ts
src/Common/EditableUtility.ts src/Common/EditableUtility.ts
src/Common/HashMap.test.ts src/Common/HashMap.test.ts
src/Common/HashMap.ts src/Common/HashMap.ts
@ -28,7 +26,6 @@ src/Common/ObjectCache.test.ts
src/Common/ObjectCache.ts src/Common/ObjectCache.ts
src/Common/QueriesClient.ts src/Common/QueriesClient.ts
src/Common/Splitter.ts src/Common/Splitter.ts
src/Common/ThemeUtility.ts
src/Common/UrlUtility.ts src/Common/UrlUtility.ts
src/Config.ts src/Config.ts
src/Contracts/ActionContracts.ts src/Contracts/ActionContracts.ts
@ -56,8 +53,6 @@ src/Explorer/ComponentRegisterer.test.ts
src/Explorer/ComponentRegisterer.ts src/Explorer/ComponentRegisterer.ts
src/Explorer/ContextMenuButtonFactory.ts src/Explorer/ContextMenuButtonFactory.ts
src/Explorer/Controls/CollapsiblePanel/CollapsiblePanelComponent.ts src/Explorer/Controls/CollapsiblePanel/CollapsiblePanelComponent.ts
src/Explorer/Controls/CommandButton/CommandButton.test.ts
src/Explorer/Controls/CommandButton/CommandButton.ts
src/Explorer/Controls/DiffEditor/DiffEditorComponent.ts src/Explorer/Controls/DiffEditor/DiffEditorComponent.ts
src/Explorer/Controls/DynamicList/DynamicList.test.ts src/Explorer/Controls/DynamicList/DynamicList.test.ts
src/Explorer/Controls/DynamicList/DynamicListComponent.ts src/Explorer/Controls/DynamicList/DynamicListComponent.ts
@ -93,8 +88,6 @@ src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.ts
src/Explorer/Graph/GraphExplorerComponent/EdgeInfoCache.ts src/Explorer/Graph/GraphExplorerComponent/EdgeInfoCache.ts
src/Explorer/Graph/GraphExplorerComponent/GraphData.test.ts src/Explorer/Graph/GraphExplorerComponent/GraphData.test.ts
src/Explorer/Graph/GraphExplorerComponent/GraphData.ts src/Explorer/Graph/GraphExplorerComponent/GraphData.ts
src/Explorer/Graph/GraphExplorerComponent/GraphUtil.test.ts
src/Explorer/Graph/GraphExplorerComponent/GraphUtil.ts
src/Explorer/Graph/GraphExplorerComponent/GremlinClient.test.ts src/Explorer/Graph/GraphExplorerComponent/GremlinClient.test.ts
src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts
src/Explorer/Graph/GraphExplorerComponent/GremlinSimpleClient.test.ts src/Explorer/Graph/GraphExplorerComponent/GremlinSimpleClient.test.ts
@ -167,7 +160,6 @@ src/Explorer/Tables/DataTable/DataTableBuilder.ts
src/Explorer/Tables/DataTable/DataTableContextMenu.ts src/Explorer/Tables/DataTable/DataTableContextMenu.ts
src/Explorer/Tables/DataTable/DataTableOperationManager.ts src/Explorer/Tables/DataTable/DataTableOperationManager.ts
src/Explorer/Tables/DataTable/DataTableOperations.ts src/Explorer/Tables/DataTable/DataTableOperations.ts
src/Explorer/Tables/DataTable/DataTableUtilities.ts
src/Explorer/Tables/DataTable/DataTableViewModel.ts src/Explorer/Tables/DataTable/DataTableViewModel.ts
src/Explorer/Tables/DataTable/TableCommands.ts src/Explorer/Tables/DataTable/TableCommands.ts
src/Explorer/Tables/DataTable/TableEntityCache.ts src/Explorer/Tables/DataTable/TableEntityCache.ts
@ -176,8 +168,6 @@ src/Explorer/Tables/Entities.ts
src/Explorer/Tables/QueryBuilder/ClauseGroup.ts src/Explorer/Tables/QueryBuilder/ClauseGroup.ts
src/Explorer/Tables/QueryBuilder/ClauseGroupViewModel.ts src/Explorer/Tables/QueryBuilder/ClauseGroupViewModel.ts
src/Explorer/Tables/QueryBuilder/CustomTimestampHelper.ts src/Explorer/Tables/QueryBuilder/CustomTimestampHelper.ts
src/Explorer/Tables/QueryBuilder/DateTimeUtilities.test.ts
src/Explorer/Tables/QueryBuilder/DateTimeUtilities.ts
src/Explorer/Tables/QueryBuilder/QueryBuilderViewModel.ts src/Explorer/Tables/QueryBuilder/QueryBuilderViewModel.ts
src/Explorer/Tables/QueryBuilder/QueryClauseViewModel.ts src/Explorer/Tables/QueryBuilder/QueryClauseViewModel.ts
src/Explorer/Tables/QueryBuilder/QueryViewModel.ts src/Explorer/Tables/QueryBuilder/QueryViewModel.ts
@ -270,23 +260,14 @@ src/Terminal/NotebookAppContracts.d.ts
src/Terminal/index.ts src/Terminal/index.ts
src/TokenProviders/PortalTokenProvider.ts src/TokenProviders/PortalTokenProvider.ts
src/TokenProviders/TokenProviderFactory.ts src/TokenProviders/TokenProviderFactory.ts
src/Utils/AuthorizationUtils.test.ts
src/Utils/AuthorizationUtils.ts
src/Utils/AutoPilotUtils.test.ts
src/Utils/AutoPilotUtils.ts
src/Utils/DatabaseAccountUtils.test.ts src/Utils/DatabaseAccountUtils.test.ts
src/Utils/DatabaseAccountUtils.ts src/Utils/DatabaseAccountUtils.ts
src/Utils/JunoUtils.ts
src/Utils/MessageValidation.ts
src/Utils/NotebookConfigurationUtils.ts src/Utils/NotebookConfigurationUtils.ts
src/Utils/PricingUtils.test.ts src/Utils/PricingUtils.test.ts
src/Utils/QueryUtils.test.ts src/Utils/QueryUtils.test.ts
src/Utils/QueryUtils.ts src/Utils/QueryUtils.ts
src/Utils/StringUtils.test.ts
src/Utils/StringUtils.ts
src/applyExplorerBindings.ts src/applyExplorerBindings.ts
src/global.d.ts src/global.d.ts
src/quickstart.ts
src/setupTests.ts src/setupTests.ts
src/workers/upload/index.ts src/workers/upload/index.ts
src/Explorer/Controls/AccessibleElement/AccessibleElement.tsx src/Explorer/Controls/AccessibleElement/AccessibleElement.tsx

View File

@ -2,8 +2,7 @@
* Copyright (C) Microsoft Corporation. All rights reserved. * Copyright (C) Microsoft Corporation. All rights reserved.
*----------------------------------------------------------*/ *----------------------------------------------------------*/
export default class ThemeUtility { export function getMonacoTheme(theme: string): string {
public static getMonacoTheme(theme: string): string {
switch (theme) { switch (theme) {
case "default": case "default":
case "hc-white": case "hc-white":
@ -16,4 +15,3 @@ export default class ThemeUtility {
return "vs"; return "vs";
} }
} }
}

View File

@ -1,4 +1,4 @@
import { StringUtils } from "../../../Utils/StringUtils"; import * as StringUtils from "../../../Utils/StringUtils";
import { KeyCodes } from "../../../Common/Constants"; import { KeyCodes } from "../../../Common/Constants";
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor"; import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants"; import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants";

View File

@ -4,7 +4,7 @@
import * as React from "react"; import * as React from "react";
import * as DataModels from "../../../Contracts/DataModels"; import * as DataModels from "../../../Contracts/DataModels";
import { StringUtils } from "../../../Utils/StringUtils"; import * as StringUtils from "../../../Utils/StringUtils";
import { userContext } from "../../../UserContext"; import { userContext } from "../../../UserContext";
import { TerminalQueryParams } from "../../../Common/Constants"; import { TerminalQueryParams } from "../../../Common/Constants";
import { handleError } from "../../../Common/ErrorHandlingUtils"; import { handleError } from "../../../Common/ErrorHandlingUtils";

View File

@ -5,7 +5,7 @@
import * as React from "react"; import * as React from "react";
import { NeighborVertexBasicInfo, EditedEdges, GraphNewEdgeData, PossibleVertex } from "./GraphExplorer"; import { NeighborVertexBasicInfo, EditedEdges, GraphNewEdgeData, PossibleVertex } from "./GraphExplorer";
import { GraphUtil } from "./GraphUtil"; import * as GraphUtil from "./GraphUtil";
import * as InputTypeaheadComponent from "../../Controls/InputTypeahead/InputTypeaheadComponent"; import * as InputTypeaheadComponent from "../../Controls/InputTypeahead/InputTypeaheadComponent";
import DeleteIcon from "../../../../images/delete.svg"; import DeleteIcon from "../../../../images/delete.svg";
import AddPropertyIcon from "../../../../images/Add-property.svg"; import AddPropertyIcon from "../../../../images/Add-property.svg";

View File

@ -9,7 +9,7 @@ import { GraphVizComponentProps } from "./GraphVizComponent";
import * as GraphData from "./GraphData"; import * as GraphData from "./GraphData";
import { ConsoleDataType } from "../../Menus/NotificationConsole/NotificationConsoleComponent"; import { ConsoleDataType } from "../../Menus/NotificationConsole/NotificationConsoleComponent";
import * as NotificationConsoleUtils from "../../../Utils/NotificationConsoleUtils"; import * as NotificationConsoleUtils from "../../../Utils/NotificationConsoleUtils";
import { GraphUtil } from "./GraphUtil"; import * as GraphUtil from "./GraphUtil";
import * as DataModels from "../../../Contracts/DataModels"; import * as DataModels from "../../../Contracts/DataModels";
import * as ViewModels from "../../../Contracts/ViewModels"; import * as ViewModels from "../../../Contracts/ViewModels";
import * as GremlinClient from "./GremlinClient"; import * as GremlinClient from "./GremlinClient";

View File

@ -1,4 +1,4 @@
import { GraphUtil } from "./GraphUtil"; import * as GraphUtil from "./GraphUtil";
import { GraphData, GremlinVertex, GremlinEdge } from "./GraphData"; import { GraphData, GremlinVertex, GremlinEdge } from "./GraphData";
import * as sinon from "sinon"; import * as sinon from "sinon";
import { GraphExplorer } from "./GraphExplorer"; import { GraphExplorer } from "./GraphExplorer";
@ -69,7 +69,7 @@ describe("Process Gremlin vertex", () => {
describe("getLimitedArrayString()", () => { describe("getLimitedArrayString()", () => {
const expectedEmptyResult = { result: "", consumedCount: 0 }; const expectedEmptyResult = { result: "", consumedCount: 0 };
it("should handle null array", () => { it("should handle null array", () => {
expect(GraphUtil.getLimitedArrayString(null, 10)).toEqual(expectedEmptyResult); expect(GraphUtil.getLimitedArrayString(undefined, 10)).toEqual(expectedEmptyResult);
}); });
it("should handle empty array", () => { it("should handle empty array", () => {

View File

@ -7,8 +7,13 @@ interface JoinArrayMaxCharOutput {
consumedCount: number; // Number of items consumed consumedCount: number; // Number of items consumed
} }
export class GraphUtil { interface EdgePropertyType {
public static getNeighborTitle(neighbor: NeighborVertexBasicInfo): string { id: string;
outV?: string;
inV?: string;
}
export function getNeighborTitle(neighbor: NeighborVertexBasicInfo): string {
return `edge id: ${neighbor.edgeId}, vertex id: ${neighbor.id}`; return `edge id: ${neighbor.edgeId}, vertex id: ${neighbor.id}`;
} }
@ -18,17 +23,17 @@ export class GraphUtil {
* @param graphData * @param graphData
* @param newNodes (optional) object describing new nodes encountered * @param newNodes (optional) object describing new nodes encountered
*/ */
public static createEdgesfromNode( export function createEdgesfromNode(
vertex: GraphData.GremlinVertex, vertex: GraphData.GremlinVertex,
graphData: GraphData.GraphData<GraphData.GremlinVertex, GraphData.GremlinEdge>, graphData: GraphData.GraphData<GraphData.GremlinVertex, GraphData.GremlinEdge>,
newNodes?: { [id: string]: boolean } newNodes?: { [id: string]: boolean }
): void { ): void {
if (vertex.hasOwnProperty("outE")) { if (Object.prototype.hasOwnProperty.call(vertex, "outE")) {
let outE = vertex.outE; const outE = vertex.outE;
for (var label in outE) { for (const label in outE) {
$.each(outE[label], (index: number, edge: any) => { $.each(outE[label], (index: number, edge: EdgePropertyType) => {
// We create our own edge. No need to fetch // We create our own edge. No need to fetch
let e = { const e = {
id: edge.id, id: edge.id,
label: label, label: label,
inV: edge.inV, inV: edge.inV,
@ -42,12 +47,12 @@ export class GraphUtil {
}); });
} }
} }
if (vertex.hasOwnProperty("inE")) { if (Object.prototype.hasOwnProperty.call(vertex, "inE")) {
let inE = vertex.inE; const inE = vertex.inE;
for (var label in inE) { for (const label in inE) {
$.each(inE[label], (index: number, edge: any) => { $.each(inE[label], (index: number, edge: EdgePropertyType) => {
// We create our own edge. No need to fetch // We create our own edge. No need to fetch
let e = { const e = {
id: edge.id, id: edge.id,
label: label, label: label,
inV: vertex.id, inV: vertex.id,
@ -70,7 +75,7 @@ export class GraphUtil {
* @param maxSize * @param maxSize
* @return * @return
*/ */
public static getLimitedArrayString(array: string[], maxSize: number): JoinArrayMaxCharOutput { export function getLimitedArrayString(array: string[], maxSize: number): JoinArrayMaxCharOutput {
if (!array || array.length === 0 || array[0].length + 2 > maxSize) { if (!array || array.length === 0 || array[0].length + 2 > maxSize) {
return { result: "", consumedCount: 0 }; return { result: "", consumedCount: 0 };
} }
@ -93,7 +98,7 @@ export class GraphUtil {
}; };
} }
public static createFetchEdgePairQuery( export function createFetchEdgePairQuery(
outE: boolean, outE: boolean,
pkid: string, pkid: string,
excludedEdgeIds: string[], excludedEdgeIds: string[],
@ -104,8 +109,8 @@ export class GraphUtil {
let gremlinQuery: string; let gremlinQuery: string;
if (excludedEdgeIds.length > 0) { if (excludedEdgeIds.length > 0) {
// build a string up to max char // build a string up to max char
const joined = GraphUtil.getLimitedArrayString(excludedEdgeIds, withoutStepArgMaxLenght); const joined = getLimitedArrayString(excludedEdgeIds, withoutStepArgMaxLenght);
const hasWithoutStep = !!joined.result ? `.has(id, without(${joined.result}))` : ""; const hasWithoutStep = joined.result ? `.has(id, without(${joined.result}))` : "";
if (joined.consumedCount === excludedEdgeIds.length) { if (joined.consumedCount === excludedEdgeIds.length) {
gremlinQuery = `g.V(${pkid}).${outE ? "outE" : "inE"}()${hasWithoutStep}.limit(${pageSize}).as('e').${ gremlinQuery = `g.V(${pkid}).${outE ? "outE" : "inE"}()${hasWithoutStep}.limit(${pageSize}).as('e').${
@ -128,7 +133,7 @@ export class GraphUtil {
/** /**
* Trim graph * Trim graph
*/ */
public static trimGraph( export function trimGraph(
currentRoot: GraphData.GremlinVertex, currentRoot: GraphData.GremlinVertex,
graphData: GraphData.GraphData<GraphData.GremlinVertex, GraphData.GremlinEdge> graphData: GraphData.GraphData<GraphData.GremlinVertex, GraphData.GremlinEdge>
) { ) {
@ -141,14 +146,14 @@ export class GraphUtil {
}); });
} }
public static addRootChildToGraph( export function addRootChildToGraph(
root: GraphData.GremlinVertex, root: GraphData.GremlinVertex,
child: GraphData.GremlinVertex, child: GraphData.GremlinVertex,
graphData: GraphData.GraphData<GraphData.GremlinVertex, GraphData.GremlinEdge> graphData: GraphData.GraphData<GraphData.GremlinVertex, GraphData.GremlinEdge>
) { ) {
child._ancestorsId = (root._ancestorsId || []).concat([root.id]); child._ancestorsId = (root._ancestorsId || []).concat([root.id]);
graphData.addVertex(child); graphData.addVertex(child);
GraphUtil.createEdgesfromNode(child, graphData); createEdgesfromNode(child, graphData);
graphData.addNeighborInfo(child); graphData.addNeighborInfo(child);
} }
@ -156,23 +161,23 @@ export class GraphUtil {
* TODO Perform minimal substitution to prevent breaking gremlin query and allow \"" for now. * TODO Perform minimal substitution to prevent breaking gremlin query and allow \"" for now.
* @param value * @param value
*/ */
public static escapeDoubleQuotes(value: string): string { export function escapeDoubleQuotes(value: string): string {
return value == null ? value : value.replace(/"/g, '\\"'); return value === undefined ? value : value.replace(/"/g, '\\"');
} }
/** /**
* Surround with double-quotes if val is a string. * Surround with double-quotes if val is a string.
* @param val * @param val
*/ */
public static getQuotedPropValue(ip: ViewModels.InputPropertyValue): string { export function getQuotedPropValue(ip: ViewModels.InputPropertyValue): string {
switch (ip.type) { switch (ip.type) {
case "number": case "number":
case "boolean": case "boolean":
return `${ip.value}`; return `${ip.value}`;
case "null": case "null":
return null; return undefined;
default: default:
return `"${GraphUtil.escapeDoubleQuotes(ip.value as string)}"`; return `"${escapeDoubleQuotes(ip.value as string)}"`;
} }
} }
@ -180,7 +185,6 @@ export class GraphUtil {
* TODO Perform minimal substitution to prevent breaking gremlin query and allow \' for now. * TODO Perform minimal substitution to prevent breaking gremlin query and allow \' for now.
* @param value * @param value
*/ */
public static escapeSingleQuotes(value: string): string { export function escapeSingleQuotes(value: string): string {
return value == null ? value : value.replace(/'/g, "\\'"); return value === undefined ? value : value.replace(/'/g, "\\'");
}
} }

View File

@ -5,7 +5,7 @@
import * as React from "react"; import * as React from "react";
import { GraphHighlightedNodeData, NeighborVertexBasicInfo } from "./GraphExplorer"; import { GraphHighlightedNodeData, NeighborVertexBasicInfo } from "./GraphExplorer";
import { GraphUtil } from "./GraphUtil"; import * as GraphUtil from "./GraphUtil";
import { AccessibleElement } from "../../Controls/AccessibleElement/AccessibleElement"; import { AccessibleElement } from "../../Controls/AccessibleElement/AccessibleElement";
export interface ReadOnlyNeighborsComponentProps { export interface ReadOnlyNeighborsComponentProps {

View File

@ -1,4 +1,4 @@
import { StringUtils } from "../../../../../Utils/StringUtils"; import * as StringUtils from "../../../../../Utils/StringUtils";
import { actions, AppState, ContentRef, selectors } from "@nteract/core"; import { actions, AppState, ContentRef, selectors } from "@nteract/core";
import { IMonacoProps as MonacoEditorProps } from "@nteract/monaco-editor"; import { IMonacoProps as MonacoEditorProps } from "@nteract/monaco-editor";
import * as React from "react"; import * as React from "react";

View File

@ -1,6 +1,6 @@
import * as DataModels from "../../Contracts/DataModels"; import * as DataModels from "../../Contracts/DataModels";
import { NotebookContentItem, NotebookContentItemType } from "./NotebookContentItem"; import { NotebookContentItem, NotebookContentItemType } from "./NotebookContentItem";
import { StringUtils } from "../../Utils/StringUtils"; import * as StringUtils from "../../Utils/StringUtils";
import { FileSystemUtil } from "./FileSystemUtil"; import { FileSystemUtil } from "./FileSystemUtil";
import * as NotebookUtil from "./NotebookUtil"; import * as NotebookUtil from "./NotebookUtil";

View File

@ -1,7 +1,7 @@
import path from "path"; import path from "path";
import { ImmutableNotebook, ImmutableCodeCell } from "@nteract/commutable"; import { ImmutableNotebook, ImmutableCodeCell } from "@nteract/commutable";
import { NotebookContentItem, NotebookContentItemType } from "./NotebookContentItem"; import { NotebookContentItem, NotebookContentItemType } from "./NotebookContentItem";
import { StringUtils } from "../../Utils/StringUtils"; import * as StringUtils from "../../Utils/StringUtils";
import * as GitHubUtils from "../../Utils/GitHubUtils"; import * as GitHubUtils from "../../Utils/GitHubUtils";
// Must match rx-jupyter' FileType // Must match rx-jupyter' FileType

View File

@ -6,7 +6,7 @@ import { IPinnedRepo, JunoClient } from "../../Juno/JunoClient";
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import * as GitHubUtils from "../../Utils/GitHubUtils"; import * as GitHubUtils from "../../Utils/GitHubUtils";
import { JunoUtils } from "../../Utils/JunoUtils"; import * as JunoUtils from "../../Utils/JunoUtils";
import { AuthorizeAccessComponent } from "../Controls/GitHub/AuthorizeAccessComponent"; import { AuthorizeAccessComponent } from "../Controls/GitHub/AuthorizeAccessComponent";
import { GitHubReposComponent, GitHubReposComponentProps, RepoListItem } from "../Controls/GitHub/GitHubReposComponent"; import { GitHubReposComponent, GitHubReposComponentProps, RepoListItem } from "../Controls/GitHub/GitHubReposComponent";
import { GitHubReposComponentAdapter } from "../Controls/GitHub/GitHubReposComponentAdapter"; import { GitHubReposComponentAdapter } from "../Controls/GitHub/GitHubReposComponentAdapter";

View File

@ -37,23 +37,6 @@ export function containItems<T>(items: T[]): boolean {
return items && items.length > 0; return items && items.length > 0;
} }
// export function setTargetIcon(idToIconHandlerMap: CloudHub.Common.IToolbarElementIdIconMap, $sourceElement: JQuery, toIconState: IconState): void {
// if (idToIconHandlerMap) {
// var iconId: string = $sourceElement.attr("id");
// var iconHandler = idToIconHandlerMap[iconId];
// switch (toIconState) {
// case IconState.default:
// iconHandler.observable(iconHandler.default);
// break;
// case IconState.hoverState:
// iconHandler.observable(iconHandler.hoverState);
// break;
// default:
// window.console.log("error");
// }
// }
// }
export function addCssClass($sourceElement: JQuery, cssClassName: string): void { export function addCssClass($sourceElement: JQuery, cssClassName: string): void {
if (!$sourceElement.hasClass(cssClassName)) { if (!$sourceElement.hasClass(cssClassName)) {
$sourceElement.addClass(cssClassName); $sourceElement.addClass(cssClassName);
@ -78,8 +61,9 @@ export function getPropertyIntersectionFromTableEntities(
entities: Entities.ITableEntity[], entities: Entities.ITableEntity[],
isCassandraApi: boolean isCassandraApi: boolean
): string[] { ): string[] {
var headerUnion: string[] = []; const headerUnion: string[] = [];
entities && entities &&
// eslint-disable-next-line @typescript-eslint/no-explicit-any
entities.forEach((row: any) => { entities.forEach((row: any) => {
const keys = Object.keys(row); const keys = Object.keys(row);
keys && keys &&

View File

@ -2,26 +2,26 @@ const epochTicks = 621355968000000000;
const ticksPerMillisecond = 10000; const ticksPerMillisecond = 10000;
export function getLocalDateTime(dateTime: string): string { export function getLocalDateTime(dateTime: string): string {
var dateTimeObject: Date = new Date(dateTime); const dateTimeObject: Date = new Date(dateTime);
var year: number = dateTimeObject.getFullYear(); const year: number = dateTimeObject.getFullYear();
var month: string = ensureDoubleDigits(dateTimeObject.getMonth() + 1); // Month ranges from 0 to 11 const month: string = ensureDoubleDigits(dateTimeObject.getMonth() + 1); // Month ranges from 0 to 11
var day: string = ensureDoubleDigits(dateTimeObject.getDate()); const day: string = ensureDoubleDigits(dateTimeObject.getDate());
var hours: string = ensureDoubleDigits(dateTimeObject.getHours()); const hours: string = ensureDoubleDigits(dateTimeObject.getHours());
var minutes: string = ensureDoubleDigits(dateTimeObject.getMinutes()); const minutes: string = ensureDoubleDigits(dateTimeObject.getMinutes());
var seconds: string = ensureDoubleDigits(dateTimeObject.getSeconds()); const seconds: string = ensureDoubleDigits(dateTimeObject.getSeconds());
var milliseconds: string = ensureTripleDigits(dateTimeObject.getMilliseconds()); const milliseconds: string = ensureTripleDigits(dateTimeObject.getMilliseconds());
var localDateTime: string = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`; const localDateTime = `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}`;
return localDateTime; return localDateTime;
} }
export function getUTCDateTime(dateTime: string): string { export function getUTCDateTime(dateTime: string): string {
var dateTimeObject: Date = new Date(dateTime); const dateTimeObject = new Date(dateTime);
return dateTimeObject.toISOString(); return dateTimeObject.toISOString();
} }
export function ensureDoubleDigits(num: number): string { export function ensureDoubleDigits(num: number): string {
var doubleDigitsString: string = num.toString(); let doubleDigitsString: string = num.toString();
if (num < 10) { if (num < 10) {
doubleDigitsString = `0${doubleDigitsString}`; doubleDigitsString = `0${doubleDigitsString}`;
} else if (num > 99) { } else if (num > 99) {
@ -31,7 +31,7 @@ export function ensureDoubleDigits(num: number): string {
} }
export function ensureTripleDigits(num: number): string { export function ensureTripleDigits(num: number): string {
var tripleDigitsString: string = num.toString(); let tripleDigitsString: string = num.toString();
if (num < 10) { if (num < 10) {
tripleDigitsString = `00${tripleDigitsString}`; tripleDigitsString = `00${tripleDigitsString}`;
} else if (num < 100) { } else if (num < 100) {
@ -51,17 +51,17 @@ export function convertJSDateToUnix(dateTime: string): number {
} }
export function convertTicksToJSDate(ticks: string): Date { export function convertTicksToJSDate(ticks: string): Date {
var ticksJSBased = Number(ticks) - epochTicks; const ticksJSBased = Number(ticks) - epochTicks;
var timeInMillisecond = ticksJSBased / ticksPerMillisecond; const timeInMillisecond = ticksJSBased / ticksPerMillisecond;
return new Date(timeInMillisecond); return new Date(timeInMillisecond);
} }
export function convertJSDateToTicksWithPadding(dateTime: string): string { export function convertJSDateToTicksWithPadding(dateTime: string): string {
var ticks = epochTicks + new Date(dateTime).getTime() * ticksPerMillisecond; const ticks = epochTicks + new Date(dateTime).getTime() * ticksPerMillisecond;
return padDateTicksWithZeros(ticks.toString()); return padDateTicksWithZeros(ticks.toString());
} }
function padDateTicksWithZeros(value: string): string { function padDateTicksWithZeros(value: string): string {
var s = "0000000000000000000" + value; const s = "0000000000000000000" + value;
return s.substr(s.length - 20); return s.substr(s.length - 20);
} }

View File

@ -7,7 +7,7 @@ import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstan
import { RouteHandler } from "../../RouteHandlers/RouteHandler"; import { RouteHandler } from "../../RouteHandlers/RouteHandler";
import { WaitsForTemplateViewModel } from "../WaitsForTemplateViewModel"; import { WaitsForTemplateViewModel } from "../WaitsForTemplateViewModel";
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import ThemeUtility from "../../Common/ThemeUtility"; import * as ThemeUtility from "../../Common/ThemeUtility";
import Explorer from "../Explorer"; import Explorer from "../Explorer";
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent"; import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";

View File

@ -1,9 +1,7 @@
import * as Constants from "../Common/Constants"; import * as Constants from "../Common/Constants";
import * as AuthorizationUtils from "./AuthorizationUtils"; import * as AuthorizationUtils from "./AuthorizationUtils";
import { AuthType } from "../AuthType"; import { AuthType } from "../AuthType";
import Explorer from "../Explorer/Explorer";
import { updateUserContext } from "../UserContext"; import { updateUserContext } from "../UserContext";
import { Platform, updateConfigContext } from "../ConfigContext";
jest.mock("../Explorer/Explorer"); jest.mock("../Explorer/Explorer");
describe("AuthorizationUtils", () => { describe("AuthorizationUtils", () => {
@ -34,10 +32,6 @@ describe("AuthorizationUtils", () => {
expect(() => AuthorizationUtils.decryptJWTToken(undefined)).toThrowError(); expect(() => AuthorizationUtils.decryptJWTToken(undefined)).toThrowError();
}); });
it("should throw an error if token is null", () => {
expect(() => AuthorizationUtils.decryptJWTToken(null)).toThrowError();
});
it("should throw an error if token is empty", () => { it("should throw an error if token is empty", () => {
expect(() => AuthorizationUtils.decryptJWTToken("")).toThrowError(); expect(() => AuthorizationUtils.decryptJWTToken("")).toThrowError();
}); });

View File

@ -1,7 +1,6 @@
import { AuthType } from "../AuthType"; import { AuthType } from "../AuthType";
import * as Constants from "../Common/Constants"; import * as Constants from "../Common/Constants";
import * as Logger from "../Common/Logger"; import * as Logger from "../Common/Logger";
import { configContext, Platform } from "../ConfigContext";
import * as ViewModels from "../Contracts/ViewModels"; import * as ViewModels from "../Contracts/ViewModels";
import { userContext } from "../UserContext"; import { userContext } from "../UserContext";

View File

@ -1,6 +1,6 @@
import { RepoListItem } from "../Explorer/Controls/GitHub/GitHubReposComponent"; import { RepoListItem } from "../Explorer/Controls/GitHub/GitHubReposComponent";
import { IPinnedRepo } from "../Juno/JunoClient"; import { IPinnedRepo } from "../Juno/JunoClient";
import { JunoUtils } from "./JunoUtils"; import * as JunoUtils from "./JunoUtils";
import { IGitHubRepo } from "../GitHub/GitHubClient"; import { IGitHubRepo } from "../GitHub/GitHubClient";
const gitHubRepo: IGitHubRepo = { const gitHubRepo: IGitHubRepo = {

View File

@ -2,8 +2,7 @@ import { RepoListItem } from "../Explorer/Controls/GitHub/GitHubReposComponent";
import { IGitHubRepo } from "../GitHub/GitHubClient"; import { IGitHubRepo } from "../GitHub/GitHubClient";
import { IPinnedRepo } from "../Juno/JunoClient"; import { IPinnedRepo } from "../Juno/JunoClient";
export class JunoUtils { export function toPinnedRepo(item: RepoListItem): IPinnedRepo {
public static toPinnedRepo(item: RepoListItem): IPinnedRepo {
return { return {
owner: item.repo.owner, owner: item.repo.owner,
name: item.repo.name, name: item.repo.name,
@ -12,11 +11,10 @@ export class JunoUtils {
}; };
} }
public static toGitHubRepo(pinnedRepo: IPinnedRepo): IGitHubRepo { export function toGitHubRepo(pinnedRepo: IPinnedRepo): IGitHubRepo {
return { return {
owner: pinnedRepo.owner, owner: pinnedRepo.owner,
name: pinnedRepo.name, name: pinnedRepo.name,
private: pinnedRepo.private, private: pinnedRepo.private,
}; };
} }
}

View File

@ -1,4 +1,4 @@
import { StringUtils } from "./StringUtils"; import * as StringUtils from "./StringUtils";
describe("StringUtils", () => { describe("StringUtils", () => {
describe("stripSpacesFromString()", () => { describe("stripSpacesFromString()", () => {
@ -12,9 +12,9 @@ describe("StringUtils", () => {
expect(transformedString).toBe("abc"); expect(transformedString).toBe("abc");
}); });
it("should return null if input is null", () => { it("should return undefined if input is undefined", () => {
const transformedString: string = StringUtils.stripSpacesFromString(null); const transformedString: string = StringUtils.stripSpacesFromString(undefined);
expect(transformedString).toBeNull(); expect(transformedString).toBeUndefined();
}); });
it("should return undefined if input is undefiend", () => { it("should return undefined if input is undefiend", () => {

View File

@ -1,6 +1,5 @@
export class StringUtils { export function stripSpacesFromString(inputString: string): string {
public static stripSpacesFromString(inputString: string): string { if (inputString === undefined || typeof inputString !== "string") {
if (inputString == null || typeof inputString !== "string") {
return inputString; return inputString;
} }
return inputString.replace(/ /g, ""); return inputString.replace(/ /g, "");
@ -11,11 +10,10 @@ export class StringUtils {
* @param stringToTest * @param stringToTest
* @param suffix * @param suffix
*/ */
public static endsWith(stringToTest: string, suffix: string): boolean { export function endsWith(stringToTest: string, suffix: string): boolean {
return stringToTest.indexOf(suffix, stringToTest.length - suffix.length) !== -1; return stringToTest.indexOf(suffix, stringToTest.length - suffix.length) !== -1;
} }
public static startsWith(stringToTest: string, prefix: string): boolean { export function startsWith(stringToTest: string, prefix: string): boolean {
return stringToTest.indexOf(prefix) === 0; return stringToTest.indexOf(prefix) === 0;
} }
}

View File

@ -4,7 +4,7 @@ import { createDatabase, onClickSaveButton } from "../utils/shared";
import { generateUniqueName } from "../utils/shared"; import { generateUniqueName } from "../utils/shared";
import { ApiKind } from "../../src/Contracts/DataModels"; import { ApiKind } from "../../src/Contracts/DataModels";
const LOADING_STATE_DELAY = 3000; const LOADING_STATE_DELAY = 5000;
jest.setTimeout(300000); jest.setTimeout(300000);
describe("MongoDB Index policy tests", () => { describe("MongoDB Index policy tests", () => {
@ -74,6 +74,7 @@ describe("MongoDB Index policy tests", () => {
let singleFieldIndexInserted = false, let singleFieldIndexInserted = false,
wildCardIndexInserted = false; wildCardIndexInserted = false;
await frame.waitFor("div[data-automationid='DetailsRowCell'] > span"), { visible: true }; await frame.waitFor("div[data-automationid='DetailsRowCell'] > span"), { visible: true };
await frame.waitFor(20000);
const elements = await frame.$$("div[data-automationid='DetailsRowCell'] > span"); const elements = await frame.$$("div[data-automationid='DetailsRowCell'] > span");
for (let i = 0; i < elements.length; i++) { for (let i = 0; i < elements.length; i++) {

View File

@ -3,6 +3,14 @@ import "expect-puppeteer";
import { Frame } from "puppeteer"; import { Frame } from "puppeteer";
import { generateDatabaseName, generateUniqueName } from "../utils/shared"; import { generateDatabaseName, generateUniqueName } from "../utils/shared";
import { CosmosClient, PermissionMode } from "@azure/cosmos"; import { CosmosClient, PermissionMode } from "@azure/cosmos";
import { CosmosDBManagementClient } from "@azure/arm-cosmosdb";
import * as msRestNodeAuth from "@azure/ms-rest-nodeauth";
const clientId = process.env["NOTEBOOKS_TEST_RUNNER_CLIENT_ID"];
const secret = process.env["NOTEBOOKS_TEST_RUNNER_CLIENT_SECRET"];
const tenantId = "72f988bf-86f1-41af-91ab-2d7cd011db47";
const subscriptionId = "69e02f2d-f059-4409-9eac-97e8a276ae2c";
const resourceGroupName = "runners";
jest.setTimeout(300000); jest.setTimeout(300000);
const RETRY_DELAY = 5000; const RETRY_DELAY = 5000;
@ -10,11 +18,16 @@ const CREATE_DELAY = 10000;
describe("Collection Add and Delete SQL spec", () => { describe("Collection Add and Delete SQL spec", () => {
it("creates a collection", async () => { it("creates a collection", async () => {
const credentials = await msRestNodeAuth.loginWithServicePrincipalSecret(clientId, secret, tenantId);
const armClient = new CosmosDBManagementClient(credentials, subscriptionId);
const account = await armClient.databaseAccounts.get(resourceGroupName, "portal-sql-runner");
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, "portal-sql-runner");
const dbId = generateDatabaseName(); const dbId = generateDatabaseName();
const collectionId = generateUniqueName("col"); const collectionId = generateUniqueName("col");
const connectionString = process.env.PORTAL_RUNNER_CONNECTION_STRING; const client = new CosmosClient({
const client = new CosmosClient(connectionString); endpoint: account.documentEndpoint,
const endpoint = /AccountEndpoint=(.*);/.exec(connectionString)[1]; key: keys.primaryMasterKey,
});
const { database } = await client.databases.createIfNotExists({ id: dbId }); const { database } = await client.databases.createIfNotExists({ id: dbId });
const { container } = await database.containers.createIfNotExists({ id: collectionId }); const { container } = await database.containers.createIfNotExists({ id: collectionId });
const { user } = await database.users.upsert({ id: "testUser" }); const { user } = await database.users.upsert({ id: "testUser" });
@ -23,7 +36,7 @@ describe("Collection Add and Delete SQL spec", () => {
permissionMode: PermissionMode.All, permissionMode: PermissionMode.All,
resource: container.url, resource: container.url,
}); });
const resourceTokenConnectionString = `AccountEndpoint=${endpoint};DatabaseId=${database.id};CollectionId=${container.id};${containerPermission._token}`; const resourceTokenConnectionString = `AccountEndpoint=${account.documentEndpoint};DatabaseId=${database.id};CollectionId=${container.id};${containerPermission._token}`;
try { try {
await page.goto(process.env.DATA_EXPLORER_ENDPOINT); await page.goto(process.env.DATA_EXPLORER_ENDPOINT);
await page.waitFor("div > p.switchConnectTypeText", { visible: true }); await page.waitFor("div > p.switchConnectTypeText", { visible: true });

View File

@ -30,7 +30,7 @@ export function generateDatabaseName(baseName = "db", length = 1): string {
return `${baseName}${crypto.randomBytes(length).toString("hex")}-${Date.now()}`; return `${baseName}${crypto.randomBytes(length).toString("hex")}-${Date.now()}`;
} }
export async function createDatabase(frame: Frame) { export async function createDatabase(frame: Frame): Promise<string> {
const dbId = generateDatabaseName(); const dbId = generateDatabaseName();
const collectionId = generateUniqueName("col"); const collectionId = generateUniqueName("col");
const shardKey = "partitionKey"; const shardKey = "partitionKey";
@ -70,7 +70,7 @@ export async function createDatabase(frame: Frame) {
return dbId; return dbId;
} }
export async function onClickSaveButton(frame: Frame) { export async function onClickSaveButton(frame: Frame): Promise<void> {
await frame.waitFor(`button[data-test="Save"]`), { visible: true }; await frame.waitFor(`button[data-test="Save"]`), { visible: true };
await frame.waitFor(LOADING_STATE_DELAY); await frame.waitFor(LOADING_STATE_DELAY);
await frame.click(`button[data-test="Save"]`); await frame.click(`button[data-test="Save"]`);