diff --git a/src/components/apis/list-of-apis/ko/runtime/api-list-dropdown.ts b/src/components/apis/list-of-apis/ko/runtime/api-list-dropdown.ts index 48b5ed6e7..285a4daef 100644 --- a/src/components/apis/list-of-apis/ko/runtime/api-list-dropdown.ts +++ b/src/components/apis/list-of-apis/ko/runtime/api-list-dropdown.ts @@ -25,7 +25,7 @@ export class ApiListDropdown { public readonly selectedApiName: ko.Observable; public readonly working: ko.Observable; public readonly pattern: ko.Observable; - public readonly tags: ko.Observable; + public readonly tags: ko.Observable; public readonly page: ko.Observable; public readonly hasPager: ko.Computed; public readonly hasPrevPage: ko.Observable; @@ -163,7 +163,7 @@ export class ApiListDropdown { } public async onTagsChange(tags: Tag[]): Promise { - this.tags(tags.map(tag => Utils.getResourceName("tags", tag.id))); + this.tags(tags); } @OnDestroyed() diff --git a/src/components/apis/list-of-apis/ko/runtime/api-list-tiles.ts b/src/components/apis/list-of-apis/ko/runtime/api-list-tiles.ts index a6b491da6..ca8c3330d 100644 --- a/src/components/apis/list-of-apis/ko/runtime/api-list-tiles.ts +++ b/src/components/apis/list-of-apis/ko/runtime/api-list-tiles.ts @@ -24,7 +24,7 @@ export class ApiListTiles { public readonly selectedApiName: ko.Observable; public readonly working: ko.Observable; public readonly pattern: ko.Observable; - public readonly tags: ko.Observable; + public readonly tags: ko.Observable; public readonly page: ko.Observable; public readonly hasPager: ko.Computed; public readonly hasPrevPage: ko.Observable; @@ -146,6 +146,6 @@ export class ApiListTiles { } public async onTagsChange(tags: Tag[]): Promise { - this.tags(tags.map(tag => Utils.getResourceName("tags", tag.id))); + this.tags(tags); } } \ No newline at end of file diff --git a/src/components/apis/list-of-apis/ko/runtime/api-list.ts b/src/components/apis/list-of-apis/ko/runtime/api-list.ts index e9562c2e4..02f36b095 100644 --- a/src/components/apis/list-of-apis/ko/runtime/api-list.ts +++ b/src/components/apis/list-of-apis/ko/runtime/api-list.ts @@ -23,7 +23,7 @@ export class ApiList { public readonly apiGroups: ko.ObservableArray>; public readonly working: ko.Observable; public readonly pattern: ko.Observable; - public readonly tags: ko.Observable; + public readonly tags: ko.Observable; public readonly page: ko.Observable; public readonly hasPager: ko.Computed; public readonly hasPrevPage: ko.Observable; @@ -140,6 +140,6 @@ export class ApiList { } public async onTagsChange(tags: Tag[]): Promise { - this.tags(tags.map(tag => Utils.getResourceName("tags", tag.id))); + this.tags(tags); } } \ No newline at end of file diff --git a/src/components/operations/operation-list/ko/runtime/operation-list.ts b/src/components/operations/operation-list/ko/runtime/operation-list.ts index ff49202ac..946fb16b3 100644 --- a/src/components/operations/operation-list/ko/runtime/operation-list.ts +++ b/src/components/operations/operation-list/ko/runtime/operation-list.ts @@ -29,7 +29,7 @@ export class OperationList { public readonly groupByTag: ko.Observable; public readonly operationGroups: ko.ObservableArray>; public readonly pattern: ko.Observable; - public readonly tags: ko.Observable; + public readonly tags: ko.Observable; public readonly pageNumber: ko.Observable; public readonly hasPrevPage: ko.Observable; public readonly hasNextPage: ko.Observable; @@ -235,7 +235,7 @@ export class OperationList { } public async onTagsChange(tags: Tag[]): Promise { - this.tags(tags.map(tag => Utils.getResourceName("tags", tag.id))); + this.tags(tags); } @OnDestroyed() diff --git a/src/components/tag-input/tag-input.ts b/src/components/tag-input/tag-input.ts index 1c8ddae24..923a1106f 100644 --- a/src/components/tag-input/tag-input.ts +++ b/src/components/tag-input/tag-input.ts @@ -21,6 +21,7 @@ export class TagInput { constructor(private readonly tagService: TagService) { this.tags = ko.observableArray(); + this.scope = ko.observable(); this.pattern = ko.observable(); this.selection = ko.observableArray([]); this.availableTags = ko.computed(() => this.tags().filter(tag => !this.selection().map(x => x.id).includes(tag.id))); @@ -29,7 +30,7 @@ export class TagInput { } @Param() - public scope: string; + public scope: ko.Observable; @Event() public onChange: (tags: Tag[]) => void; @@ -47,10 +48,13 @@ export class TagInput { this.pattern .extend({ rateLimit: { timeout: Constants.defaultInputDelayMs, method: "notifyWhenChangesStop" } }) .subscribe(this.resetSearch); + + this.scope + .subscribe(this.resetSearch); } public async loadPageOfTags(): Promise { - const pageOfTags = await this.tagService.getTags(this.scope, this.pattern()); + const pageOfTags = await this.tagService.getTags(this.scope(), this.pattern()); const tags = pageOfTags.value.filter(tag => !this.selection().map(x => x.id).includes(tag.id)); this.tags(tags); diff --git a/src/contracts/searchQuery.ts b/src/contracts/searchQuery.ts index f9e766ed9..f30c58e9b 100644 --- a/src/contracts/searchQuery.ts +++ b/src/contracts/searchQuery.ts @@ -1,6 +1,8 @@ +import { Tag } from "./../models/tag"; + export interface SearchQuery { pattern?: string; - tags?: string[]; + tags?: Tag[]; skip?: number; take?: number; grouping?: string; diff --git a/src/services/apiService.ts b/src/services/apiService.ts index 2c31c6c26..642587a89 100644 --- a/src/services/apiService.ts +++ b/src/services/apiService.ts @@ -40,7 +40,7 @@ export class ApiService { if (searchQuery) { if (searchQuery.tags) { searchQuery.tags.forEach((tag, index) => { - query = Utils.addQueryParameter(query, `tags[${index}]=${tag}`); + query = Utils.addQueryParameter(query, `tags[${index}]=${tag.name}`); }); } @@ -98,7 +98,7 @@ export class ApiService { if (searchQuery) { if (searchQuery.tags && searchQuery.tags.length > 0) { - const tagFilterEntries = searchQuery.tags.map((tag) => `tag/name eq '${tag}'`); + const tagFilterEntries = searchQuery.tags.map((tag) => `tag/id eq '${Utils.getResourceName("tags", tag.id)}'`); odataFilterEntries.push(`(${tagFilterEntries.join(" or ")})`); } @@ -157,7 +157,7 @@ export class ApiService { if (searchRequest) { if (searchRequest.tags && searchRequest.tags.length > 0) { - const tagFilterEntries = searchRequest.tags.map((tag) => `tag/name eq '${tag}'`); + const tagFilterEntries = searchRequest.tags.map((tag) => `tag/id eq '${Utils.getResourceName("tags", tag.id)}'`); odataFilterEntries.push(`(${tagFilterEntries.join(" or ")})`); } @@ -338,7 +338,7 @@ export class ApiService { if (searchQuery) { searchQuery.tags.forEach((tag, index) => { - query = Utils.addQueryParameter(query, `tags[${index}]=${tag}`); + query = Utils.addQueryParameter(query, `tags[${index}]=${tag.name}`); }); if (searchQuery.pattern) { @@ -363,32 +363,12 @@ export class ApiService { return page; } - private lastApiSchemas = {}; public async getApiSchema(schemaId: string): Promise { - const apiId = schemaId.split("/schemas").shift(); - let cachedApi = this.lastApiSchemas[apiId]; + const contract = await this.mapiClient.get(`${schemaId}`); + const model = new Schema(contract); - if (!cachedApi) { - // clean cache if apiId changed - if (Object.keys(this.lastApiSchemas).length > 0) { - this.lastApiSchemas = {}; - } - this.lastApiSchemas[apiId] = {}; - cachedApi = this.lastApiSchemas[apiId]; - } - - const cached = cachedApi && cachedApi[schemaId]; - if (cached) { - return cached; - } - - const schema = await this.mapiClient.get(`${schemaId}`); - const loaded = new Schema(schema); - - cachedApi[schemaId] = loaded; - - return loaded; + return model; } public async getSchemas(api: Api): Promise> { @@ -419,24 +399,11 @@ export class ApiService { return SchemaType.openapi; } - private lastApiProducts = {}; - public async getAllApiProducts(apiId: string): Promise> { if (!apiId) { throw new Error(`Parameter "apiId" not specified.`); } - - const cachedApi = this.lastApiProducts[apiId]; - - if (!cachedApi) { - // clean cache if apiId changed - if (Object.keys(this.lastApiProducts).length > 0) { - this.lastApiProducts = {}; - } - } else { - return cachedApi; - } - + const result = []; const pageOfProducts = await this.mapiClient.get>(`${apiId}/products`); @@ -447,9 +414,7 @@ export class ApiService { const page = new Page(); page.value = result; page.count = pageOfProducts.count; - // page.nextPage = pageOfProductContracts.nextPage; - this.lastApiProducts[apiId] = page; return page; }