Compare commits

..

1 Commits

Author SHA1 Message Date
vaidankarswapnil
25c46ad504 Fix eslint issues for DataTableOperationManager and CustomTimestampHelper 2021-10-13 12:49:59 +05:30
11 changed files with 129 additions and 121 deletions

View File

@@ -42,6 +42,8 @@ src/Explorer/Controls/Editor/EditorComponent.ts
src/Explorer/Controls/JsonEditor/JsonEditorComponent.ts
src/Explorer/DataSamples/ContainerSampleGenerator.test.ts
src/Explorer/DataSamples/ContainerSampleGenerator.ts
src/Explorer/DataSamples/DataSamplesUtil.test.ts
src/Explorer/DataSamples/DataSamplesUtil.ts
src/Explorer/Graph/GraphExplorerComponent/ArraysByKeyCache.test.ts
src/Explorer/Graph/GraphExplorerComponent/ArraysByKeyCache.ts
src/Explorer/Graph/GraphExplorerComponent/D3ForceGraph.test.ts
@@ -52,6 +54,8 @@ src/Explorer/Graph/GraphExplorerComponent/GraphData.ts
src/Explorer/Graph/GraphExplorerComponent/GremlinClient.test.ts
src/Explorer/Graph/GraphExplorerComponent/GremlinClient.ts
src/Explorer/Graph/GraphExplorerComponent/GremlinSimpleClient.test.ts
src/Explorer/Graph/GraphExplorerComponent/GremlinSimpleClient.ts
src/Explorer/Menus/ContextMenu.ts
src/Explorer/MostRecentActivity/MostRecentActivity.ts
src/Explorer/Notebook/NotebookClientV2.ts
src/Explorer/Notebook/NotebookComponent/NotebookContentProvider.ts
@@ -60,8 +64,11 @@ src/Explorer/Notebook/NotebookComponent/actions.ts
src/Explorer/Notebook/NotebookComponent/epics.test.ts
src/Explorer/Notebook/NotebookComponent/epics.ts
src/Explorer/Notebook/NotebookComponent/loadTransform.ts
src/Explorer/Notebook/NotebookComponent/reducers.ts
src/Explorer/Notebook/NotebookComponent/store.ts
src/Explorer/Notebook/NotebookComponent/types.ts
src/Explorer/Notebook/NotebookContainerClient.ts
src/Explorer/Notebook/NotebookContentClient.ts
src/Explorer/Notebook/NotebookContentItem.ts
src/Explorer/Notebook/NotebookUtil.ts
src/Explorer/OpenActionsStubs.ts
@@ -73,10 +80,10 @@ src/Explorer/Tables/DataTable/CacheBase.ts
src/Explorer/Tables/DataTable/DataTableBindingManager.ts
src/Explorer/Tables/DataTable/DataTableBuilder.ts
src/Explorer/Tables/DataTable/DataTableContextMenu.ts
src/Explorer/Tables/DataTable/DataTableOperationManager.ts
# src/Explorer/Tables/DataTable/DataTableOperationManager.ts
src/Explorer/Tables/DataTable/DataTableViewModel.ts
src/Explorer/Tables/DataTable/TableEntityListViewModel.ts
src/Explorer/Tables/QueryBuilder/CustomTimestampHelper.ts
# src/Explorer/Tables/QueryBuilder/CustomTimestampHelper.ts
src/Explorer/Tables/TableDataClient.ts
src/Explorer/Tables/TableEntityProcessor.ts
src/Explorer/Tables/Utilities.ts

View File

