diff --git a/packages/components/__mocks__/@elastic-suite/gally-admin-shared.ts b/packages/components/__mocks__/@elastic-suite/gally-admin-shared.ts index f35173b7..5edc2677 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 productSortingOptions from '@elastic-suite/gally-admin-shared/src/mocks/static/product_sorting_options.json' +import categorySortingOptions from '@elastic-suite/gally-admin-shared/src/mocks/static/category_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('product_sorting_options') + resource.endsWith('category_sorting_options') ) { - data = { ...productSortingOptions } + data = { ...categorySortingOptions } } 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 29952eff..7eb1a3ef 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 = 'ProductSortingOption' + const resourceName = 'CategorySortingOption' const resourceSortingOption = useResource(resourceName) - const [{ data }] = useApiList(resourceSortingOption) + const [{ data }] = useApiList(resourceSortingOption) const sortOption = data - ? data[`hydra:member`].map((obj: ISortingOption) => ({ + ? data[`hydra:member`].map((obj: ICategorySortingOption) => ({ value: obj.code, ...obj, })) diff --git a/packages/shared/src/constants/category.ts b/packages/shared/src/constants/category.ts deleted file mode 100644 index 217203be..00000000 --- a/packages/shared/src/constants/category.ts +++ /dev/null @@ -1 +0,0 @@ -export const categoryEntityType = 'category' diff --git a/packages/shared/src/constants/cmsPage.ts b/packages/shared/src/constants/cmsPage.ts deleted file mode 100644 index 8d638eeb..00000000 --- a/packages/shared/src/constants/cmsPage.ts +++ /dev/null @@ -1 +0,0 @@ -export const cmsPageEntityType = 'cms_page' diff --git a/packages/shared/src/constants/graphql.ts b/packages/shared/src/constants/graphql.ts index 7b7572cb..016023d4 100644 --- a/packages/shared/src/constants/graphql.ts +++ b/packages/shared/src/constants/graphql.ts @@ -2,7 +2,6 @@ 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, @@ -99,34 +98,7 @@ export function getSearchCategoryQueryContent( filter: IDocumentFieldFilterInput | IDocumentFieldFilterInput[] = null, withAggregations = false ): IGraphqlQueryContent { - 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, - }, - }, - }) + return getSearchDocumentQueryContent(filter, withAggregations, 'category') } export function getSearchDocumentQueryContent( @@ -190,18 +162,15 @@ export function getSearchDocumentQueryContent( } export function getAutoCompleteSearchQuery( - productFilter: IProductFieldFilterInput | IProductFieldFilterInput[] = null, - categoryFilter: - | IDocumentFieldFilterInput - | IDocumentFieldFilterInput[] = null, + filter: IProductFieldFilterInput | IProductFieldFilterInput[] = null, withAggregations = false ): string { const productQueryContent = getSearchProductsQueryContent( - productFilter, + filter, withAggregations ) const categoryQueryContent = getSearchCategoryQueryContent( - categoryFilter, + filter, withAggregations ) return jsonToGraphQLQuery({ @@ -226,35 +195,6 @@ 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 6afde8ec..8894b6f5 100644 --- a/packages/shared/src/constants/index.ts +++ b/packages/shared/src/constants/index.ts @@ -1,10 +1,7 @@ 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 deleted file mode 100644 index 6ff62c03..00000000 --- a/packages/shared/src/constants/product.ts +++ /dev/null @@ -1 +0,0 @@ -export const productEntityType = 'product' diff --git a/packages/shared/src/mocks/api.ts b/packages/shared/src/mocks/api.ts index bc95dbf8..873a19f8 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: '/product_sorting_options', + api_rest: '/category_sorting_options', }, editable: false, position: 10, @@ -1806,7 +1806,7 @@ export const resources = [ url: 'https://localhost/categories', }, { - '@id': 'https://localhost/docs.jsonld#ProductSortingOption', + '@id': 'https://localhost/docs.jsonld#CategorySortingOption', '@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 ProductSortingOption resources.', - label: 'Retrieves the collection of ProductSortingOption resources.', + title: 'Retrieves the collection of CategorySortingOption resources.', + label: 'Retrieves the collection of CategorySortingOption 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#ProductSortingOption/label', + '@id': 'https://localhost/docs.jsonld#CategorySortingOption/label', '@type': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property', domain: { - '@id': 'https://localhost/docs.jsonld#ProductSortingOption', + '@id': 'https://localhost/docs.jsonld#CategorySortingOption', }, 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#ProductSortingOption/code', + '@id': 'https://localhost/docs.jsonld#CategorySortingOption/code', '@type': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#Property', domain: { - '@id': 'https://localhost/docs.jsonld#ProductSortingOption', + '@id': 'https://localhost/docs.jsonld#CategorySortingOption', }, range: { '@id': 'http://www.w3.org/2001/XMLSchema#string' }, label: 'code', @@ -1852,9 +1852,9 @@ export const resources = [ writeable: true, }, ], - title: 'ProductSortingOption', - label: 'ProductSortingOption', - url: 'https://localhost/product_sorting_options', + title: 'CategorySortingOption', + label: 'CategorySortingOption', + url: 'https://localhost/category_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 cc164d88..81ee1ddd 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#ProductSortingOption', + '@id': 'https://localhost/docs.jsonld#CategorySortingOption', '@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,11 +2553,12 @@ 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#ProductSortingOption/label', + '@id': + 'https://localhost/docs.jsonld#CategorySortingOption/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#ProductSortingOption', + '@id': 'https://localhost/docs.jsonld#CategorySortingOption', }, ], 'http://www.w3.org/2000/01/rdf-schema#range': [ @@ -2577,11 +2578,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#ProductSortingOption/code', + '@id': 'https://localhost/docs.jsonld#CategorySortingOption/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#ProductSortingOption', + '@id': 'https://localhost/docs.jsonld#CategorySortingOption', }, ], 'http://www.w3.org/2000/01/rdf-schema#range': [ @@ -2599,10 +2600,10 @@ export const expandedDocs = { }, ], 'http://www.w3.org/ns/hydra/core#title': [ - { '@value': 'ProductSortingOption' }, + { '@value': 'CategorySortingOption' }, ], 'http://www.w3.org/2000/01/rdf-schema#label': [ - { '@value': 'ProductSortingOption' }, + { '@value': 'CategorySortingOption' }, ], }, { @@ -4469,7 +4470,7 @@ export const expandedDocs = { 'http://www.w3.org/ns/hydra/core#property': [ { '@id': - 'https://localhost/docs.jsonld#Entrypoint/productSortingOption', + 'https://localhost/docs.jsonld#Entrypoint/categorySortingOption', '@type': ['http://www.w3.org/ns/hydra/core#Link'], 'http://www.w3.org/2000/01/rdf-schema#domain': [ { '@id': 'https://localhost/docs.jsonld#Entrypoint' }, @@ -4486,13 +4487,13 @@ export const expandedDocs = { 'http://www.w3.org/ns/hydra/core#title': [ { '@value': - 'Retrieves the collection of ProductSortingOption resources.', + 'Retrieves the collection of CategorySortingOption resources.', }, ], 'http://www.w3.org/2000/01/rdf-schema#label': [ { '@value': - 'Retrieves the collection of ProductSortingOption resources.', + 'Retrieves the collection of CategorySortingOption resources.', }, ], 'http://www.w3.org/ns/hydra/core#returns': [ @@ -4502,7 +4503,7 @@ export const expandedDocs = { ], 'http://www.w3.org/2000/01/rdf-schema#label': [ { - '@value': 'The collection of ProductSortingOption resources', + '@value': 'The collection of CategorySortingOption resources', }, ], 'http://www.w3.org/2000/01/rdf-schema#range': [ @@ -4513,7 +4514,7 @@ export const expandedDocs = { 'http://www.w3.org/2002/07/owl#allValuesFrom': [ { '@id': - 'https://localhost/docs.jsonld#ProductSortingOption', + 'https://localhost/docs.jsonld#CategorySortingOption', }, ], 'http://www.w3.org/2002/07/owl#onProperty': [ @@ -4527,7 +4528,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 ProductSortingOption resources' }, + { '@value': 'The collection of CategorySortingOption resources' }, ], 'http://www.w3.org/ns/hydra/core#writeable': [{ '@value': false }], }, diff --git a/packages/shared/src/mocks/static/product_sorting_options.json b/packages/shared/src/mocks/static/category_sorting_options.json similarity index 81% rename from packages/shared/src/mocks/static/product_sorting_options.json rename to packages/shared/src/mocks/static/category_sorting_options.json index 633427e5..12a6acc2 100644 --- a/packages/shared/src/mocks/static/product_sorting_options.json +++ b/packages/shared/src/mocks/static/category_sorting_options.json @@ -1,6 +1,6 @@ { - "@context": "/contexts/ProductSortingOption", - "@id": "/product_sorting_options", + "@context": "/contexts/CategorySortingOption", + "@id": "/category_sorting_options", "@type": "hydra:Collection", "hydra:member": [ { diff --git a/packages/shared/src/mocks/static/contexts/Entrypoint.json b/packages/shared/src/mocks/static/contexts/Entrypoint.json index f25fe549..ec2d340f 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" }, - "productSortingOption": { - "@id": "Entrypoint/productSortingOption", + "categorySortingOption": { + "@id": "Entrypoint/categorySortingOption", "@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 5dd884c4..8a537d33 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": "/product_sorting_options", - "api_graphql": "productSortingOptions" + "api_rest": "/category_sorting_options", + "api_graphql": "categorySortingOptions" } } }, @@ -2320,18 +2320,18 @@ ] }, { - "@id": "#ProductSortingOption", + "@id": "#CategorySortingOption", "@type": "hydra:Class", - "rdfs:label": "ProductSortingOption", - "hydra:title": "ProductSortingOption", + "rdfs:label": "CategorySortingOption", + "hydra:title": "CategorySortingOption", "hydra:supportedProperty": [ { "@type": "hydra:SupportedProperty", "hydra:property": { - "@id": "#ProductSortingOption/code", + "@id": "#CategorySortingOption/code", "@type": "rdf:Property", "rdfs:label": "code", - "domain": "#ProductSortingOption", + "domain": "#CategorySortingOption", "range": "xmls:string" }, "hydra:title": "code", @@ -2342,10 +2342,10 @@ { "@type": "hydra:SupportedProperty", "hydra:property": { - "@id": "#ProductSortingOption/label", + "@id": "#CategorySortingOption/label", "@type": "rdf:Property", "rdfs:label": "label", - "domain": "#ProductSortingOption", + "domain": "#CategorySortingOption", "range": "xmls:string" }, "hydra:title": "label", @@ -3624,16 +3624,16 @@ { "@type": "hydra:SupportedProperty", "hydra:property": { - "@id": "#Entrypoint/productSortingOption", + "@id": "#Entrypoint/categorySortingOption", "@type": "hydra:Link", "domain": "#Entrypoint", - "rdfs:label": "The collection of ProductSortingOption resources", + "rdfs:label": "The collection of CategorySortingOption resources", "rdfs:range": [ { "@id": "hydra:Collection" }, { "owl:equivalentClass": { "owl:onProperty": { "@id": "hydra:member" }, - "owl:allValuesFrom": { "@id": "#ProductSortingOption" } + "owl:allValuesFrom": { "@id": "#CategorySortingOption" } } } ], @@ -3641,13 +3641,13 @@ { "@type": ["hydra:Operation", "schema:FindAction"], "hydra:method": "GET", - "hydra:title": "Retrieves the collection of ProductSortingOption resources.", - "rdfs:label": "Retrieves the collection of ProductSortingOption resources.", + "hydra:title": "Retrieves the collection of CategorySortingOption resources.", + "rdfs:label": "Retrieves the collection of CategorySortingOption resources.", "returns": "hydra:Collection" } ] }, - "hydra:title": "The collection of ProductSortingOption resources", + "hydra:title": "The collection of CategorySortingOption resources", "hydra:readable": true, "hydra:writeable": false }, diff --git a/packages/shared/src/services/__mocks__/api.ts b/packages/shared/src/services/__mocks__/api.ts index e12e255d..a30843a6 100644 --- a/packages/shared/src/services/__mocks__/api.ts +++ b/packages/shared/src/services/__mocks__/api.ts @@ -1,4 +1,4 @@ -import productSortingOptions from '../../mocks/static/product_sorting_options.json' +import categorySortingOptions from '../../mocks/static/category_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('product_sorting_options') + resource.endsWith('category_sorting_options') ) { - data = { ...productSortingOptions } + data = { ...categorySortingOptions } } 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 96c5fd35..801b5008 100644 --- a/packages/shared/src/services/hydra.test.ts +++ b/packages/shared/src/services/hydra.test.ts @@ -1,4 +1,4 @@ -import productSortingOptions from '../mocks/static/product_sorting_options.json' +import categorySortingOptions from '../mocks/static/category_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(productSortingOptions)).toEqual([ + expect(getOptionsFromApiSchema(categorySortingOptions)).toEqual([ { label: 'Position', value: 'position', diff --git a/packages/shared/src/types/aggregation.ts b/packages/shared/src/types/aggregation.ts deleted file mode 100644 index a8b88a1a..00000000 --- a/packages/shared/src/types/aggregation.ts +++ /dev/null @@ -1,20 +0,0 @@ -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 new file mode 100644 index 00000000..7cadee15 --- /dev/null +++ b/packages/shared/src/types/categorySortingOption.ts @@ -0,0 +1,15 @@ +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 deleted file mode 100644 index 80ef36c1..00000000 --- a/packages/shared/src/types/cmsPage.ts +++ /dev/null @@ -1,12 +0,0 @@ -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 18dbf45e..1128d3a9 100644 --- a/packages/shared/src/types/documents.ts +++ b/packages/shared/src/types/documents.ts @@ -1,13 +1,21 @@ -import { SortOrder } from './sortingOption' -import { IGraphqlAggregation } from './aggregation' +import { SortOrder } from './categorySortingOption' +import { ISearchParameters } from './fetch' export interface IGraphqlSearchDocumentsVariables { entityType: string localizedCatalog: string + currentCategoryId?: string currentPage?: number filter?: IDocumentFieldFilterInput[] | IDocumentFieldFilterInput pageSize?: number search?: string - sort?: IGraphqlDocumentSort + sort?: Record +} + +export enum AggregationType { + CATEGORY = 'category', + CHECKBOX = 'checkbox', + SLIDER = 'slider', + BOOLEAN = 'boolean', } export interface IGraphqlSearchDocuments { @@ -18,7 +26,7 @@ export interface IGraphqlSearchDocument { collection: IGraphqlDocument[] paginationInfo: IGraphqlDocumentPaginationInfo sortInfo: IGraphqlDocumentSortInfo - aggregations?: IGraphqlAggregation[] + aggregations?: IGraphqlDocumentAggregation[] } export interface IGraphqlDocument { @@ -32,10 +40,6 @@ export interface IGraphqlDocumentPaginationInfo { totalCount: number } -export interface IGraphqlDocumentSort { - field: string - direction: SortOrder -} export interface IGraphqlDocumentSortInfo { current: IGraphqlDocumentSortInfoCurrent[] } @@ -45,6 +49,26 @@ 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[] @@ -52,18 +76,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 @@ -71,13 +95,9 @@ 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 deleted file mode 100644 index 303b9f67..00000000 --- a/packages/shared/src/types/facet.ts +++ /dev/null @@ -1,20 +0,0 @@ -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 e8fbda8c..a8b2043e 100644 --- a/packages/shared/src/types/index.ts +++ b/packages/shared/src/types/index.ts @@ -1,19 +1,15 @@ -export * from './aggregation' export * from './api' export * from './catalog' export * from './categories' export * from './categoryConfiguration' -export * from './sortingOption' -export * from './cmsPage' +export * from './categorySortingOption' 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' @@ -42,3 +38,4 @@ 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 60b82e36..be13abb6 100644 --- a/packages/shared/src/types/products.ts +++ b/packages/shared/src/types/products.ts @@ -1,11 +1,6 @@ -import { ISortingOption, SortOrder } from './sortingOption' +import { SortOrder } from './categorySortingOption' import { IPrice, IStock } from './customTables' import { ISearchParameters } from './fetch' -import { IGraphqlAggregation } from './aggregation' -import { - IGraphqlViewMoreFacetOption, - IGraphqlViewMoreFacetOptionsVariables, -} from './facet' export enum ProductRequestType { CATALOG = 'product_catalog', @@ -24,6 +19,13 @@ export interface IGraphqlSearchProductsVariables { sort?: Record } +export enum AggregationType { + CATEGORY = 'category', + CHECKBOX = 'checkbox', + SLIDER = 'slider', + BOOLEAN = 'boolean', +} + export interface IGraphqlSearchProducts { products: IGraphqlSearchProduct } @@ -32,7 +34,7 @@ export interface IGraphqlSearchProduct { collection: IGraphqlProduct[] paginationInfo: IGraphqlProductPaginationInfo sortInfo: IGraphqlProductSortInfo - aggregations?: IGraphqlAggregation[] + aggregations?: IGraphqlProductAggregation[] } export interface IGraphqlProduct { @@ -59,6 +61,21 @@ 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 @@ -113,16 +130,21 @@ export interface IProductFieldFilterInput { [key: string]: ITypeFilterInput } -export interface IGraphqlViewMoreProductFacetOptionsVariables - extends Omit { +export interface IGraphqlViewMoreFacetOption { + id: string + value: string + label: string + count: number +} + +export interface IGraphqlViewMoreFacetOptionsVariables { + aggregation: string + localizedCatalog: string currentCategoryId?: string filter?: IProductFieldFilterInput[] | IProductFieldFilterInput + search?: string } -export interface IGraphqlViewMoreProductFacetOptions { +export interface IGraphqlViewMoreFacetOptions { viewMoreProductFacetOptions: IGraphqlViewMoreFacetOption[] } - -export interface IGraphqlProductSortingOptions { - productSortingOptions: ISortingOption[] -} diff --git a/packages/shared/src/types/sortingOption.ts b/packages/shared/src/types/sortingOption.ts deleted file mode 100644 index d009b66e..00000000 --- a/packages/shared/src/types/sortingOption.ts +++ /dev/null @@ -1,15 +0,0 @@ -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[] -}