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

Add initial saved views widget implementation #6

Merged
merged 12 commits into from
Nov 29, 2023
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
coverage
lib
node_modules
.cache

npm-debug.log*
pnpm-debug.log*
Expand Down
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"json.format.keepLines": true,

"typescript.format.semicolons": "insert",
"typescript.preferences.importModuleSpecifierEnding": "js",
"typescript.reportStyleChecksAsWarnings": true,

"[javascript][typescript][typescriptreact]": {
Expand Down
4 changes: 2 additions & 2 deletions packages/saved-views-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"scripts": {
"build": "run-p build:**",
"build:transpile:esm": "tsc --project ./tsconfig.build.json",
"test": "vitest",
"test": "vitest run",
"test:cover": "vitest run --coverage",
"test:watch": "vitest watch",
"typecheck": "tsc --noEmit"
Expand All @@ -43,7 +43,7 @@
"happy-dom": "^10.5.2",
"npm-run-all": "^4.1.5",
"typescript": "^5.1.6",
"vite": "^4.4.7",
"vite": "^4.4.11",
"vitest": "^0.33.0"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/saved-views-client/src/client/ApiUtils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/

export interface CallITwinApiParams {
url: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { describe, expect, it, vi } from "vitest";
import { View } from "../models/savedViews/View.js";
diegopinate marked this conversation as resolved.
Show resolved Hide resolved
import { CallITwinApiParams } from "./ApiUtils";
import { ITwinSavedViewsClient, PreferOptions } from "./ITwinSavedViewsClient";
import { ImageSize } from "./SavedViewsClient";

interface TestQueryParams {
urlParams: string[];
method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
body?: object | undefined;
headers?: {
prefer?: PreferOptions;
Prefer?: PreferOptions;
};
signal?: AbortSignal | undefined;
}
Expand Down Expand Up @@ -73,7 +73,7 @@ describe("ITwinSavedViewsClient tests for callITwinApi information transference"
urlParams: [savedViewId],
method: "GET",
headers: {
prefer: PreferOptions.Minimal,
Prefer: PreferOptions.Minimal,
},
body: undefined,
signal: new AbortSignal(),
Expand All @@ -93,7 +93,7 @@ describe("ITwinSavedViewsClient tests for callITwinApi information transference"
urlParams: [savedViewId],
method: "GET",
headers: {
prefer: PreferOptions.Representation,
Prefer: PreferOptions.Representation,
},
body: undefined,
signal: new AbortSignal(),
Expand All @@ -117,7 +117,7 @@ describe("ITwinSavedViewsClient tests for callITwinApi information transference"
urlParams: [iTwinId, iModelId, groupId, top, skip],
method: "GET",
headers: {
prefer: PreferOptions.Minimal,
Prefer: PreferOptions.Minimal,
},
body: undefined,
signal: new AbortSignal(),
Expand All @@ -140,7 +140,7 @@ describe("ITwinSavedViewsClient tests for callITwinApi information transference"
urlParams: [iTwinId, iModelId, groupId, top, skip],
method: "GET",
headers: {
prefer: PreferOptions.Representation,
Prefer: PreferOptions.Representation,
},
body: undefined,
signal: new AbortSignal(),
Expand All @@ -167,8 +167,9 @@ describe("ITwinSavedViewsClient tests for callITwinApi information transference"

await callITwinApiTestRunner(expectedQueryParams, async () => {
await systemUnderTest.createSavedView({
iTwinId: "",
signal: new AbortSignal(),
savedViewData: {},
savedViewData: {} as View,
displayName: "Test View",
});
}, checkIfFetchIsReceivingExpectedParams);
Expand All @@ -177,7 +178,7 @@ describe("ITwinSavedViewsClient tests for callITwinApi information transference"
it("updateSavedView", async () => {
const savedViewId = "savedViewComboId";
const body = {
savedViewData: {},
savedViewData: {} as View,
groupId: "groupId",
displayName: "displayName",
shared: true,
Expand Down Expand Up @@ -221,15 +222,15 @@ describe("ITwinSavedViewsClient tests for callITwinApi information transference"
it("getImage", async () => {
const savedViewId = "savedViewComboId";
const expectedQueryParams: TestQueryParams = {
urlParams: [savedViewId, ImageSize.Full],
urlParams: [savedViewId, "full"],
method: "GET",
headers: {},
signal: new AbortSignal(),
};

await callITwinApiTestRunner(expectedQueryParams, async () => {
await systemUnderTest.getImage({
size: ImageSize.Full,
size: "full",
savedViewId: savedViewId,
signal: new AbortSignal(),
});
Expand Down Expand Up @@ -557,7 +558,7 @@ describe("ITwinSavedViewsClient tests for callITwinApi information transference"
urlParams: [savedViewId],
method: "GET",
headers: {
prefer: PreferOptions.Minimal,
Prefer: PreferOptions.Minimal,
},
body: undefined,
signal: new AbortSignal(),
Expand Down
72 changes: 31 additions & 41 deletions packages/saved-views-client/src/client/ITwinSavedViewsClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
import { callITwinApi } from "./ApiUtils.js";
import {
CreateExtensionParams, CreateGroupParams, CreateSavedViewParams, CreateTagParams, ExtensionListResponse,
Expand Down Expand Up @@ -33,6 +33,7 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
url: queyParams.url,
method: queyParams.method,
headers: {
"Content-Type": "application/json",
...queyParams.headers,
},
body: queyParams.body,
Expand All @@ -46,7 +47,7 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
url: `${this.baseUrl}/${args.savedViewId}`,
method: "GET",
headers: {
prefer: PreferOptions.Minimal,
Prefer: PreferOptions.Minimal,
},
signal: args.signal,
});
Expand All @@ -57,7 +58,7 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
url: `${this.baseUrl}/${args.savedViewId}`,
method: "GET",
headers: {
prefer: PreferOptions.Representation,
Prefer: PreferOptions.Representation,
},
signal: args.signal,
});
Expand All @@ -68,28 +69,28 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
const groupId = args.groupId ? `&groupId=${args.groupId}` : "";
const top = args.top ? `&$top=${args.top}` : "";
const skip = args.skip ? `&$skip=${args.skip}` : "";
const url = `${this.baseUrl}/?iTwinId=${args.iTwinId}${iModelId}${groupId}${top}${skip}`;
return this.queryITwinApi({
url: url,
url: `${this.baseUrl}/?iTwinId=${args.iTwinId}${iModelId}${groupId}${top}${skip}`,
method: "GET",
headers: {
prefer: PreferOptions.Minimal,
Prefer: PreferOptions.Minimal,
},
signal: args.signal,
});
}

async getAllSavedViewsRepresentation(args: GetSavedViewsParams): Promise<SavedViewListRepresentationResponse> {
const iModelId = args.iModelId ? `&iModelId=${args.iModelId}` : "";
const groupId = args.groupId ? `&groupId=${args.groupId}` : "";
const top = args.top ? `&$top=${args.top}` : "";
const skip = args.skip ? `&$skip=${args.skip}` : "";
const url = `${this.baseUrl}/?iTwinId=${args.iTwinId}${iModelId}${groupId}${top}${skip}`;
const iTwinId = args.iTwinId && `iTwinId=${args.iTwinId}`;
const iModelId = args.iModelId && `iModelId=${args.iModelId}`;
const groupId = args.groupId && `groupId=${args.groupId}`;
const top = args.top && `$top=${args.top}`;
const skip = args.skip && `$skip=${args.skip}`;
const query = [iTwinId, iModelId, groupId, top, skip].filter((param) => param).join("&");
return this.queryITwinApi({
url: url,
url: `${this.baseUrl}?${query}`,
method: "GET",
headers: {
prefer: PreferOptions.Representation,
Prefer: PreferOptions.Representation,
},
signal: args.signal,
});
Expand All @@ -100,8 +101,8 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
return this.queryITwinApi({
url: `${this.baseUrl}/`,
method: "POST",
body: body,
signal: signal,
body,
signal,
});
}

Expand All @@ -110,7 +111,7 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
return this.queryITwinApi({
url: `${this.baseUrl}/${savedViewId}`,
method: "PATCH",
body: body,
body,
signal,
});
}
Expand All @@ -136,8 +137,8 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
return this.queryITwinApi({
url: `${this.baseUrl}/${savedViewId}/image`,
method: "PUT",
body: body,
signal: signal,
body,
signal,
});
}

Expand All @@ -151,9 +152,8 @@ export class ITwinSavedViewsClient implements SavedViewsClient {

async getAllGroups(args: GetGroupsParams): Promise<GroupListResponse> {
const iModelId = args.iModelId ? `&iModelId=${args.iModelId}` : "";
const url = `${this.baseUrl}/groups/?iTwinId=${args.iTwinId}${iModelId}`;
return this.queryITwinApi({
url: url,
url: `${this.baseUrl}/groups/?iTwinId=${args.iTwinId}${iModelId}`,
method: "GET",
signal: args.signal,
});
Expand All @@ -163,7 +163,7 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
const { signal, ...body } = args;
return this.queryITwinApi({
method: "POST",
body: body,
body,
signal,
url: `${this.baseUrl}/groups/`,
});
Expand All @@ -174,8 +174,8 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
return this.queryITwinApi({
url: `${this.baseUrl}/groups/${groupId}`,
method: "PATCH",
body: body,
signal: signal,
body,
signal,
});
}

Expand Down Expand Up @@ -203,14 +203,12 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
});
}

async createExtension(
args: CreateExtensionParams,
): Promise<ExtensionResponse> {
async createExtension(args: CreateExtensionParams): Promise<ExtensionResponse> {
const { savedViewId, signal, ...body } = args;
return this.queryITwinApi({
url: `${this.baseUrl}/${savedViewId}/extensions/`,
method: "PUT",
body: body,
body,
signal,
});
}
Expand All @@ -233,9 +231,8 @@ export class ITwinSavedViewsClient implements SavedViewsClient {

async getAllTags(args: GetTagsParams): Promise<TagListResponse> {
const iModelId = args.iModelId ? `&iModelId=${args.iModelId}` : "";
const url = `${this.baseUrl}/tags/?iTwinId=${args.iTwinId}${iModelId}`;
return this.queryITwinApi({
url: url,
url: `${this.baseUrl}/tags/?iTwinId=${args.iTwinId}${iModelId}`,
method: "GET",
signal: args.signal,
});
Expand All @@ -246,7 +243,7 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
return this.queryITwinApi({
url: `${this.baseUrl}/tags`,
method: "POST",
body: body,
body,
signal,
});
}
Expand All @@ -256,7 +253,7 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
return this.queryITwinApi({
url: `${this.baseUrl}/tags/${tagId}`,
method: "PATCH",
body: body,
body,
signal,
});
}
Expand All @@ -270,14 +267,7 @@ export class ITwinSavedViewsClient implements SavedViewsClient {
}
}

/** Prefer enum for request. */
export enum PreferOptions {
/**
* affects the granularity of the data returned
* ONLY for get requests will be ignored for PUT POST DELETE
* MINIMAL = "return=minimal", least info
* REPRESENTATION = "return=representation" most info
*/
Minimal = "return=minimal",
Representation = "return=representation",
}
Expand All @@ -287,7 +277,7 @@ interface QueryParams {
method: "GET" | "POST" | "PATCH" | "PUT" | "DELETE";
body?: object | undefined;
headers?: {
prefer?: PreferOptions;
Prefer?: PreferOptions;
};
signal?: AbortSignal | undefined;
}
Loading
Loading