mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-29 13:51:49 +00:00
merge conflict
This commit is contained in:
15
src/Utils/KeyboardUtils.ts
Normal file
15
src/Utils/KeyboardUtils.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Is the environment 'ctrl' key press. This key is used for multi selection, like select one more item, select all.
|
||||
* For Windows and Linux, it's ctrl. For Mac, it's command.
|
||||
*/
|
||||
export const isEnvironmentCtrlPressed = (event: JQueryEventObject | React.MouseEvent): boolean =>
|
||||
isMac() ? event.metaKey : event.ctrlKey;
|
||||
|
||||
export const isEnvironmentShiftPressed = (event: JQueryEventObject | React.MouseEvent): boolean => event.shiftKey;
|
||||
|
||||
export const isEnvironmentAltPressed = (event: JQueryEventObject | React.MouseEvent): boolean => event.altKey;
|
||||
|
||||
/**
|
||||
* Returns whether the current platform is MacOS.
|
||||
*/
|
||||
export const isMac = (): boolean => navigator.platform.toUpperCase().indexOf("MAC") >= 0;
|
||||
@@ -160,3 +160,52 @@ async function getOperationStatus(operationStatusUrl: string) {
|
||||
}
|
||||
throw new Error(`Operation Response: ${JSON.stringify(body)}. Retrying.`);
|
||||
}
|
||||
|
||||
export async function getOfferingIdsRequest<T>({
|
||||
host,
|
||||
path,
|
||||
apiVersion,
|
||||
method,
|
||||
body: requestBody,
|
||||
queryParams,
|
||||
}: Options): Promise<{ result: T; operationStatusUrl: string }> {
|
||||
const url = new URL(path, host);
|
||||
url.searchParams.append("api-version", configContext.armAPIVersion || apiVersion);
|
||||
if (queryParams) {
|
||||
queryParams.filter && url.searchParams.append("$filter", queryParams.filter);
|
||||
queryParams.metricNames && url.searchParams.append("metricnames", queryParams.metricNames);
|
||||
}
|
||||
|
||||
if (!configContext.CATALOG_API_KEY) {
|
||||
throw new Error("No catalog API key provided");
|
||||
}
|
||||
|
||||
const response = await window.fetch(url.href, {
|
||||
method,
|
||||
headers: {
|
||||
[HttpHeaders.xAPIKey]: configContext.CATALOG_API_KEY,
|
||||
},
|
||||
body: requestBody ? JSON.stringify(requestBody) : undefined,
|
||||
});
|
||||
if (!response.ok) {
|
||||
let error: ARMError;
|
||||
try {
|
||||
const errorResponse = (await response.json()) as ParsedErrorResponse;
|
||||
if ("error" in errorResponse) {
|
||||
error = new ARMError(errorResponse.error.message);
|
||||
error.code = errorResponse.error.code;
|
||||
} else {
|
||||
error = new ARMError(errorResponse.message);
|
||||
error.code = errorResponse.code;
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(await response.text());
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
const operationStatusUrl = (response.headers && response.headers.get("location")) || "";
|
||||
const responseBody = (await response.json()) as T;
|
||||
return { result: responseBody, operationStatusUrl: operationStatusUrl };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user