From abd7381d758ea635c9a8fcdc0eb70559f9920524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nidhi=20Tyagi=20=F0=9F=8C=9F=F0=9F=90=87=F0=9F=8C=B4?= =?UTF-8?q?=E2=9D=84=EF=B8=8F?= Date: Wed, 9 Aug 2023 07:54:23 +0530 Subject: [PATCH] Update Entity Etag in server side changes chosen scenario --- src/web/client/context/fileData.ts | 10 ++++++++- src/web/client/context/fileDataMap.ts | 10 +++++++++ src/web/client/dal/fileSystemProvider.ts | 22 ++++++++++++++++++- src/web/client/services/etagHandlerService.ts | 12 +++------- src/web/client/utilities/fileAndEntityUtil.ts | 15 +++++++++++++ 5 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/web/client/context/fileData.ts b/src/web/client/context/fileData.ts index 558a0335a..26907c0b0 100644 --- a/src/web/client/context/fileData.ts +++ b/src/web/client/context/fileData.ts @@ -10,6 +10,7 @@ export interface IFileData extends IFileInfo { entityFileExtensionType: string; attributePath: IAttributePath; hasDirtyChanges: boolean; + hasDiffViewTriggered: boolean; encodeAsBase64: boolean | undefined; mimeType: string | undefined; isContentLoaded?: boolean; @@ -23,6 +24,7 @@ export class FileData implements IFileData { private _entityFileExtensionType: string; private _attributePath: IAttributePath; private _hasDirtyChanges!: boolean; + private _hasDiffViewTriggered!: boolean; private _encodeAsBase64: boolean | undefined; private _mimeType: string | undefined; private _isContentLoaded: boolean | undefined; @@ -55,7 +57,9 @@ export class FileData implements IFileData { public get hasDirtyChanges(): boolean { return this._hasDirtyChanges; } - + public get hasDiffViewTriggered(): boolean { + return this._hasDiffViewTriggered; + } public get isContentLoaded(): boolean | undefined { return this._isContentLoaded; } @@ -67,6 +71,9 @@ export class FileData implements IFileData { public set setEntityEtag(value: string) { this._entityEtag = value; } + public set setHasDiffViewTriggered(value: boolean) { + this._hasDiffViewTriggered = value; + } constructor( entityId: string, @@ -88,6 +95,7 @@ export class FileData implements IFileData { this._encodeAsBase64 = encodeAsBase64; this._mimeType = mimeType; this._hasDirtyChanges = false; + this._hasDiffViewTriggered = false; this._isContentLoaded = isContentLoaded; } } diff --git a/src/web/client/context/fileDataMap.ts b/src/web/client/context/fileDataMap.ts index d699350dc..945bde069 100644 --- a/src/web/client/context/fileDataMap.ts +++ b/src/web/client/context/fileDataMap.ts @@ -50,6 +50,16 @@ export class FileDataMap { throw Error("File does not exist in the map"); // TODO - Revisit errors and dialog experience here } + public updateDiffViewTriggered(fileFsPath: string, diffViewTriggerValue: boolean) { + const existingEntity = this.fileMap.get(fileFsPath); + + if (existingEntity) { + existingEntity.setHasDiffViewTriggered = diffViewTriggerValue; + return; + } + throw Error("File does not exist in the map"); // TODO - Revisit errors and dialog experience here + } + public updateEtagValue(fileFsPath: string, etag: string) { const existingEntity = this.fileMap.get(fileFsPath); diff --git a/src/web/client/dal/fileSystemProvider.ts b/src/web/client/dal/fileSystemProvider.ts index 67fc7c4dc..8bd0fe66e 100644 --- a/src/web/client/dal/fileSystemProvider.ts +++ b/src/web/client/dal/fileSystemProvider.ts @@ -18,13 +18,17 @@ import { telemetryEventNames } from "../telemetry/constants"; import { getFolderSubUris } from "../utilities/folderHelperUtility"; import { EtagHandlerService } from "../services/etagHandlerService"; import { + fileHasDiffViewTriggered, fileHasDirtyChanges, getEntityEtag, getFileEntityEtag, getFileEntityId, getFileEntityName, getFileName, + updateDiffViewTriggered, + updateEntityColumnContent, updateFileDirtyChanges, + updateFileEntityEtag, } from "../utilities/fileAndEntityUtil"; import { isVersionControlEnabled } from "../utilities/commonUtil"; import { IFileInfo } from "../common/interfaces"; @@ -91,6 +95,8 @@ export class PortalsFS implements vscode.FileSystemProvider { latestContent.length > 0 && getFileEntityEtag(uri.fsPath) !== entityEtagValue ) { + updateDiffViewTriggered(uri.fsPath, true); + updateFileEntityEtag(uri.fsPath, entityEtagValue); await this.updateMtime(uri, latestContent); WebExtensionContext.telemetry.sendInfoTelemetry( telemetryEventNames.WEB_EXTENSION_DIFF_VIEW_TRIGGERED @@ -135,7 +141,20 @@ export class PortalsFS implements vscode.FileSystemProvider { data = await this._lookup(uri, true); } - return data instanceof File ? data.data : new Uint8Array(); + const fileContent = data instanceof File ? data.data : new Uint8Array(); + if (fileHasDirtyChanges(uri.fsPath)) { + if (fileHasDiffViewTriggered(uri.fsPath)) { + updateDiffViewTriggered(uri.fsPath, false); + } else { + const fileData = WebExtensionContext.fileDataMap.getFileMap.get(uri.fsPath); + if (fileData?.entityId && fileData.attributePath) { + updateEntityColumnContent(fileData?.entityId, fileData?.attributePath, Buffer.from(fileContent).toString()); + updateFileDirtyChanges(uri.fsPath, false); + } + } + } + + return fileContent; } async writeFile( @@ -476,6 +495,7 @@ export class PortalsFS implements vscode.FileSystemProvider { // Update fileDataMap with the latest changes updateFileDirtyChanges(uri.fsPath, false); + updateDiffViewTriggered(uri.fsPath, false); // Update the etag of the file after saving await EtagHandlerService.updateFileEtag(uri.fsPath); diff --git a/src/web/client/services/etagHandlerService.ts b/src/web/client/services/etagHandlerService.ts index 2dce2c62e..976b827a5 100644 --- a/src/web/client/services/etagHandlerService.ts +++ b/src/web/client/services/etagHandlerService.ts @@ -12,6 +12,7 @@ import { PortalsFS } from "../dal/fileSystemProvider"; import { telemetryEventNames } from "../telemetry/constants"; import { GetFileContent } from "../utilities/commonUtil"; import { + getFileEntityEtag, getFileEntityId, getFileEntityName, updateEntityEtag, @@ -30,10 +31,7 @@ export class EtagHandlerService { const requestSentAtTime = new Date().getTime(); - const entityEtag = - WebExtensionContext.fileDataMap.getFileMap.get( - fileFsPath - )?.entityEtag; + const entityEtag = getFileEntityEtag(fileFsPath); const dataverseOrgUrl = WebExtensionContext.urlParametersMap.get( queryParameters.ORG_URL @@ -88,13 +86,9 @@ export class EtagHandlerService { await portalFs.readFile(vscode.Uri.parse(fileFsPath)) ); const latestContent = GetFileContent(result, attributePath, entityName, entityId); + updateEntityEtag(entityId, result[ODATA_ETAG]); if (currentContent !== latestContent) { - updateEntityEtag( - entityId, - result[ODATA_ETAG] - ); - WebExtensionContext.telemetry.sendInfoTelemetry( telemetryEventNames.WEB_EXTENSION_ENTITY_CONTENT_CHANGED ); diff --git a/src/web/client/utilities/fileAndEntityUtil.ts b/src/web/client/utilities/fileAndEntityUtil.ts index 9ab72c1fc..0b1ff4417 100644 --- a/src/web/client/utilities/fileAndEntityUtil.ts +++ b/src/web/client/utilities/fileAndEntityUtil.ts @@ -13,6 +13,11 @@ export function fileHasDirtyChanges(fileFsPath: string) { ?.hasDirtyChanges as boolean; } +export function fileHasDiffViewTriggered(fileFsPath: string) { + return WebExtensionContext.fileDataMap.getFileMap.get(fileFsPath) + ?.hasDiffViewTriggered as boolean; +} + export function getFileEntityId(fileFsPath: string) { return WebExtensionContext.fileDataMap.getFileMap.get(fileFsPath) ?.entityId as string ?? WebExtensionContext.getVscodeWorkspaceState(fileFsPath)?.entityId as string; @@ -42,6 +47,16 @@ export function updateFileDirtyChanges( ); } +export function updateDiffViewTriggered( + fileFsPath: string, + hasDiffViewTriggered: boolean +) { + WebExtensionContext.fileDataMap.updateDiffViewTriggered( + fileFsPath, + hasDiffViewTriggered + ); +} + export function doesFileExist(fileFsPath: string) { return WebExtensionContext.fileDataMap.getFileMap.has(vscode.Uri.parse(fileFsPath).fsPath); }