Skip to content

Commit

Permalink
Remove noisy notifications from fetch flow (#814)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyaginidhi authored Jan 19, 2024
1 parent cfc45d3 commit bdb1a27
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
5 changes: 3 additions & 2 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
"There was a permissions problem with the server": "There was a permissions problem with the server",
"There’s a problem on the back end": "There’s a problem on the back end",
"Try again": "Try again",
"We encountered an error preparing the file for edit.": "We encountered an error preparing the file for edit.",
"We encountered an error preparing the files for edit.": "We encountered an error preparing the files for edit.",
"Response data is empty": "Response data is empty",
"Failed to fetch some files.": "Failed to fetch some files.",
"Failed to get file ready for edit.": "Failed to get file ready for edit.",
"Failed to get file ready for edit: {0}": "Failed to get file ready for edit: {0}",
"Saving your file ...": "Saving your file ...",
"Enter Organization ID": "Enter Organization ID",
"Power Pages Copilot is now connected to the environment: {0} : {1}/{0} represents the environment name": {
Expand Down
11 changes: 7 additions & 4 deletions loc/translations-export/vscode-powerplatform.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca
<trans-unit id="++CODE++83d9d98e86aca9239f8a2635a98356d956268fb41a465fbc039b9ac979c61649">
<source xml:lang="en">Failed to fetch some files.</source>
</trans-unit>
<trans-unit id="++CODE++e1a694d8ed0093d17fa58ee8b44cc76f74583667ffc3511e5d8f77df7b156c41">
<source xml:lang="en">Failed to get file ready for edit.</source>
<trans-unit id="++CODE++862d6197d64601aa13ce30db5ec5b8f819ad00fe21e3b031a3e47fe22ef68fb3">
<source xml:lang="en">Failed to get file ready for edit: {0}</source>
</trans-unit>
<trans-unit id="++CODE++2a8ddde521f14ecd4a8717f2bcf9a2b021fa38a578518066d2ae32271aa95237">
<source xml:lang="en">Fetching your file ...</source>
Expand Down Expand Up @@ -234,6 +234,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<source xml:lang="en">Resource: {0}</source>
<note>The {0} represents profile's resource/environment URL</note>
</trans-unit>
<trans-unit id="++CODE++b62120c5416487f4c793d75aee7fea083971e5ac665a3f35767023f408f482e5">
<source xml:lang="en">Response data is empty</source>
</trans-unit>
<trans-unit id="++CODE++0134bc37f2fdeb11daa9e760ecee0ef9706989b33f77a38daadb8b7aae685749">
<source xml:lang="en">Saving your file ...</source>
</trans-unit>
Expand Down Expand Up @@ -284,8 +287,8 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<source xml:lang="en">User: {0}</source>
<note>The {0} represents auth profile's user name (email address))</note>
</trans-unit>
<trans-unit id="++CODE++91357f5ee585bec70c13f9f0807c5a047f35066e4fc63b571f5a957a657d0262">
<source xml:lang="en">We encountered an error preparing the file for edit.</source>
<trans-unit id="++CODE++d941ee96c6f480390012381f9fc0dfd961f2aa803732860e2505a8453700f458">
<source xml:lang="en">We encountered an error preparing the files for edit.</source>
</trans-unit>
<trans-unit id="++CODE++ff174a54d200db312e20f9f72e805df5d0221070730c1d789d642185b1a3b3e5">
<source xml:lang="en">Web files</source>
Expand Down
20 changes: 7 additions & 13 deletions src/web/client/dal/remoteFetchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function fetchDataFromDataverseAndUpdateVFS(
showErrorDialog(
vscode.l10n.t("There was a problem opening the workspace"),
vscode.l10n.t(
"We encountered an error preparing the file for edit."
"We encountered an error preparing the files for edit."
)
);
WebExtensionContext.telemetry.sendErrorTelemetry(telemetryEventNames.WEB_EXTENSION_FAILED_TO_PREPARE_WORKSPACE, fetchDataFromDataverseAndUpdateVFS.name, errorMsg, error as Error);
Expand Down Expand Up @@ -116,10 +116,7 @@ async function fetchFromDataverseAndCreateFiles(
}

if (result[Constants.ODATA_COUNT] !== 0 && data.length === 0) {
vscode.window.showErrorMessage(
"microsoft-powerapps-portals.webExtension.fetch.nocontent.error",
"Response data is empty"
);
console.error(vscode.l10n.t("Response data is empty"));
throw new Error(ERRORS.EMPTY_RESPONSE);
}

Expand Down Expand Up @@ -147,9 +144,7 @@ async function fetchFromDataverseAndCreateFiles(
} catch (error) {
makeRequestCall = false;
const errorMsg = (error as Error)?.message;
vscode.window.showErrorMessage(
vscode.l10n.t("Failed to fetch some files.")
);
console.error(vscode.l10n.t("Failed to fetch some files."));
if ((error as Response)?.status > 0) {
WebExtensionContext.telemetry.sendAPIFailureTelemetry(
requestUrl,
Expand Down Expand Up @@ -194,6 +189,7 @@ async function createContentFiles(
filePathInPortalFS?: string,
defaultFileInfo?: IFileInfo,
) {
let fileName = "";
try {
const entityDetails = getEntity(entityName);
const attributes = entityDetails?.get(schemaEntityKey.ATTRIBUTES);
Expand Down Expand Up @@ -227,7 +223,7 @@ async function createContentFiles(
throw new Error(ERRORS.FILE_ID_EMPTY);
}

const fileName = fetchedFileName
fileName = fetchedFileName
? result[fetchedFileName]
: Constants.EMPTY_FILE_NAME;

Expand Down Expand Up @@ -291,9 +287,7 @@ async function createContentFiles(

} catch (error) {
const errorMsg = (error as Error)?.message;
vscode.window.showErrorMessage(
vscode.l10n.t("Failed to get file ready for edit.")
);
console.error(vscode.l10n.t("Failed to get file ready for edit: {0}", fileName));
WebExtensionContext.telemetry.sendErrorTelemetry(
telemetryEventNames.WEB_EXTENSION_CONTENT_FILE_CREATION_FAILED,
createContentFiles.name,
Expand Down Expand Up @@ -361,7 +355,7 @@ async function processDataAndCreateFile(
let rootWebPageId = undefined;

if (rootWebPageIdAttribute) {
const rootWebPageIdPath : IAttributePath = getAttributePath(rootWebPageIdAttribute);
const rootWebPageIdPath: IAttributePath = getAttributePath(rootWebPageIdAttribute);
rootWebPageId = getAttributeContent(result, rootWebPageIdPath, entityName, entityId);
}

Expand Down
48 changes: 28 additions & 20 deletions src/web/client/test/integration/remoteFetchProvider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ describe("remoteFetchProvider", () => {
assert.callCount(sendAPISuccessTelemetry, 4);
});

it("fetchDataFromDataverseAndUpdateVFS_whenResponseSuccessButDataIsNull_shouldCallShowErrorMessage", async () => {
it("fetchDataFromDataverseAndUpdateVFS_whenResponseSuccessButDataIsNull_shouldSendErrorTelemetry", async () => {
//Act
const entityName = "webpages";
const entityId = "aa563be7-9a38-4a89-9216-47f9fc6a3f14";
Expand Down Expand Up @@ -490,7 +490,7 @@ describe("remoteFetchProvider", () => {
assert.calledOnce(_mockFetch);
});

it("fetchDataFromDataverseAndUpdateVFS_whenResponseNotSuccess_shouldCallShowErrorMessage", async () => {
it("fetchDataFromDataverseAndUpdateVFS_whenResponseNotSuccess_shouldCallSendErrorTelemetry", async () => {
//Act
const entityName = "webpages";
const entityId = "aa563be7-9a38-4a89-9216-47f9fc6a3f14";
Expand All @@ -504,12 +504,15 @@ describe("remoteFetchProvider", () => {
[schemaKey.SCHEMA_VERSION, "portalschemav2"],
]);

const showErrorMessage = stub(vscode.window, "showErrorMessage");
WebExtensionContext.setWebExtensionContext(
entityName,
entityId,
queryParamsMap
);
const sendErrorTelemetry = stub(
WebExtensionContext.telemetry,
"sendErrorTelemetry"
);

const languageIdCodeMap = new Map<string, string>([["1033", "en-US"]]);
stub(schemaHelperUtil, "getLcidCodeMap").returns(languageIdCodeMap);
Expand Down Expand Up @@ -553,9 +556,9 @@ describe("remoteFetchProvider", () => {
json: () => {
return new Promise((resolve) => {
return resolve({
"@odata.count": 1,
"@Microsoft.Dynamics.CRM.totalrecordcount": 1,
"value": null,
"@odata.count": 0,
"@Microsoft.Dynamics.CRM.totalrecordcount": 0,
"value": [],
});
});
},
Expand All @@ -566,13 +569,26 @@ describe("remoteFetchProvider", () => {
await fetchDataFromDataverseAndUpdateVFS(portalFs);

//Assert
const sendErrorTelemetryCalls = sendErrorTelemetry.getCalls();

assert.callCount(sendErrorTelemetry, 5);
assert.calledWithMatch(sendErrorTelemetryCalls[0], telemetryEventNames.WEB_EXTENSION_POPULATE_WEBSITE_ID_TO_LANGUAGE_SYSTEM_ERROR,
"populateWebsiteIdToLanguageMap",
"Only absolute URLs are supported");
assert.calledWithMatch(sendErrorTelemetryCalls[1], telemetryEventNames.WEB_EXTENSION_POPULATE_WEBSITE_LANGUAGE_ID_TO_PORTALLANGUAGE_SYSTEM_ERROR,
"populateWebsiteLanguageIdToPortalLanguageMap",
"Only absolute URLs are supported");
assert.calledWithMatch(sendErrorTelemetryCalls[2], telemetryEventNames.WEB_EXTENSION_POPULATE_LANGUAGE_ID_TO_CODE_SYSTEM_ERROR,
"populateLanguageIdToCode",
"Only absolute URLs are supported");
assert.calledWithMatch(sendErrorTelemetryCalls[3], telemetryEventNames.WEB_EXTENSION_POPULATE_SHARED_WORKSPACE_SYSTEM_ERROR,
"populateSharedWorkspace",
"Web extension populate shared workspace system error");
assert.calledWithMatch(sendErrorTelemetryCalls[4],
telemetryEventNames.WEB_EXTENSION_FETCH_DATAVERSE_AND_CREATE_FILES_SYSTEM_ERROR,
"fetchFromDataverseAndCreateFiles",
`{"ok":false,"statusText":"statusText"}`);
assert.calledOnce(_mockFetch);

assert.calledOnce(showErrorMessage);
const showErrorMessageCalls = showErrorMessage.getCalls();
expect(showErrorMessageCalls[0].args[0]).eq(
"Failed to fetch some files."
);
});

it("fetchDataFromDataverseAndUpdateVFS_whenResponseSuccessAndSubUriIsBlank_shouldThrowError", async () => {
Expand Down Expand Up @@ -661,7 +677,6 @@ describe("remoteFetchProvider", () => {
WebExtensionContext.telemetry,
"sendErrorTelemetry"
);
const showErrorMessage = stub(vscode.window, "showErrorMessage");
stub(WebExtensionContext, "updateEntityDetailsInContext");
const sendAPITelemetry = stub(
WebExtensionContext.telemetry,
Expand All @@ -674,7 +689,6 @@ describe("remoteFetchProvider", () => {
assert.calledOnce(_mockFetch);
assert.calledTwice(sendAPITelemetry);
assert.calledOnce(sendErrorTelemetry);
assert.calledOnce(showErrorMessage);
assert.callCount(getEntity, 2);
});

Expand Down Expand Up @@ -765,7 +779,6 @@ describe("remoteFetchProvider", () => {
WebExtensionContext.telemetry,
"sendErrorTelemetry"
);
const showErrorMessage = stub(vscode.window, "showErrorMessage");
stub(WebExtensionContext, "updateEntityDetailsInContext");
const sendAPITelemetry = stub(
WebExtensionContext.telemetry,
Expand All @@ -779,7 +792,6 @@ describe("remoteFetchProvider", () => {
assert.calledOnce(_mockFetch);
assert.calledTwice(sendAPITelemetry);
assert.calledOnce(sendErrorTelemetry);
assert.calledOnce(showErrorMessage);
assert.callCount(getEntity, 2);
});

Expand Down Expand Up @@ -871,7 +883,6 @@ describe("remoteFetchProvider", () => {
WebExtensionContext.telemetry,
"sendErrorTelemetry"
);
const showErrorMessage = stub(vscode.window, "showErrorMessage");
stub(WebExtensionContext, "updateEntityDetailsInContext");
const sendAPITelemetry = stub(
WebExtensionContext.telemetry,
Expand All @@ -885,7 +896,6 @@ describe("remoteFetchProvider", () => {
assert.calledOnce(_mockFetch);
assert.calledTwice(sendAPITelemetry);
assert.calledOnce(sendErrorTelemetry);
assert.calledOnce(showErrorMessage);
assert.callCount(getEntity, 2);
});

Expand Down Expand Up @@ -978,7 +988,6 @@ describe("remoteFetchProvider", () => {
WebExtensionContext.telemetry,
"sendErrorTelemetry"
);
const showErrorMessage = stub(vscode.window, "showErrorMessage");
const sendAPITelemetry = stub(
WebExtensionContext.telemetry,
"sendAPITelemetry"
Expand All @@ -991,7 +1000,6 @@ describe("remoteFetchProvider", () => {
assert.calledOnce(_mockFetch);
assert.calledTwice(sendAPITelemetry);
assert.calledOnce(sendErrorTelemetry);
assert.calledOnce(showErrorMessage);
assert.callCount(getEntity, 2);
});

Expand Down

0 comments on commit bdb1a27

Please sign in to comment.