@@ -19,7 +19,7 @@ describe("DataSampleUtils", () => {
const explorer = {} as Explorer;
useDatabases.getState().addDatabases([database]);
const dataSamplesUtil = new DataSamplesUtil(explorer);
//eslint-disable-next-line
const fakeGenerator = sinon.createStubInstance<ContainerSampleGenerator>(ContainerSampleGenerator as any);
fakeGenerator.getCollectionId.returns(sampleCollectionId);
fakeGenerator.getDatabaseId.returns(sampleDatabaseId);

View File

@@ -18,7 +18,6 @@ export interface GremlinSimpleClientParameters {
export interface Result {
requestId: string; // Can be null
//eslint-disable-next-line
data: any;
requestCharge: number; // RU cost
}
@@ -31,7 +30,6 @@ export interface GremlinRequestMessage {
args:
| {
gremlin: string;
//eslint-disable-next-line
bindings: {};
language: string;
}
@@ -56,7 +54,6 @@ export interface GremlinResponseMessage {
message: string;
};
result: {
//eslint-disable-next-line
data: any;
};
}
@@ -77,7 +74,7 @@ export class GremlinSimpleClient {
this.requestsToSend = {};
}
public connect(): void {
public connect() {
if (this.ws) {
if (this.ws.readyState === WebSocket.CONNECTING) {
// Wait until it connects to execute all requests
@@ -109,10 +106,9 @@ export class GremlinSimpleClient {
return new WebSocket(endpoint);
}
public close(): void {
public close() {
if (this.ws && this.ws.readyState !== WebSocket.CLOSING && this.ws.readyState !== WebSocket.CLOSED) {
const msg = `Disconnecting from ${this.params.endpoint} as ${this.params.user}`;
//eslint-disable-next-line
console.log(msg);
if (this.params.infoCallback) {
this.params.infoCallback(msg);
@@ -147,7 +143,7 @@ export class GremlinSimpleClient {
}
}
public onMessage(msg: MessageEvent): void {
public onMessage(msg: MessageEvent) {
if (!msg) {
if (this.params.failureCallback) {
this.params.failureCallback(null, "onMessage called with no message");
@@ -198,10 +194,8 @@ export class GremlinSimpleClient {
}
break;
case 407: // Request authentication
{
const challengeResponse = this.buildChallengeResponse(this.pendingRequests[requestId]);
this.sendGremlinMessage(challengeResponse);
}
const challengeResponse = this.buildChallengeResponse(this.pendingRequests[requestId]);
this.sendGremlinMessage(challengeResponse);
break;
case 401: // Unauthorized
delete this.pendingRequests[requestId];
@@ -273,7 +267,7 @@ export class GremlinSimpleClient {
}
public buildChallengeResponse(request: GremlinRequestMessage): GremlinRequestMessage {
const args = {
var args = {
SASL: GremlinSimpleClient.utf8ToB64("\0" + this.params.user + "\0" + this.params.password),
};
return {
@@ -284,9 +278,9 @@ export class GremlinSimpleClient {
};
}
public static utf8ToB64(utf8Str: string): string {
public static utf8ToB64(utf8Str: string) {
return btoa(
encodeURIComponent(utf8Str).replace(/%([0-9A-F]{2})/g, (match, p1) => {
encodeURIComponent(utf8Str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
return String.fromCharCode(parseInt(p1, 16));
})
);
@@ -297,13 +291,12 @@ export class GremlinSimpleClient {
* mimeLength + mimeType + serialized message
* @param requestMessage
*/
//eslint-disable-next-line
public static buildGremlinMessage(requestMessage: {}): Uint8Array {
const mimeType = "application/json";
const serializedMessage = mimeType + JSON.stringify(requestMessage);
let serializedMessage = mimeType + JSON.stringify(requestMessage);
const encodedMessage = new TextEncoder().encode(serializedMessage);
const binaryMessage = new Uint8Array(1 + encodedMessage.length);
let binaryMessage = new Uint8Array(1 + encodedMessage.length);
binaryMessage[0] = mimeType.length;
for (let i = 0; i < encodedMessage.length; i++) {
@@ -312,19 +305,19 @@ export class GremlinSimpleClient {
return binaryMessage;
}
private onOpen() {
private onOpen(event: any) {
this.executeRequestsToSend();
}
private executeRequestsToSend() {
for (const requestId in this.requestsToSend) {
for (let requestId in this.requestsToSend) {
const request = this.requestsToSend[requestId];
this.sendGremlinMessage(request);
this.pendingRequests[request.requestId] = request;
delete this.requestsToSend[request.requestId];
}
}
//eslint-disable-next-line
private onError(err: any) {
if (this.params.failureCallback) {
this.params.failureCallback(null, err);
@@ -346,9 +339,9 @@ export class GremlinSimpleClient {
* RFC4122 version 4 compliant UUID
*/
private static uuidv4() {
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
const r = (Math.random() * 16) | 0,
v = c === "x" ? r : (r & 0x3) | 0x8;
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = (Math.random() * 16) | 0,
v = c == "x" ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}

View File

@@ -307,11 +307,18 @@ 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} />),
useSidePanel
.getState()
.openSidePanel(
"New " + getDatabaseName(),
<AddDatabasePanel explorer={container} buttonElement={newDatabaseButton} />
),
commandButtonLabel: label,
ariaLabel: label,
hasPopup: true,

View File

@@ -50,7 +50,6 @@ export const coreReducer = (state: CoreRecord, action: Action) => {
.setIn(path.concat("language"), kernelspecs.language);
}
default:
//eslint-disable-next-line
return nteractReducers.core(state as any, action as any);
}
};

View File

@@ -228,12 +228,11 @@ export class NotebookContentClient {
public async readFileContent(filePath: string): Promise<string> {
const xhr = await this.contentProvider.get(this.getServerConfig(), filePath, { content: 1 }).toPromise();
//eslint-disable-next-line
const content = (xhr.response as any).content;
if (!content) {
throw new Error("No content read");
}
//eslint-disable-next-line
const format = (xhr.response as any).format;
switch (format) {
case "text":

View File

@@ -23,10 +23,12 @@ 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;
@@ -77,6 +79,7 @@ export const AddDatabasePanel: FunctionComponent<AddDatabasePaneProps> = ({
dataExplorerArea: Constants.Areas.ContextualPane,
};
TelemetryProcessor.trace(Action.CreateDatabase, ActionModifiers.Open, addDatabasePaneOpenMessage);
buttonElement.focus();
}, []);
const onSubmit = () => {

View File

@@ -307,16 +307,23 @@ export class SplashScreen extends React.Component<SplashScreenProps> {
iconSrc: AddDatabaseIcon,
title: "New " + getDatabaseName(),
description: undefined,
onClick: () =>
useSidePanel
.getState()
.openSidePanel("New " + getDatabaseName(), <AddDatabasePanel explorer={this.container} />),
onClick: () => this.openAddDatabasePanel(),
});
}
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

@@ -1,11 +1,10 @@
import ko from "knockout";
import * as DataTableOperations from "./DataTableOperations";
import * as Constants from "../Constants";
import * as Entities from "../Entities";
import * as Utilities from "../Utilities";
import * as DataTableOperations from "./DataTableOperations";
import TableCommands from "./TableCommands";
import TableEntityListViewModel from "./TableEntityListViewModel";
import * as Utilities from "../Utilities";
import * as Entities from "../Entities";
/*
* Base class for data table row selection.
@@ -25,7 +24,7 @@ export default class DataTableOperationManager {
}
private click = (event: JQueryEventObject) => {
var elem: JQuery = $(event.currentTarget);
const elem: JQuery = $(event.currentTarget);
this.updateLastSelectedItem(elem, event.shiftKey);
if (Utilities.isEnvironmentCtrlPressed(event)) {
@@ -37,30 +36,30 @@ export default class DataTableOperationManager {
}
};
private doubleClick = (event: JQueryEventObject) => {
private doubleClick = () => {
this.tryOpenEditor();
};
private keyDown = (event: JQueryEventObject): boolean => {
var isUpArrowKey: boolean = event.keyCode === Constants.keyCodes.UpArrow,
isDownArrowKey: boolean = event.keyCode === Constants.keyCodes.DownArrow,
handled: boolean = false;
const isUpArrowKey: boolean = event.keyCode === Constants.keyCodes.UpArrow,
isDownArrowKey: boolean = event.keyCode === Constants.keyCodes.DownArrow;
let handled = false;
if (isUpArrowKey || isDownArrowKey) {
var lastSelectedItem: Entities.ITableEntity = this._tableEntityListViewModel.lastSelectedItem;
var dataTableRows: JQuery = $(Constants.htmlSelectors.dataTableAllRowsSelector);
var maximumIndex = dataTableRows.length - 1;
const lastSelectedItem: Entities.ITableEntity = this._tableEntityListViewModel.lastSelectedItem;
const dataTableRows: JQuery = $(Constants.htmlSelectors.dataTableAllRowsSelector);
const maximumIndex = dataTableRows.length - 1;
// If can't find an index for lastSelectedItem, then either no item is previously selected or it goes across page.
// Simply select the first item in this case.
var lastSelectedItemIndex = lastSelectedItem
const lastSelectedItemIndex = lastSelectedItem
? this._tableEntityListViewModel.getItemIndexFromCurrentPage(
this._tableEntityListViewModel.getTableEntityKeys(lastSelectedItem.RowKey._)
)
: -1;
var nextIndex: number = isUpArrowKey ? lastSelectedItemIndex - 1 : lastSelectedItemIndex + 1;
var safeIndex: number = Utilities.ensureBetweenBounds(nextIndex, 0, maximumIndex);
var selectedRowElement: JQuery = dataTableRows.eq(safeIndex);
const nextIndex: number = isUpArrowKey ? lastSelectedItemIndex - 1 : lastSelectedItemIndex + 1;
const safeIndex: number = Utilities.ensureBetweenBounds(nextIndex, 0, maximumIndex);
const selectedRowElement: JQuery = dataTableRows.eq(safeIndex);
if (selectedRowElement) {
if (event.shiftKey) {
@@ -90,7 +89,7 @@ export default class DataTableOperationManager {
// in contrast, there may be more than one key down and key
// pressed events.
private keyUp = (event: JQueryEventObject): boolean => {
var handled: boolean = false;
let handled = false;
switch (event.keyCode) {
case Constants.keyCodes.Enter:
@@ -105,8 +104,9 @@ export default class DataTableOperationManager {
};
private itemDropped = (event: JQueryEventObject): boolean => {
var handled: boolean = false;
var items = (<any>event.originalEvent).dataTransfer.items;
const handled = false;
//eslint-disable-next-line
const items = (<any>event.originalEvent).dataTransfer.items;
if (!items) {
// On browsers outside of Chromium
@@ -115,9 +115,9 @@ export default class DataTableOperationManager {
return null;
}
for (var i = 0; i < items.length; i++) {
var item = items[i];
var entry = item.webkitGetAsEntry();
for (let i = 0; i < items.length; i++) {
const item = items[i];
const entry = item.webkitGetAsEntry();
if (entry.isFile) {
// TODO: parse the file and insert content as entities
@@ -132,8 +132,8 @@ export default class DataTableOperationManager {
}
private tryHandleDeleteSelected(): boolean {
var selectedEntities: Entities.ITableEntity[] = this._tableEntityListViewModel.selected();
var handled: boolean = false;
const selectedEntities: Entities.ITableEntity[] = this._tableEntityListViewModel.selected();
let handled = false;
if (selectedEntities && selectedEntities.length) {
this._tableCommands.deleteEntitiesCommand(this._tableEntityListViewModel);
@@ -150,8 +150,8 @@ export default class DataTableOperationManager {
}
private updateLastSelectedItem($elem: JQuery, isShiftSelect: boolean) {
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
var entity = this._tableEntityListViewModel.getItemFromCurrentPage(
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
const entity = this._tableEntityListViewModel.getItemFromCurrentPage(
this._tableEntityListViewModel.getTableEntityKeys(entityIdentity.RowKey)
);
@@ -164,7 +164,7 @@ export default class DataTableOperationManager {
private applySingleSelection($elem: JQuery) {
if ($elem) {
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
this._tableEntityListViewModel.clearSelection();
this.addToSelection(entityIdentity.RowKey);
@@ -180,12 +180,12 @@ export default class DataTableOperationManager {
}
private applyCtrlSelection($elem: JQuery): void {
var koSelected: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
const koSelected: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
? this._tableEntityListViewModel.selected
: null;
if (koSelected) {
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
if (
!this._tableEntityListViewModel.isItemSelected(
@@ -201,7 +201,7 @@ export default class DataTableOperationManager {
}
private applyShiftSelection($elem: JQuery): void {
var anchorItem = this._tableEntityListViewModel.lastSelectedAnchorItem;
let anchorItem = this._tableEntityListViewModel.lastSelectedAnchorItem;
// If anchor item doesn't exist, use the first available item of current page instead
if (!anchorItem && this._tableEntityListViewModel.items().length > 0) {
@@ -209,16 +209,16 @@ export default class DataTableOperationManager {
}
if (anchorItem) {
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
var elementIndex = this._tableEntityListViewModel.getItemIndexFromAllPages(
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
const elementIndex = this._tableEntityListViewModel.getItemIndexFromAllPages(
this._tableEntityListViewModel.getTableEntityKeys(entityIdentity.RowKey)
);
var anchorIndex = this._tableEntityListViewModel.getItemIndexFromAllPages(
const anchorIndex = this._tableEntityListViewModel.getItemIndexFromAllPages(
this._tableEntityListViewModel.getTableEntityKeys(anchorItem.RowKey._)
);
var startIndex = Math.min(elementIndex, anchorIndex);
var endIndex = Math.max(elementIndex, anchorIndex);
const startIndex = Math.min(elementIndex, anchorIndex);
const endIndex = Math.max(elementIndex, anchorIndex);
this._tableEntityListViewModel.clearSelection();
ko.utils.arrayPushAll<Entities.ITableEntity>(
@@ -229,7 +229,7 @@ export default class DataTableOperationManager {
}
private applyContextMenuSelection($elem: JQuery) {
var entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
const entityIdentity: Entities.ITableEntityIdentity = this.getEntityIdentity($elem);
if (
!this._tableEntityListViewModel.isItemSelected(
@@ -244,26 +244,26 @@ export default class DataTableOperationManager {
}
private addToSelection(rowKey: string) {
var selectedEntity: Entities.ITableEntity = this._tableEntityListViewModel.getItemFromCurrentPage(
const selectedEntity: Entities.ITableEntity = this._tableEntityListViewModel.getItemFromCurrentPage(
this._tableEntityListViewModel.getTableEntityKeys(rowKey)
);
if (selectedEntity != null) {
if (selectedEntity !== null) {
this._tableEntityListViewModel.selected.push(selectedEntity);
}
}
// Selecting first row if the selection is empty.
public selectFirstIfNeeded(): void {
var koSelected: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
const koSelected: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
? this._tableEntityListViewModel.selected
: null;
var koEntities: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
const koEntities: ko.ObservableArray<Entities.ITableEntity> = this._tableEntityListViewModel
? this._tableEntityListViewModel.items
: null;
if (!koSelected().length && koEntities().length) {
var firstEntity: Entities.ITableEntity = koEntities()[0];
const firstEntity: Entities.ITableEntity = koEntities()[0];
// Clear last selection: lastSelectedItem and lastSelectedAnchorItem
this._tableEntityListViewModel.clearLastSelected();
@@ -278,7 +278,7 @@ export default class DataTableOperationManager {
}
}
public bind() {
public bind(): void {
this.dataTable.on("click", "tr", this.click);
this.dataTable.on("dblclick", "tr", this.doubleClick);
this.dataTable.on("keydown", "td", this.keyDown);

View File

@@ -1,12 +1,12 @@
import * as DateTimeUtilities from "./DateTimeUtilities";
import QueryBuilderViewModel from "./QueryBuilderViewModel";
import QueryClauseViewModel from "./QueryClauseViewModel";
import * as DateTimeUtilities from "./DateTimeUtilities";
/**
* Constants
*/
export var utc = "utc";
export var local = "local";
export const utc = "utc";
export const local = "local";
export interface ITimestampQuery {
queryType: string; // valid values are "last" and "range"
@@ -41,11 +41,11 @@ export function addRangeTimestamp(
queryBuilderViewModel.addCustomRange(timestamp, queryClauseViewModel);
}
export function getDefaultStart(localTime: boolean, durationHours: number = 24): string {
var startTimestamp: string;
export function getDefaultStart(localTime: boolean, durationHours = 24): string {
let startTimestamp: string;
var utcNowString: string = new Date().toISOString();
var yesterday: Date = new Date(utcNowString);
const utcNowString: string = new Date().toISOString();
const yesterday: Date = new Date(utcNowString);
yesterday.setHours(yesterday.getHours() - durationHours);
startTimestamp = yesterday.toISOString();
@@ -58,9 +58,9 @@ export function getDefaultStart(localTime: boolean, durationHours: number = 24):
}
export function getDefaultEnd(localTime: boolean): string {
var endTimestamp: string;
let endTimestamp: string;
var utcNowString: string = new Date().toISOString();
const utcNowString: string = new Date().toISOString();
endTimestamp = utcNowString;
@@ -73,14 +73,14 @@ export function getDefaultEnd(localTime: boolean): string {
export function parseDate(dateString: string, isUTC: boolean): Date {
// TODO validate dateString
var date: Date = null;
let date: Date = null;
if (dateString) {
try {
// Date string is assumed to be UTC in Storage Explorer Standalone.
// Behavior may vary in other browsers.
// Here's an example of how the string looks like "2015-10-24T21:44:12"
var millisecondTime = Date.parse(dateString),
const millisecondTime = Date.parse(dateString),
parsed: Date = new Date(millisecondTime);
if (isUTC) {
@@ -89,7 +89,7 @@ export function parseDate(dateString: string, isUTC: boolean): Date {
// Since we parsed in UTC, accessors are flipped - we get local time from the getUTC* group
// Reinstating, the date is parsed above as UTC, and here we are creating a new date object
// in local time.
var year = parsed.getUTCFullYear(),
const year = parsed.getUTCFullYear(),
month = parsed.getUTCMonth(),
day = parsed.getUTCDate(),
hours = parsed.getUTCHours(),
@@ -109,8 +109,8 @@ export function parseDate(dateString: string, isUTC: boolean): Date {
export function utcFromLocalDateString(localDateString: string): string {
// TODO validate localDateString
var localDate = parseDate(localDateString, false),
utcDateString: string = null;
const localDate = parseDate(localDateString, false);
let utcDateString: string = null;
if (localDate) {
utcDateString = localDate.toISOString();
@@ -120,7 +120,7 @@ export function utcFromLocalDateString(localDateString: string): string {
}
function padIfNeeded(value: number): string {
var padded: string = String(value);
let padded = String(value);
if (0 <= value && value < 10) {
padded = "0" + padded;
@@ -130,7 +130,7 @@ function padIfNeeded(value: number): string {
}
function toLocalDateString(date: Date): string {
var localDateString: string = null;
let localDateString: string = null;
if (date) {
localDateString =
@@ -152,8 +152,8 @@ function toLocalDateString(date: Date): string {
export function localFromUtcDateString(utcDateString: string): string {
// TODO validate utcDateString
var utcDate: Date = parseDate(utcDateString, true),
localDateString: string = null;
const utcDate: Date = parseDate(utcDateString, true);
let localDateString: string = null;
if (utcDate) {
localDateString = toLocalDateString(utcDate);
@@ -164,8 +164,8 @@ export function localFromUtcDateString(utcDateString: string): string {
export function tryChangeTimestampTimeZone(koTimestamp: ko.Observable<string>, toUTC: boolean): void {
if (koTimestamp) {
var currentDateString: string = koTimestamp(),
newDateString: string;
const currentDateString: string = koTimestamp();
let newDateString: string;
if (currentDateString) {
if (toUTC) {
@@ -189,16 +189,16 @@ export function tryChangeTimestampTimeZone(koTimestamp: ko.Observable<string>, t
* Input validation helpers
*/
export var noTooltip = "",
export const noTooltip = "",
invalidStartTimeTooltip = "Please provide a valid start time.", // localize
invalidExpiryTimeRequiredTooltip = "Required field. Please provide a valid expiry time.", // localize
invalidExpiryTimeGreaterThanStartTimeTooltip = "The expiry time must be greater than the start time."; // localize
export function isDateString(dateString: string): boolean {
var success: boolean = false;
let success = false;
if (dateString) {
var date: number = Date.parse(dateString);
const date = Date.parse(dateString);
success = $.isNumeric(date);
}
@@ -308,10 +308,10 @@ function _getLocalIsoDateStringFromParts(
}
function _addDaysHours(time: Date, days: number, hours: number): Date {
var msPerHour = 1000 * 60 * 60;
var daysMs = days * msPerHour * 24;
var hoursMs = hours * msPerHour;
var newTimeMs = time.getTime() + daysMs + hoursMs;
const msPerHour = 1000 * 60 * 60;
const daysMs = days * msPerHour * 24;
const hoursMs = hours * msPerHour;
const newTimeMs = time.getTime() + daysMs + hoursMs;
return new Date(newTimeMs);
}
@@ -321,7 +321,7 @@ function _daysHoursBeforeNow(days: number, hours: number): Date {
export function _queryLastDaysHours(days: number, hours: number): string {
/* tslint:disable: no-unused-variable */
var daysHoursAgo = _getLocalIsoDateTimeString(_daysHoursBeforeNow(days, hours));
let daysHoursAgo = _getLocalIsoDateTimeString(_daysHoursBeforeNow(days, hours));
daysHoursAgo = DateTimeUtilities.getUTCDateTime(daysHoursAgo);
return daysHoursAgo;
@@ -329,21 +329,21 @@ export function _queryLastDaysHours(days: number, hours: number): string {
}
export function _queryCurrentMonthLocal(): string {
var now = new Date();
var start = _getLocalIsoDateStringFromParts(now.getFullYear(), now.getMonth(), 1);
const now = new Date();
let start = _getLocalIsoDateStringFromParts(now.getFullYear(), now.getMonth(), 1);
start = DateTimeUtilities.getUTCDateTime(start);
return start;
}
export function _queryCurrentYearLocal(): string {
var now = new Date();
var start = _getLocalIsoDateStringFromParts(now.getFullYear(), 0, 1); // Month is 0..11, date is 1..31
const now = new Date();
let start = _getLocalIsoDateStringFromParts(now.getFullYear(), 0, 1); // Month is 0..11, date is 1..31
start = DateTimeUtilities.getUTCDateTime(start);
return start;
}
function _addTime(time: Date, lastNumber: number, timeUnit: string): Date {
var timeMS: number;
let timeMS: number;
switch (TimeUnit[Number(timeUnit)]) {
case TimeUnit.Days.toString():
timeMS = lastNumber * 1000 * 60 * 60 * 24;
@@ -360,7 +360,7 @@ function _addTime(time: Date, lastNumber: number, timeUnit: string): Date {
default:
//throw new Errors.ArgumentOutOfRangeError(timeUnit);
}
var newTimeMS = time.getTime() + timeMS;
const newTimeMS = time.getTime() + timeMS;
return new Date(newTimeMS);
}
@@ -370,7 +370,7 @@ function _timeBeforeNow(lastNumber: number, timeUnit: string): Date {
export function _queryLastTime(lastNumber: number, timeUnit: string): string {
/* tslint:disable: no-unused-variable */
var daysHoursAgo = _getLocalIsoDateTimeString(_timeBeforeNow(lastNumber, timeUnit));
let daysHoursAgo = _getLocalIsoDateTimeString(_timeBeforeNow(lastNumber, timeUnit));
daysHoursAgo = DateTimeUtilities.getUTCDateTime(daysHoursAgo);
return daysHoursAgo;
/* tslint:enable: no-unused-variable */

View File

@@ -202,21 +202,14 @@ 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()
) {
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;
updateQuery += this.isStringType(newEntity[property].$)
? ` SET ${property} = '${newEntity[property]._}',`
: ` SET ${property} = ${newEntity[property]._},`;
isPropertyUpdated = true;
}
}