Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organization url changes on web extension #237

Merged
merged 1 commit into from
Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/web/client/common/authenticationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import * as vscode from 'vscode';
import { pathParamToSchema, PROVIDER_ID, SCOPE_OPTION, SCOPE_VERB } from './constants';
import { pathParamToSchema, PROVIDER_ID, SCOPE_OPTION } from './constants';
import { ERRORS } from './errorHandler';
import { dataSourcePropertiesMap } from './localStore';

Expand All @@ -22,7 +22,7 @@ export function getHeader(accessToken: string) {
export async function dataverseAuthentication(dataverseOrgURL: string): Promise<string> {
let accessToken = '';
try {
const session = await vscode.authentication.getSession(PROVIDER_ID, [SCOPE_VERB + dataverseOrgURL + SCOPE_OPTION], { createIfNone: true });
const session = await vscode.authentication.getSession(PROVIDER_ID, [dataverseOrgURL + SCOPE_OPTION], { createIfNone: true });
accessToken = session.accessToken;
} catch (e: any) {
vscode.window.showErrorMessage(ERRORS.AUTHORIZATION_FAILED);
Expand Down
2 changes: 0 additions & 2 deletions src/web/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ export const FILE_NAME_FIELD = '_primarynamefield';
export const CHARSET = 'utf-8';
export const PROVIDER_ID = "microsoft";
export const SCOPE_OPTION = "//.default";
export const SCOPE_VERB = "https://";


export const columnExtension = new Map([
["customcss.cs", "adx_customcss"],
Expand Down
5 changes: 0 additions & 5 deletions src/web/client/common/createFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/


/* --------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
/* eslint-disable @typescript-eslint/no-explicit-any */
import * as vscode from "vscode";
import { PORTALS_FOLDER_NAME, PORTALS_URI_SCHEME, PORTALS_WORKSPACE_NAME } from "./constants";
Expand Down
16 changes: 8 additions & 8 deletions src/web/client/common/errorHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export const ERRORS = {
VSCODE_INITIAL_LOAD: "Error Initializing Platform",
APP_NAME_NOT_AVAILABLE: "Please specify the appName",
UNKNOWN_APP: "Unknown app, Please add authentication flow for this app",
AUTHORIZATION_FAILED: "Authorization Failed. Please run again to authorize it.",
AUTHORIZATION_FAILED: "Authorization Failed. Please run again to authorize it",
FILE_NOT_FOUND: "File Not Found",
RETRY_LIMIT_EXCEEDED: " Retry Limit Exceeded.",
PRECONDITION_CHECK_FAILED: "Precondition check failed.",
SERVER_ERROR_RETRY_LATER: "We're sorry, a server error occurred. Please wait a bit and try again.",
AUTHORIZATION_REQUIRED: "Authorization is required to perform that action. Please run again to authorize it.",
SERVER_ERROR_PERMISSION_DENIED: "We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED.",
RETRY_LIMIT_EXCEEDED: "Retry Limit Exceeded",
PRECONDITION_CHECK_FAILED: "Precondition check failed",
SERVER_ERROR_RETRY_LATER: "We're sorry, a server error occurred. Please wait a bit and try again",
AUTHORIZATION_REQUIRED: "Authorization is required to perform that action. Please run again to authorize it",
SERVER_ERROR_PERMISSION_DENIED: "We're sorry, a server error occurred while reading from storage. Error code PERMISSION_DENIED",
EMPTY_RESPONSE: "Empty Response",
BAD_VALUE: "Bad Value",
LIMIT_EXCEEDED: "Limit Exceeded: .",
LIMIT_EXCEEDED: "Limit Exceeded",
THRESHOLD_LIMIT_EXCEEDED: "Threshold Rate Limit Exceeded",
RATE_LIMIT_EXCEEDED: "Rate Limit Exceeded",
NOT_FOUND: "Not Found",
Expand All @@ -31,7 +31,7 @@ export const ERRORS = {
SERVICE_UNAVAILABLE: "Service unavailable",
SERVICE_ERROR: "Service error",
INVALID_ARGUMENT: 'Invalid argument',
MANDATORY_PARAMETERS_NULL: 'Mandatory Parameters Cannot Be Null',
MANDATORY_PARAMETERS_NULL: "Mandatory Parameters Cannot Be Null",
FILE_NAME_NOT_SET: "Error Creating File as File Name Not Specified"
};

Expand Down
2 changes: 0 additions & 2 deletions src/web/client/common/fileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/



import * as path from 'path';
import * as vscode from 'vscode';

Expand Down
2 changes: 1 addition & 1 deletion src/web/client/common/localStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export async function setContext(accessToken: string, pathEntity: string, entity
}

function createEntityFiles(portalsFS: PortalsFS, accessToken: string, entity: string, entityId: string, queryParamsMap: any, entitiesSchemaMap: any, languageIdCodeMap: any) {
createFileSystem(portalsFS)
createFileSystem(portalsFS);
getDataFromDataVerse(accessToken, entity, entityId, queryParamsMap, entitiesSchemaMap, languageIdCodeMap, portalsFS);
}

Expand Down
4 changes: 2 additions & 2 deletions src/web/client/common/portalSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export const portal_schema_data = {
api: "api",
data: "data",
version: "v9.1",
singleEntityURL: "https://{dataverseOrgUrl}/{api}/{data}/{version}/{entity}({entityId})",
multiEntityURL: "https://{dataverseOrgUrl}/{api}/{data}/{version}/{entity}"
singleEntityURL: "{dataverseOrgUrl}/{api}/{data}/{version}/{entity}({entityId})",
multiEntityURL: "{dataverseOrgUrl}/{api}/{data}/{version}/{entity}"
},
"entity": [
{
Expand Down
10 changes: 5 additions & 5 deletions src/web/client/common/remoteFetchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as vscode from 'vscode';
import { getHeader, getRequestURLSingleEntity } from './authenticationProvider';
import { columnExtension, CONTENT_PAGES, NO_CONTENT, EMPTY_FILE_NAME, DEFAULT_LANGUAGE_CODE, entityFolder, FILE_NAME_FIELD, MULTI_ENTITY_URL_KEY, ORG_URL, pathParamToSchema, CHARSET } from './constants';
import { columnExtension, CONTENT_PAGES, NO_CONTENT, EMPTY_FILE_NAME, DEFAULT_LANGUAGE_CODE, entityFolder, FILE_NAME_FIELD, MULTI_ENTITY_URL_KEY, ORG_URL, pathParamToSchema } from './constants';
import { PORTALS_FOLDER_NAME, PORTALS_URI_SCHEME, SINGLE_ENTITY_URL_KEY } from './constants';
import { ERRORS, showErrorDialog } from './errorHandler';
import { PortalsFS } from './fileSystemProvider';
Expand Down Expand Up @@ -35,7 +35,7 @@ export async function fetchData(accessToken: string, entity: string, entityId: s
const data = await response.json();
if (data.value?.length >= 0) {
for (let counter = 0; counter < data.value.length; counter++) {
createContentFiles(data[counter], entity, queryParamsMap, entitiesSchemaMap, languageIdCodeMap, portalFs, dataverseOrgUrl, accessToken, entityId);
createContentFiles(data[counter], entity, queryParamsMap, entitiesSchemaMap, languageIdCodeMap, portalFs, dataverseOrgUrl, accessToken, entityId);
}
} else {
createContentFiles(data, entity, queryParamsMap, entitiesSchemaMap, languageIdCodeMap, portalFs, dataverseOrgUrl, accessToken, entityId);
Expand Down Expand Up @@ -71,14 +71,14 @@ function createContentFiles(result: string, entity: string, queryParamsMap: any,
const value = result[attributeArray[counter]] ? result[attributeArray[counter]] : NO_CONTENT;
saveDataMap = createVirtualFile(portalsFS, fileName, languageCode, value, columnExtension.get(attributeArray[counter]) as string, subUri, entityId, attributeArray[counter] as string, entity);
}
vscode.window.showTextDocument(vscode.Uri.parse(`${PORTALS_URI_SCHEME}:/${PORTALS_FOLDER_NAME}/${subUri}/${fileName}/${entityFolder.get(CONTENT_PAGES)}/${fileName}.${languageCode}.${columnExtension.get(attributeArray[--counter]) as string}`))
vscode.window.showTextDocument(vscode.Uri.parse(`${PORTALS_URI_SCHEME}:/${PORTALS_FOLDER_NAME}/${subUri}/${fileName}/${entityFolder.get(CONTENT_PAGES)}/${fileName}.${languageCode}.${columnExtension.get(attributeArray[--counter]) as string}`));
}
registerSaveProvider(accessToken, portalsFS,dataverseOrgUrl, saveDataMap)
registerSaveProvider(accessToken, portalsFS, dataverseOrgUrl, saveDataMap);
}



function createVirtualFile(portalsFS: PortalsFS, fileName: string, languageCode: string, data: any, portalFileExtension: string, subUri: string,entityId : string, saveDataAtribute : string, entity: string ) {
function createVirtualFile(portalsFS: PortalsFS, fileName: string, languageCode: string, data: any, portalFileExtension: string, subUri: string, entityId: string, saveDataAtribute: string, entity: string) {
const saveEntityDetails = new SaveEntityDetails(entityId, entity, saveDataAtribute);
const fileUri = `${PORTALS_URI_SCHEME}:/${PORTALS_FOLDER_NAME}/${subUri}/${fileName}/${entityFolder.get(CONTENT_PAGES)}/${fileName}.${languageCode}.${portalFileExtension}`;
portalsFS.writeFile(vscode.Uri.parse(fileUri), new TextEncoder().encode(data), { create: true, overwrite: true });
Expand Down
6 changes: 2 additions & 4 deletions src/web/client/common/remoteSaveProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*/


/* eslint-disable @typescript-eslint/no-explicit-any */
import * as vscode from 'vscode';
import { getHeader, getRequestURLSingleEntity } from './authenticationProvider';
Expand All @@ -13,13 +12,12 @@ import { PortalsFS } from './fileSystemProvider';
import { entitiesSchemaMap } from './localStore';
import { SaveEntityDetails } from './portalSchemaInterface';

export function registerSaveProvider(accessToken: string, portalsFS: PortalsFS, dataVerseOrgUrl: string, saveDataMap: Map<string, SaveEntityDetails>)
{
export function registerSaveProvider(accessToken: string, portalsFS: PortalsFS, dataVerseOrgUrl: string, saveDataMap: Map<string, SaveEntityDetails>) {
vscode.workspace.onDidSaveTextDocument(async (e) => {
vscode.window.showInformationMessage('saving file: ' + e.uri);
const newFileData = portalsFS.readFile(e.uri);
const patchRequestUrl = getRequestURLSingleEntity(dataVerseOrgUrl, saveDataMap.get(e.uri.fsPath)?.getEntityName as string, saveDataMap.get(e.uri.fsPath)?.getEntityId as string, SINGLE_ENTITY_URL_KEY, entitiesSchemaMap, 'PATCH');
vscode.window.showInformationMessage(patchRequestUrl)
vscode.window.showInformationMessage(patchRequestUrl);
await saveData(accessToken, patchRequestUrl, e.uri, saveDataMap, new TextDecoder(CHARSET).decode(newFileData));
});
}
Expand Down