From 206bfd423d4c4fd5b07829560c9e656e2e584424 Mon Sep 17 00:00:00 2001 From: Botis Date: Thu, 26 Oct 2023 18:15:04 +0200 Subject: [PATCH] feat: #1214071 add/update GQL queries getSearchDocumentsQuery, getMoreFacetOptionsQuery and getMoreFacetProductOptionsQuery and the related types --- .../@elastic-suite/gally-admin-shared.ts | 6 +- .../ProductsContainer/ProductsContainer.tsx | 8 +-- packages/shared/src/constants/category.ts | 1 + packages/shared/src/constants/cmsPage.ts | 1 + packages/shared/src/constants/graphql.ts | 68 +++++++++++++++++-- packages/shared/src/constants/index.ts | 3 + packages/shared/src/constants/product.ts | 1 + packages/shared/src/mocks/api.ts | 22 +++--- packages/shared/src/mocks/expandedDocs.ts | 27 ++++---- .../src/mocks/static/contexts/Entrypoint.json | 4 +- packages/shared/src/mocks/static/docs.json | 30 ++++---- ...ions.json => product_sorting_options.json} | 4 +- packages/shared/src/services/__mocks__/api.ts | 6 +- packages/shared/src/services/hydra.test.ts | 4 +- packages/shared/src/types/aggregation.ts | 20 ++++++ .../shared/src/types/categorySortingOption.ts | 15 ---- packages/shared/src/types/cmsPage.ts | 12 ++++ packages/shared/src/types/documents.ts | 58 ++++++---------- packages/shared/src/types/facet.ts | 20 ++++++ packages/shared/src/types/index.ts | 7 +- packages/shared/src/types/products.ts | 50 ++++---------- packages/shared/src/types/sortingOption.ts | 15 ++++ 22 files changed, 230 insertions(+), 152 deletions(-) create mode 100644 packages/shared/src/constants/category.ts create mode 100644 packages/shared/src/constants/cmsPage.ts create mode 100644 packages/shared/src/constants/product.ts rename packages/shared/src/mocks/static/{category_sorting_options.json => product_sorting_options.json} (81%) create mode 100644 packages/shared/src/types/aggregation.ts delete mode 100644 packages/shared/src/types/categorySortingOption.ts create mode 100644 packages/shared/src/types/cmsPage.ts create mode 100644 packages/shared/src/types/facet.ts create mode 100644 packages/shared/src/types/sortingOption.ts diff --git a/packages/components/__mocks__/@elastic-suite/gally-admin-shared.ts b/packages/components/__mocks__/@elastic-suite/gally-admin-shared.ts index 5edc2677..f35173b7 100644 --- a/packages/components/__mocks__/@elastic-suite/gally-admin-shared.ts +++ b/packages/components/__mocks__/@elastic-suite/gally-admin-shared.ts @@ -1,7 +1,7 @@ import { api } from '@elastic-suite/gally-admin-shared/src/mocks' import catalog from '@elastic-suite/gally-admin-shared/src/mocks/static/catalog.json' -import categorySortingOptions from '@elastic-suite/gally-admin-shared/src/mocks/static/category_sorting_options.json' +import productSortingOptions from '@elastic-suite/gally-admin-shared/src/mocks/static/product_sorting_options.json' import docs from '@elastic-suite/gally-admin-shared/src/mocks/static/docs.json' import entrypoint from '@elastic-suite/gally-admin-shared/src/mocks/static/index.json' import graphql from '@elastic-suite/gally-admin-shared/src/mocks/static/graphql.json' @@ -46,9 +46,9 @@ fetchApi.mockImplementation((_, resource) => { data = { ...metadata } } else if ( typeof resource === 'string' && - resource.endsWith('category_sorting_options') + resource.endsWith('product_sorting_options') ) { - data = { ...categorySortingOptions } + data = { ...productSortingOptions } } else if ( (typeof resource !== 'string' && resource.title.toLowerCase() === 'source_field_option_label') || diff --git a/packages/components/src/components/stateful/ProductsContainer/ProductsContainer.tsx b/packages/components/src/components/stateful/ProductsContainer/ProductsContainer.tsx index 7eb1a3ef..29952eff 100644 --- a/packages/components/src/components/stateful/ProductsContainer/ProductsContainer.tsx +++ b/packages/components/src/components/stateful/ProductsContainer/ProductsContainer.tsx @@ -10,11 +10,11 @@ import { useTranslation } from 'next-i18next' import { ICategory, - ICategorySortingOption, IGraphqlProductPosition, IParsedCategoryConfiguration, IProductFieldFilterInput, IProductPositions, + ISortingOption, LoadStatus, getProductPosition, } from '@elastic-suite/gally-admin-shared' @@ -110,12 +110,12 @@ function ProductsContainer(props: IProps): JSX.Element { setBottomSelectedRows([]) } - const resourceName = 'CategorySortingOption' + const resourceName = 'ProductSortingOption' const resourceSortingOption = useResource(resourceName) - const [{ data }] = useApiList(resourceSortingOption) + const [{ data }] = useApiList(resourceSortingOption) const sortOption = data - ? data[`hydra:member`].map((obj: ICategorySortingOption) => ({ + ? data[`hydra:member`].map((obj: ISortingOption) => ({ value: obj.code, ...obj, })) diff --git a/packages/shared/src/constants/category.ts b/packages/shared/src/constants/category.ts new file mode 100644 index 00000000..217203be --- /dev/null +++ b/packages/shared/src/constants/category.ts @@ -0,0 +1 @@ +export const categoryEntityType = 'category' diff --git a/packages/shared/src/constants/cmsPage.ts b/packages/shared/src/constants/cmsPage.ts new file mode 100644 index 00000000..8d638eeb --- /dev/null +++ b/packages/shared/src/constants/cmsPage.ts @@ -0,0 +1 @@ +export const cmsPageEntityType = 'cms_page' diff --git a/packages/shared/src/constants/graphql.ts b/packages/shared/src/constants/graphql.ts index 016023d4..7b7572cb 100644 --- a/packages/shared/src/constants/graphql.ts +++ b/packages/shared/src/constants/graphql.ts @@ -2,6 +2,7 @@ import { VariableType, jsonToGraphQLQuery } from 'json-to-graphql-query' import { IGraphqlQueryContent, IProductFieldFilterInput } from '../types' import { IDocumentFieldFilterInput } from '../types/documents' +import { categoryEntityType } from './category' export function getSearchProductsQuery( filter: IProductFieldFilterInput | IProductFieldFilterInput[] = null, @@ -98,7 +99,34 @@ export function getSearchCategoryQueryContent( filter: IDocumentFieldFilterInput | IDocumentFieldFilterInput[] = null, withAggregations = false ): IGraphqlQueryContent { - return getSearchDocumentQueryContent(filter, withAggregations, 'category') + return getSearchDocumentQueryContent( + filter, + withAggregations, + categoryEntityType + ) +} + +export function getSearchDocumentsQuery( + entityType: string, + filter: IDocumentFieldFilterInput | IDocumentFieldFilterInput[] = null, + withAggregations = false +): string { + const documentQueryContent = getSearchDocumentQueryContent( + filter, + withAggregations, + entityType + ) + return jsonToGraphQLQuery({ + query: { + __name: 'getDocuments', + __variables: { ...documentQueryContent.variables }, + documents: { + __aliasFor: 'documents', + __args: { ...documentQueryContent.args }, + ...documentQueryContent.fields, + }, + }, + }) } export function getSearchDocumentQueryContent( @@ -162,15 +190,18 @@ export function getSearchDocumentQueryContent( } export function getAutoCompleteSearchQuery( - filter: IProductFieldFilterInput | IProductFieldFilterInput[] = null, + productFilter: IProductFieldFilterInput | IProductFieldFilterInput[] = null, + categoryFilter: + | IDocumentFieldFilterInput + | IDocumentFieldFilterInput[] = null, withAggregations = false ): string { const productQueryContent = getSearchProductsQueryContent( - filter, + productFilter, withAggregations ) const categoryQueryContent = getSearchCategoryQueryContent( - filter, + categoryFilter, withAggregations ) return jsonToGraphQLQuery({ @@ -195,6 +226,35 @@ export function getAutoCompleteSearchQuery( } export function getMoreFacetOptionsQuery( + filter: IDocumentFieldFilterInput | IDocumentFieldFilterInput[] = null +): string { + return jsonToGraphQLQuery({ + query: { + __name: 'viewMoreFacetOptions', + __variables: { + entityType: 'String!', + localizedCatalog: 'String!', + aggregation: 'String!', + search: 'String', + }, + viewMoreFacetOptions: { + __args: { + entityType: new VariableType('entityType'), + localizedCatalog: new VariableType('localizedCatalog'), + aggregation: new VariableType('aggregation'), + search: new VariableType('search'), + filter, + }, + id: true, + value: true, + label: true, + count: true, + }, + }, + }) +} + +export function getMoreFacetProductOptionsQuery( filter: IProductFieldFilterInput | IProductFieldFilterInput[] = null ): string { return jsonToGraphQLQuery({ diff --git a/packages/shared/src/constants/index.ts b/packages/shared/src/constants/index.ts index 8894b6f5..6afde8ec 100644 --- a/packages/shared/src/constants/index.ts +++ b/packages/shared/src/constants/index.ts @@ -1,7 +1,10 @@ export * from './api' +export * from './category' +export * from './cmsPage' export * from './customTable' export * from './graphql' export * from './hydra' +export * from './product' export * from './rules' export * from './theme' export * from './url' diff --git a/packages/shared/src/constants/product.ts b/packages/shared/src/constants/product.ts new file mode 100644 index 00000000..6ff62c03 --- /dev/null +++ b/packages/shared/src/constants/product.ts @@ -0,0 +1 @@ +export const productEntityType = 'product' diff --git a/packages/shared/src/mocks/api.ts b/packages/shared/src/mocks/api.ts index 873a19f8..bc95dbf8 100644 --- a/packages/shared/src/mocks/api.ts +++ b/packages/shared/src/mocks/api.ts @@ -99,7 +99,7 @@ export const fieldDropdownWithApiOptions = { gally: { input: 'select', options: { - api_rest: '/category_sorting_options', + api_rest: '/product_sorting_options', }, editable: false, position: 10, @@ -1806,7 +1806,7 @@ export const resources = [ url: 'https://localhost/categories', }, { - '@id': 'https://localhost/docs.jsonld#CategorySortingOption', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption', '@type': 'http://www.w3.org/ns/hydra/core#Class', supportedOperation: { '@type': [ @@ -1814,18 +1814,18 @@ export const resources = [ 'http://schema.org/FindAction', ], method: 'GET', - title: 'Retrieves the collection of CategorySortingOption resources.', - label: 'Retrieves the collection of CategorySortingOption resources.', + title: 'Retrieves the collection of ProductSortingOption resources.', + label: 'Retrieves the collection of ProductSortingOption resources.', returns: { '@id': 'http://www.w3.org/ns/hydra/core#Collection' }, }, supportedProperty: [ { '@type': 'http://www.w3.org/ns/hydra/core#SupportedProperty', property: { - '@id': 'https://localhost/docs.jsonld#CategorySortingOption/label', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption/label', '@type': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property', domain: { - '@id': 'https://localhost/docs.jsonld#CategorySortingOption', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption', }, range: { '@id': 'http://www.w3.org/2001/XMLSchema#string' }, label: 'label', @@ -1838,10 +1838,10 @@ export const resources = [ { '@type': 'http://www.w3.org/ns/hydra/core#SupportedProperty', property: { - '@id': 'https://localhost/docs.jsonld#CategorySortingOption/code', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption/code', '@type': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property', domain: { - '@id': 'https://localhost/docs.jsonld#CategorySortingOption', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption', }, range: { '@id': 'http://www.w3.org/2001/XMLSchema#string' }, label: 'code', @@ -1852,9 +1852,9 @@ export const resources = [ writeable: true, }, ], - title: 'CategorySortingOption', - label: 'CategorySortingOption', - url: 'https://localhost/category_sorting_options', + title: 'ProductSortingOption', + label: 'ProductSortingOption', + url: 'https://localhost/product_sorting_options', }, { '@id': 'https://localhost/docs.jsonld#CategoryConfiguration', diff --git a/packages/shared/src/mocks/expandedDocs.ts b/packages/shared/src/mocks/expandedDocs.ts index 81ee1ddd..cc164d88 100644 --- a/packages/shared/src/mocks/expandedDocs.ts +++ b/packages/shared/src/mocks/expandedDocs.ts @@ -2545,7 +2545,7 @@ export const expandedDocs = { 'http://www.w3.org/2000/01/rdf-schema#label': [{ '@value': 'Category' }], }, { - '@id': 'https://localhost/docs.jsonld#CategorySortingOption', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption', '@type': ['http://www.w3.org/ns/hydra/core#Class'], 'http://www.w3.org/ns/hydra/core#supportedOperation': [], 'http://www.w3.org/ns/hydra/core#supportedProperty': [ @@ -2553,12 +2553,11 @@ export const expandedDocs = { '@type': ['http://www.w3.org/ns/hydra/core#SupportedProperty'], 'http://www.w3.org/ns/hydra/core#property': [ { - '@id': - 'https://localhost/docs.jsonld#CategorySortingOption/label', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption/label', '@type': ['http://www.w3.org/1999/02/22-rdf-syntax-ns#Property'], 'http://www.w3.org/2000/01/rdf-schema#domain': [ { - '@id': 'https://localhost/docs.jsonld#CategorySortingOption', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption', }, ], 'http://www.w3.org/2000/01/rdf-schema#range': [ @@ -2578,11 +2577,11 @@ export const expandedDocs = { '@type': ['http://www.w3.org/ns/hydra/core#SupportedProperty'], 'http://www.w3.org/ns/hydra/core#property': [ { - '@id': 'https://localhost/docs.jsonld#CategorySortingOption/code', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption/code', '@type': ['http://www.w3.org/1999/02/22-rdf-syntax-ns#Property'], 'http://www.w3.org/2000/01/rdf-schema#domain': [ { - '@id': 'https://localhost/docs.jsonld#CategorySortingOption', + '@id': 'https://localhost/docs.jsonld#ProductSortingOption', }, ], 'http://www.w3.org/2000/01/rdf-schema#range': [ @@ -2600,10 +2599,10 @@ export const expandedDocs = { }, ], 'http://www.w3.org/ns/hydra/core#title': [ - { '@value': 'CategorySortingOption' }, + { '@value': 'ProductSortingOption' }, ], 'http://www.w3.org/2000/01/rdf-schema#label': [ - { '@value': 'CategorySortingOption' }, + { '@value': 'ProductSortingOption' }, ], }, { @@ -4470,7 +4469,7 @@ export const expandedDocs = { 'http://www.w3.org/ns/hydra/core#property': [ { '@id': - 'https://localhost/docs.jsonld#Entrypoint/categorySortingOption', + 'https://localhost/docs.jsonld#Entrypoint/productSortingOption', '@type': ['http://www.w3.org/ns/hydra/core#Link'], 'http://www.w3.org/2000/01/rdf-schema#domain': [ { '@id': 'https://localhost/docs.jsonld#Entrypoint' }, @@ -4487,13 +4486,13 @@ export const expandedDocs = { 'http://www.w3.org/ns/hydra/core#title': [ { '@value': - 'Retrieves the collection of CategorySortingOption resources.', + 'Retrieves the collection of ProductSortingOption resources.', }, ], 'http://www.w3.org/2000/01/rdf-schema#label': [ { '@value': - 'Retrieves the collection of CategorySortingOption resources.', + 'Retrieves the collection of ProductSortingOption resources.', }, ], 'http://www.w3.org/ns/hydra/core#returns': [ @@ -4503,7 +4502,7 @@ export const expandedDocs = { ], 'http://www.w3.org/2000/01/rdf-schema#label': [ { - '@value': 'The collection of CategorySortingOption resources', + '@value': 'The collection of ProductSortingOption resources', }, ], 'http://www.w3.org/2000/01/rdf-schema#range': [ @@ -4514,7 +4513,7 @@ export const expandedDocs = { 'http://www.w3.org/2002/07/owl#allValuesFrom': [ { '@id': - 'https://localhost/docs.jsonld#CategorySortingOption', + 'https://localhost/docs.jsonld#ProductSortingOption', }, ], 'http://www.w3.org/2002/07/owl#onProperty': [ @@ -4528,7 +4527,7 @@ export const expandedDocs = { ], 'http://www.w3.org/ns/hydra/core#readable': [{ '@value': true }], 'http://www.w3.org/ns/hydra/core#title': [ - { '@value': 'The collection of CategorySortingOption resources' }, + { '@value': 'The collection of ProductSortingOption resources' }, ], 'http://www.w3.org/ns/hydra/core#writeable': [{ '@value': false }], }, diff --git a/packages/shared/src/mocks/static/contexts/Entrypoint.json b/packages/shared/src/mocks/static/contexts/Entrypoint.json index ec2d340f..f25fe549 100644 --- a/packages/shared/src/mocks/static/contexts/Entrypoint.json +++ b/packages/shared/src/mocks/static/contexts/Entrypoint.json @@ -65,8 +65,8 @@ "@type": "@id" }, "categoryTree": { "@id": "Entrypoint/categoryTree", "@type": "@id" }, - "categorySortingOption": { - "@id": "Entrypoint/categorySortingOption", + "productSortingOption": { + "@id": "Entrypoint/productSortingOption", "@type": "@id" }, "configuration": { "@id": "Entrypoint/configuration", "@type": "@id" }, diff --git a/packages/shared/src/mocks/static/docs.json b/packages/shared/src/mocks/static/docs.json index 8a537d33..5dd884c4 100644 --- a/packages/shared/src/mocks/static/docs.json +++ b/packages/shared/src/mocks/static/docs.json @@ -1129,8 +1129,8 @@ "gally": { "input": "select", "options": { - "api_rest": "/category_sorting_options", - "api_graphql": "categorySortingOptions" + "api_rest": "/product_sorting_options", + "api_graphql": "productSortingOptions" } } }, @@ -2320,18 +2320,18 @@ ] }, { - "@id": "#CategorySortingOption", + "@id": "#ProductSortingOption", "@type": "hydra:Class", - "rdfs:label": "CategorySortingOption", - "hydra:title": "CategorySortingOption", + "rdfs:label": "ProductSortingOption", + "hydra:title": "ProductSortingOption", "hydra:supportedProperty": [ { "@type": "hydra:SupportedProperty", "hydra:property": { - "@id": "#CategorySortingOption/code", + "@id": "#ProductSortingOption/code", "@type": "rdf:Property", "rdfs:label": "code", - "domain": "#CategorySortingOption", + "domain": "#ProductSortingOption", "range": "xmls:string" }, "hydra:title": "code", @@ -2342,10 +2342,10 @@ { "@type": "hydra:SupportedProperty", "hydra:property": { - "@id": "#CategorySortingOption/label", + "@id": "#ProductSortingOption/label", "@type": "rdf:Property", "rdfs:label": "label", - "domain": "#CategorySortingOption", + "domain": "#ProductSortingOption", "range": "xmls:string" }, "hydra:title": "label", @@ -3624,16 +3624,16 @@ { "@type": "hydra:SupportedProperty", "hydra:property": { - "@id": "#Entrypoint/categorySortingOption", + "@id": "#Entrypoint/productSortingOption", "@type": "hydra:Link", "domain": "#Entrypoint", - "rdfs:label": "The collection of CategorySortingOption resources", + "rdfs:label": "The collection of ProductSortingOption resources", "rdfs:range": [ { "@id": "hydra:Collection" }, { "owl:equivalentClass": { "owl:onProperty": { "@id": "hydra:member" }, - "owl:allValuesFrom": { "@id": "#CategorySortingOption" } + "owl:allValuesFrom": { "@id": "#ProductSortingOption" } } } ], @@ -3641,13 +3641,13 @@ { "@type": ["hydra:Operation", "schema:FindAction"], "hydra:method": "GET", - "hydra:title": "Retrieves the collection of CategorySortingOption resources.", - "rdfs:label": "Retrieves the collection of CategorySortingOption resources.", + "hydra:title": "Retrieves the collection of ProductSortingOption resources.", + "rdfs:label": "Retrieves the collection of ProductSortingOption resources.", "returns": "hydra:Collection" } ] }, - "hydra:title": "The collection of CategorySortingOption resources", + "hydra:title": "The collection of ProductSortingOption resources", "hydra:readable": true, "hydra:writeable": false }, diff --git a/packages/shared/src/mocks/static/category_sorting_options.json b/packages/shared/src/mocks/static/product_sorting_options.json similarity index 81% rename from packages/shared/src/mocks/static/category_sorting_options.json rename to packages/shared/src/mocks/static/product_sorting_options.json index 12a6acc2..633427e5 100644 --- a/packages/shared/src/mocks/static/category_sorting_options.json +++ b/packages/shared/src/mocks/static/product_sorting_options.json @@ -1,6 +1,6 @@ { - "@context": "/contexts/CategorySortingOption", - "@id": "/category_sorting_options", + "@context": "/contexts/ProductSortingOption", + "@id": "/product_sorting_options", "@type": "hydra:Collection", "hydra:member": [ { diff --git a/packages/shared/src/services/__mocks__/api.ts b/packages/shared/src/services/__mocks__/api.ts index a30843a6..e12e255d 100644 --- a/packages/shared/src/services/__mocks__/api.ts +++ b/packages/shared/src/services/__mocks__/api.ts @@ -1,4 +1,4 @@ -import categorySortingOptions from '../../mocks/static/category_sorting_options.json' +import productSortingOptions from '../../mocks/static/product_sorting_options.json' import metadata from '../../mocks/static/metadata.json' import sourceFieldOptionLabels from '../../mocks/static/source_field_option_labels.json' import { IResource, ISearchParameters } from '../../types' @@ -18,9 +18,9 @@ export const fetchApi = jest.fn( data = { ...metadata } } else if ( typeof resource === 'string' && - resource.endsWith('category_sorting_options') + resource.endsWith('product_sorting_options') ) { - data = { ...categorySortingOptions } + data = { ...productSortingOptions } } else if ( (typeof resource !== 'string' && resource.title.toLowerCase() === 'source_field_option_label') || diff --git a/packages/shared/src/services/hydra.test.ts b/packages/shared/src/services/hydra.test.ts index 801b5008..96c5fd35 100644 --- a/packages/shared/src/services/hydra.test.ts +++ b/packages/shared/src/services/hydra.test.ts @@ -1,4 +1,4 @@ -import categorySortingOptions from '../mocks/static/category_sorting_options.json' +import productSortingOptions from '../mocks/static/product_sorting_options.json' import metadata from '../mocks/static/metadata.json' import sourceFieldOptions from '../mocks/static/source_field_options.json' import sourceFieldOptionLabels from '../mocks/static/source_field_option_labels.json' @@ -440,7 +440,7 @@ describe('Hydra service', () => { describe('getOptionsFromApiSchema', () => { it('Should return the options', () => { - expect(getOptionsFromApiSchema(categorySortingOptions)).toEqual([ + expect(getOptionsFromApiSchema(productSortingOptions)).toEqual([ { label: 'Position', value: 'position', diff --git a/packages/shared/src/types/aggregation.ts b/packages/shared/src/types/aggregation.ts new file mode 100644 index 00000000..a8b88a1a --- /dev/null +++ b/packages/shared/src/types/aggregation.ts @@ -0,0 +1,20 @@ +export enum AggregationType { + CATEGORY = 'category', + CHECKBOX = 'checkbox', + SLIDER = 'slider', + BOOLEAN = 'boolean', +} +export interface IGraphqlAggregation { + count: number + field: string + label: string + type: AggregationType + options: IGraphqlAggregationOption[] + hasMore: boolean | null +} + +export interface IGraphqlAggregationOption { + count: number + label: string + value: string +} diff --git a/packages/shared/src/types/categorySortingOption.ts b/packages/shared/src/types/categorySortingOption.ts deleted file mode 100644 index 7cadee15..00000000 --- a/packages/shared/src/types/categorySortingOption.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { IJsonldBase } from './jsonld' - -export enum SortOrder { - ASC = 'asc', - DESC = 'desc', -} - -export interface ICategorySortingOption extends IJsonldBase { - label: string - code: string -} - -export interface IGraphqlCategorySortingOption { - categorySortingOptions: ICategorySortingOption[] -} diff --git a/packages/shared/src/types/cmsPage.ts b/packages/shared/src/types/cmsPage.ts new file mode 100644 index 00000000..80ef36c1 --- /dev/null +++ b/packages/shared/src/types/cmsPage.ts @@ -0,0 +1,12 @@ +import { IGraphqlDocument, IGraphqlSearchDocument } from './documents' + +export interface IGraphqlSearchCmsPages { + cmsPages: IGraphqlSearchDocument +} + +export interface ICmsPage extends IGraphqlDocument { + id: string + title: string + content: string + contentHeading: string +} diff --git a/packages/shared/src/types/documents.ts b/packages/shared/src/types/documents.ts index 1128d3a9..18dbf45e 100644 --- a/packages/shared/src/types/documents.ts +++ b/packages/shared/src/types/documents.ts @@ -1,21 +1,13 @@ -import { SortOrder } from './categorySortingOption' -import { ISearchParameters } from './fetch' +import { SortOrder } from './sortingOption' +import { IGraphqlAggregation } from './aggregation' export interface IGraphqlSearchDocumentsVariables { entityType: string localizedCatalog: string - currentCategoryId?: string currentPage?: number filter?: IDocumentFieldFilterInput[] | IDocumentFieldFilterInput pageSize?: number search?: string - sort?: Record -} - -export enum AggregationType { - CATEGORY = 'category', - CHECKBOX = 'checkbox', - SLIDER = 'slider', - BOOLEAN = 'boolean', + sort?: IGraphqlDocumentSort } export interface IGraphqlSearchDocuments { @@ -26,7 +18,7 @@ export interface IGraphqlSearchDocument { collection: IGraphqlDocument[] paginationInfo: IGraphqlDocumentPaginationInfo sortInfo: IGraphqlDocumentSortInfo - aggregations?: IGraphqlDocumentAggregation[] + aggregations?: IGraphqlAggregation[] } export interface IGraphqlDocument { @@ -40,6 +32,10 @@ export interface IGraphqlDocumentPaginationInfo { totalCount: number } +export interface IGraphqlDocumentSort { + field: string + direction: SortOrder +} export interface IGraphqlDocumentSortInfo { current: IGraphqlDocumentSortInfoCurrent[] } @@ -49,26 +45,6 @@ export interface IGraphqlDocumentSortInfoCurrent { direction: SortOrder } -export interface IGraphqlDocumentAggregation { - count: number - field: string - label: string - type: AggregationType - options: IGraphqlDocumentAggregationOption[] - hasMore: boolean | null -} - -export interface IGraphqlDocumentAggregationOption { - count: number - label: string - value: string -} - -export interface IFetchParams { - options: RequestInit - searchParameters: ISearchParameters -} - export interface IDocumentBoolFilterInput { _must?: IDocumentFieldFilterInput[] _should?: IDocumentFieldFilterInput[] @@ -76,18 +52,18 @@ export interface IDocumentBoolFilterInput { } export interface IDocumentEqualFilterInput { - field?: string - eq: string - in: string[] + field: string + eq?: string + in?: string[] } export interface IDocumentMatchFilterInput { - field?: string - match?: string + field: string + match: string } export interface IDocumentRangeFilterInput { - field?: string + field: string gte?: string gt?: string lt?: string @@ -95,9 +71,13 @@ export interface IDocumentRangeFilterInput { } export interface IDocumentExistFilterInput { - field?: string + field: string } export interface IDocumentFieldFilterInput { boolFilter?: IDocumentBoolFilterInput + equalFilter?: IDocumentEqualFilterInput + matchFilter?: IDocumentMatchFilterInput + rangeFilter?: IDocumentRangeFilterInput + existFilter?: IDocumentExistFilterInput } diff --git a/packages/shared/src/types/facet.ts b/packages/shared/src/types/facet.ts new file mode 100644 index 00000000..303b9f67 --- /dev/null +++ b/packages/shared/src/types/facet.ts @@ -0,0 +1,20 @@ +import { IDocumentFieldFilterInput } from './documents' + +export interface IGraphqlViewMoreFacetOption { + id: string + value: string + label: string + count: number +} + +export interface IGraphqlViewMoreFacetOptionsVariables { + entityType: string + aggregation: string + localizedCatalog: string + filter?: IDocumentFieldFilterInput[] | IDocumentFieldFilterInput + search?: string +} + +export interface IGraphqlViewMoreFacetOptions { + viewMoreFacetOptions: IGraphqlViewMoreFacetOption[] +} diff --git a/packages/shared/src/types/index.ts b/packages/shared/src/types/index.ts index a8b2043e..e8fbda8c 100644 --- a/packages/shared/src/types/index.ts +++ b/packages/shared/src/types/index.ts @@ -1,15 +1,19 @@ +export * from './aggregation' export * from './api' export * from './catalog' export * from './categories' export * from './categoryConfiguration' -export * from './categorySortingOption' +export * from './sortingOption' +export * from './cmsPage' export * from './customTables' export * from './docsJson' export * from './docsJsonld' +export * from './documents' export * from './entrypoint' export * from './expansion' export * from './extraBundle' export * from './extraConfiguration' +export * from './facet' export * from './fetch' export * from './field' export * from './form' @@ -38,4 +42,3 @@ export * from './textFieldTags' export * from './requestType' export * from './tree' export * from './user' -export * from './categorySortingOption' diff --git a/packages/shared/src/types/products.ts b/packages/shared/src/types/products.ts index be13abb6..60b82e36 100644 --- a/packages/shared/src/types/products.ts +++ b/packages/shared/src/types/products.ts @@ -1,6 +1,11 @@ -import { SortOrder } from './categorySortingOption' +import { ISortingOption, SortOrder } from './sortingOption' import { IPrice, IStock } from './customTables' import { ISearchParameters } from './fetch' +import { IGraphqlAggregation } from './aggregation' +import { + IGraphqlViewMoreFacetOption, + IGraphqlViewMoreFacetOptionsVariables, +} from './facet' export enum ProductRequestType { CATALOG = 'product_catalog', @@ -19,13 +24,6 @@ export interface IGraphqlSearchProductsVariables { sort?: Record } -export enum AggregationType { - CATEGORY = 'category', - CHECKBOX = 'checkbox', - SLIDER = 'slider', - BOOLEAN = 'boolean', -} - export interface IGraphqlSearchProducts { products: IGraphqlSearchProduct } @@ -34,7 +32,7 @@ export interface IGraphqlSearchProduct { collection: IGraphqlProduct[] paginationInfo: IGraphqlProductPaginationInfo sortInfo: IGraphqlProductSortInfo - aggregations?: IGraphqlProductAggregation[] + aggregations?: IGraphqlAggregation[] } export interface IGraphqlProduct { @@ -61,21 +59,6 @@ export interface IGraphqlProductSortInfoCurrent { direction: SortOrder } -export interface IGraphqlProductAggregation { - count: number - field: string - label: string - type: AggregationType - options: IGraphqlProductAggregationOption[] - hasMore: boolean | null -} - -export interface IGraphqlProductAggregationOption { - count: number - label: string - value: string -} - export interface IFetchParams { options: RequestInit searchParameters: ISearchParameters @@ -130,21 +113,16 @@ export interface IProductFieldFilterInput { [key: string]: ITypeFilterInput } -export interface IGraphqlViewMoreFacetOption { - id: string - value: string - label: string - count: number -} - -export interface IGraphqlViewMoreFacetOptionsVariables { - aggregation: string - localizedCatalog: string +export interface IGraphqlViewMoreProductFacetOptionsVariables + extends Omit { currentCategoryId?: string filter?: IProductFieldFilterInput[] | IProductFieldFilterInput - search?: string } -export interface IGraphqlViewMoreFacetOptions { +export interface IGraphqlViewMoreProductFacetOptions { viewMoreProductFacetOptions: IGraphqlViewMoreFacetOption[] } + +export interface IGraphqlProductSortingOptions { + productSortingOptions: ISortingOption[] +} diff --git a/packages/shared/src/types/sortingOption.ts b/packages/shared/src/types/sortingOption.ts new file mode 100644 index 00000000..d009b66e --- /dev/null +++ b/packages/shared/src/types/sortingOption.ts @@ -0,0 +1,15 @@ +import { IJsonldBase } from './jsonld' + +export enum SortOrder { + ASC = 'asc', + DESC = 'desc', +} + +export interface ISortingOption extends IJsonldBase { + label: string + code: string +} + +export interface IGraphqlSortingOptions { + sortingOptions: ISortingOption[] +}