Compare commits

..

3 Commits

Author SHA1 Message Date
sunilyadav840
bd1009c849 fixed eslint of ConflictsTab 2021-10-20 14:13:47 +05:30
victor-meng
55837db65b Revert "Fix keyboard focus does not retain on 'New Database' button a… (#1139)
* Revert "Fix keyboard focus does not retain on 'New Database' button after closing the 'New Database' blade via ESC key (#1109)"

This reverts commit f7e7240010.

* Revert "Fix ally database panel open issue (#1120)"

This reverts commit ed1ffb692f.
2021-10-15 17:36:48 -07:00
victor-meng
9f27cb95b9 Only use the SET keyword once in the update query (#1138) 2021-10-15 12:33:59 -07:00
8 changed files with 55 additions and 59 deletions

View File

@@ -87,13 +87,16 @@ src/Explorer/Tables/QueryBuilder/CustomTimestampHelper.ts
src/Explorer/Tables/TableDataClient.ts
src/Explorer/Tables/TableEntityProcessor.ts
src/Explorer/Tables/Utilities.ts
src/Explorer/Tabs/ConflictsTab.ts
src/Explorer/Tabs/DatabaseSettingsTab.ts
src/Explorer/Tabs/DocumentsTab.test.ts
src/Explorer/Tabs/DocumentsTab.ts
src/Explorer/Tabs/GraphTab.ts
src/Explorer/Tabs/MongoDocumentsTab.ts
src/Explorer/Tabs/NotebookV2Tab.ts
src/Explorer/Tabs/ScriptTabBase.ts
src/Explorer/Tabs/TabComponents.ts
src/Explorer/Tabs/TabsBase.ts
src/Explorer/Tabs/TriggerTab.ts
src/Explorer/Tabs/UserDefinedFunctionTab.ts
src/Explorer/Tree/AccessibleVerticalList.ts
src/Explorer/Tree/Collection.ts

View File

@@ -307,18 +307,11 @@ function createOpenSynapseLinkDialogButton(container: Explorer): CommandButtonCo
function createNewDatabase(container: Explorer): CommandButtonComponentProps {
const label = "New " + getDatabaseName();
const newDatabaseButton = document.activeElement as HTMLElement;
return {
iconSrc: AddDatabaseIcon,
iconAlt: label,
onCommandClick: () =>
useSidePanel
.getState()
.openSidePanel(
"New " + getDatabaseName(),
<AddDatabasePanel explorer={container} buttonElement={newDatabaseButton} />
),
useSidePanel.getState().openSidePanel("New " + getDatabaseName(), <AddDatabasePanel explorer={container} />),
commandButtonLabel: label,
ariaLabel: label,
hasPopup: true,

View File

@@ -23,12 +23,10 @@ import { RightPaneForm, RightPaneFormProps } from "../RightPaneForm/RightPaneFor
export interface AddDatabasePaneProps {
explorer: Explorer;
buttonElement?: HTMLElement;
}
export const AddDatabasePanel: FunctionComponent<AddDatabasePaneProps> = ({
explorer: container,
buttonElement,
}: AddDatabasePaneProps) => {
const closeSidePanel = useSidePanel((state) => state.closeSidePanel);
let throughput: number;
@@ -79,7 +77,6 @@ export const AddDatabasePanel: FunctionComponent<AddDatabasePaneProps> = ({
dataExplorerArea: Constants.Areas.ContextualPane,
};
TelemetryProcessor.trace(Action.CreateDatabase, ActionModifiers.Open, addDatabasePaneOpenMessage);
buttonElement.focus();
}, []);
const onSubmit = () => {

View File

@@ -307,23 +307,16 @@ export class SplashScreen extends React.Component<SplashScreenProps> {
iconSrc: AddDatabaseIcon,
title: "New " + getDatabaseName(),
description: undefined,
onClick: () => this.openAddDatabasePanel(),
onClick: () =>
useSidePanel
.getState()
.openSidePanel("New " + getDatabaseName(), <AddDatabasePanel explorer={this.container} />),
});
}
return items;
}
private openAddDatabasePanel() {
const newDatabaseButton = document.activeElement as HTMLElement;
useSidePanel
.getState()
.openSidePanel(
"New " + getDatabaseName(),
<AddDatabasePanel explorer={this.container} buttonElement={newDatabaseButton} />
);
}
private decorateOpenCollectionActivity({ databaseId, collectionId }: MostRecentActivity.OpenCollectionItem) {
return {
iconSrc: NotebookIcon,

View File

@@ -202,14 +202,21 @@ export class CassandraAPIDataClient extends TableDataClient {
let updateQuery = `UPDATE ${collection.databaseId}.${collection.id()}`;
let isPropertyUpdated = false;
let isFirstPropertyToUpdate = true;
for (let property in newEntity) {
if (
!originalDocument[property] ||
newEntity[property]._.toString() !== originalDocument[property]._.toString()
) {
updateQuery += this.isStringType(newEntity[property].$)
? ` SET ${property} = '${newEntity[property]._}',`
: ` SET ${property} = ${newEntity[property]._},`;
let propertyQuerySegment = this.isStringType(newEntity[property].$)
? `${property} = '${newEntity[property]._}',`
: `${property} = ${newEntity[property]._},`;
// Only add the "SET" keyword once
if (isFirstPropertyToUpdate) {
propertyQuerySegment = " SET " + propertyQuerySegment;
isFirstPropertyToUpdate = false;
}
updateQuery += propertyQuerySegment;
isPropertyUpdated = true;
}
}

View File

@@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/switch-exhaustiveness-check */
import { ConflictDefinition, FeedOptions, QueryIterator, Resource } from "@azure/cosmos";
import * as ko from "knockout";
import Q from "q";
@@ -69,13 +71,13 @@ export default class ConflictsTab extends TabsBase {
ViewModels.DocumentExplorerState.noDocumentSelected
);
this.selectedConflictId = ko.observable<ConflictId>();
this.selectedConflictContent = editable.observable<any>("");
this.selectedConflictCurrent = editable.observable<any>("");
this.selectedConflictContent = editable.observable<string>("");
this.selectedConflictCurrent = editable.observable<string>("");
this.partitionKey = options.partitionKey || (this.collection && this.collection.partitionKey);
this.conflictIds = options.conflictIds;
this.partitionKeyPropertyHeader =
(this.collection && this.collection.partitionKeyPropertyHeader) || this._getPartitionKeyPropertyHeader();
this.partitionKeyProperty = !!this.partitionKeyPropertyHeader
this.partitionKeyProperty = this.partitionKeyPropertyHeader
? this.partitionKeyPropertyHeader.replace(/[/]+/g, ".").substr(1).replace(/[']+/g, "")
: null;
@@ -187,7 +189,7 @@ export default class ConflictsTab extends TabsBase {
this.buildCommandBarOptions();
this.shouldShowDiffEditor = ko.pureComputed<boolean>(() => {
const documentHasContent: boolean =
this.selectedConflictContent() != null && this.selectedConflictContent().length > 0;
this.selectedConflictContent() !== null && this.selectedConflictContent().length > 0;
const operationIsReplace: boolean = this.conflictOperation() === Constants.ConflictOperationType.Replace;
const isLoadingData: boolean = this.loadingConflictData();
return documentHasContent && operationIsReplace && !isLoadingData;
@@ -195,7 +197,7 @@ export default class ConflictsTab extends TabsBase {
this.shouldShowEditor = ko.pureComputed<boolean>(() => {
const documentHasContent: boolean =
this.selectedConflictContent() != null && this.selectedConflictContent().length > 0;
this.selectedConflictContent() !== null && this.selectedConflictContent().length > 0;
const operationIsInsert: boolean = this.conflictOperation() === Constants.ConflictOperationType.Create;
const operationIsDelete: boolean = this.conflictOperation() === Constants.ConflictOperationType.Delete;
const isLoadingData: boolean = this.loadingConflictData();
@@ -242,7 +244,7 @@ export default class ConflictsTab extends TabsBase {
return true;
};
public onConflictIdClick(clickedDocumentId: ConflictId): Q.Promise<any> {
public onConflictIdClick(): Q.Promise<unknown> {
if (this.editorState() !== ViewModels.DocumentExplorerState.noDocumentSelected) {
return Q();
}
@@ -405,19 +407,19 @@ export default class ConflictsTab extends TabsBase {
}
};
public onDiscardClick = (): Q.Promise<any> => {
public onDiscardClick = (): Q.Promise<unknown> => {
this.selectedConflictContent(this.selectedConflictContent.getEditableOriginalValue());
this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits);
return Q();
};
public onValidDocumentEdit(): Q.Promise<any> {
public onValidDocumentEdit(): Q.Promise<unknown> {
this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid);
return Q();
}
public onInvalidDocumentEdit(): Q.Promise<any> {
public onInvalidDocumentEdit(): Q.Promise<unknown> {
if (
this.editorState() === ViewModels.DocumentExplorerState.exisitingDocumentNoEdits ||
this.editorState() === ViewModels.DocumentExplorerState.exisitingDocumentDirtyValid
@@ -442,7 +444,7 @@ export default class ConflictsTab extends TabsBase {
this._documentsIterator = await this.createIterator();
await this.loadNextPage();
} catch (error) {
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) {
if (this.onLoadStartKey !== null && this.onLoadStartKey !== undefined) {
TelemetryProcessor.traceFailure(
Action.Tab,
{
@@ -471,7 +473,7 @@ export default class ConflictsTab extends TabsBase {
return queryConflicts(this.collection.databaseId, this.collection.id(), query, options as FeedOptions);
}
public loadNextPage(): Q.Promise<any> {
public loadNextPage(): Q.Promise<unknown> {
this.isExecuting(true);
this.isExecutionError(false);
return this._loadNextPageInternal()
@@ -491,7 +493,7 @@ export default class ConflictsTab extends TabsBase {
const merged = currentConflicts.concat(nextConflictIds);
this.conflictIds(merged);
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) {
if (this.onLoadStartKey !== null && this.onLoadStartKey !== undefined) {
TelemetryProcessor.traceSuccess(
Action.Tab,
{
@@ -508,7 +510,7 @@ export default class ConflictsTab extends TabsBase {
},
(error) => {
this.isExecutionError(true);
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) {
if (this.onLoadStartKey !== null && this.onLoadStartKey !== undefined) {
TelemetryProcessor.traceFailure(
Action.Tab,
{
@@ -541,18 +543,18 @@ export default class ConflictsTab extends TabsBase {
return Q(this._documentsIterator.fetchNext().then((response) => response.resources));
}
protected _onEditorContentChange(newContent: string) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
protected _onEditorContentChange(_newContent: string) {
try {
const parsed: any = JSON.parse(newContent);
this.onValidDocumentEdit();
} catch (e) {
this.onInvalidDocumentEdit();
}
}
public initDocumentEditorForCreate(documentId: ConflictId, documentToInsert: any): Q.Promise<any> {
public initDocumentEditorForCreate(documentId: ConflictId, documentToInsert: any): Q.Promise<unknown> {
if (documentId) {
let parsedConflictContent: any = JSON.parse(documentToInsert);
const parsedConflictContent: any = JSON.parse(documentToInsert);
const renderedConflictContent: string = this.renderObjectForEditor(parsedConflictContent, null, 4);
this.selectedConflictContent.setBaseline(renderedConflictContent);
this.editorState(ViewModels.DocumentExplorerState.exisitingDocumentNoEdits);
@@ -565,7 +567,7 @@ export default class ConflictsTab extends TabsBase {
documentId: ConflictId,
conflictContent: any,
currentContent: any
): Q.Promise<any> {
): Q.Promise<unknown> {
if (documentId) {
currentContent = ConflictsTab.removeSystemProperties(currentContent);
const renderedCurrentContent: string = this.renderObjectForEditor(currentContent, null, 4);
@@ -582,7 +584,7 @@ export default class ConflictsTab extends TabsBase {
return Q();
}
public initDocumentEditorForDelete(documentId: ConflictId, documentToDelete: any): Q.Promise<any> {
public initDocumentEditorForDelete(documentId: ConflictId, documentToDelete: any): Q.Promise<unknown> {
if (documentId) {
let parsedDocumentToDelete: any = JSON.parse(documentToDelete);
parsedDocumentToDelete = ConflictsTab.removeSystemProperties(parsedDocumentToDelete);
@@ -594,7 +596,8 @@ export default class ConflictsTab extends TabsBase {
return Q();
}
public initDocumentEditorForNoOp(documentId: ConflictId): Q.Promise<any> {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public initDocumentEditorForNoOp(_documentId: ConflictId): Q.Promise<unknown> {
this.selectedConflictContent(null);
this.selectedConflictCurrent(null);
this.editorState(ViewModels.DocumentExplorerState.noDocumentSelected);

View File

@@ -54,7 +54,7 @@ export default class NotebookTabV2 extends NotebookTabBase {
});
}
public onCloseTabButtonClick(): Q.Promise<void> {
public onCloseTabButtonClick(): Q.Promise<any> {
const cleanup = () => {
this.notebookComponentAdapter.notebookShutdown();
super.onCloseTabButtonClick();
@@ -78,7 +78,7 @@ export default class NotebookTabV2 extends NotebookTabBase {
}
}
public async reconfigureServiceEndpoints(): Promise<void> {
public async reconfigureServiceEndpoints() {
if (!this.notebookComponentAdapter) {
return;
}
@@ -136,7 +136,7 @@ export default class NotebookTabV2 extends NotebookTabBase {
ariaLabel: publishLabel,
});
const buttons: CommandButtonComponentProps[] = [
let buttons: CommandButtonComponentProps[] = [
{
iconSrc: SaveIcon,
iconAlt: saveLabel,
@@ -160,7 +160,7 @@ export default class NotebookTabV2 extends NotebookTabBase {
{
iconSrc: null,
iconAlt: kernelLabel,
onCommandClick: () => undefined,
onCommandClick: () => {},
commandButtonLabel: null,
hasPopup: false,
disabled: availableKernels.length < 1,
@@ -271,7 +271,7 @@ export default class NotebookTabV2 extends NotebookTabBase {
{
iconSrc: null,
iconAlt: null,
onCommandClick: () => undefined,
onCommandClick: () => {},
commandButtonLabel: null,
ariaLabel: cellTypeLabel,
hasPopup: false,
@@ -361,7 +361,7 @@ export default class NotebookTabV2 extends NotebookTabBase {
}
private onKernelUpdate = async () => {
await this.configureServiceEndpoints(this.notebookComponentAdapter.getCurrentKernelName()).catch(() => {
await this.configureServiceEndpoints(this.notebookComponentAdapter.getCurrentKernelName()).catch((reason) => {
/* Erroring is ok here */
});
this.updateNavbarWithTabsButtons();

View File

@@ -25,12 +25,11 @@ export default abstract class ScriptTabBase extends TabsBase implements ViewMode
public errors: ko.ObservableArray<ViewModels.QueryError>;
public statusMessge: ko.Observable<string>;
public statusIcon: ko.Observable<string>;
public formFields: ko.ObservableArray<ViewModels.Editable<unknown>>;
public formFields: ko.ObservableArray<ViewModels.Editable<any>>;
public formIsValid: ko.Computed<boolean>;
public formIsDirty: ko.Computed<boolean>;
public isNew: ko.Observable<boolean>;
// TODO: Remove any. The SDK types for all the script.body are slightly incorrect which makes this REALLY hard to type correct.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public resource: ko.Observable<any>;
public isTemplateReady: ko.Observable<boolean>;
protected _partitionKey: DataModels.PartitionKey;
@@ -86,6 +85,7 @@ export default abstract class ScriptTabBase extends TabsBase implements ViewMode
this.editorState(ViewModels.ScriptEditorState.exisitingDirtyInvalid);
}
break;
case ViewModels.ScriptEditorState.exisitingDirtyValid:
default:
break;
}
@@ -182,7 +182,7 @@ export default abstract class ScriptTabBase extends TabsBase implements ViewMode
this.editorContent.setBaseline(resource.body);
}
public setBaselines(): void {
public setBaselines() {
this._setBaselines();
}
@@ -194,9 +194,9 @@ export default abstract class ScriptTabBase extends TabsBase implements ViewMode
}
public abstract onSaveClick: () => void;
public abstract onUpdateClick: () => Promise<void>;
public abstract onUpdateClick: () => Promise<any>;
public onDiscard = (): Q.Promise<void> => {
public onDiscard = (): Q.Promise<any> => {
this.setBaselines();
const original = this.editorContent.getEditableOriginalValue();
const editorModel = this.editor() && this.editor().getModel();
@@ -289,7 +289,7 @@ export default abstract class ScriptTabBase extends TabsBase implements ViewMode
return !!value;
}
protected async _createBodyEditor(): Promise<void> {
protected async _createBodyEditor() {
const id = this.editorId;
const container = document.getElementById(id);
const options = {
@@ -308,7 +308,7 @@ export default abstract class ScriptTabBase extends TabsBase implements ViewMode
editorModel.onDidChangeContent(this._onBodyContentChange.bind(this));
}
private _onBodyContentChange() {
private _onBodyContentChange(e: monaco.editor.IModelContentChangedEvent) {
const editorModel = this.editor().getModel();
this.editorContent(editorModel.getValue());
}