-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce new filters for product types (#5411)
* Migrate from tabs to filter presets * Add changeset * Update test id * Fix import in providers and extract getFilterElement with test * Build flags * Add new conditional filters * Add tests * Add changeset * Fix type
- Loading branch information
1 parent
a04abc7
commit 2ab3653
Showing
34 changed files
with
664 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
Product types list page uses now new filters. New filters are under feature flag and are enabled by default. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
name: product_types_filters | ||
displayName: Product types filtering | ||
enabled: true | ||
payload: "default" | ||
visible: true | ||
--- | ||
|
||
 | ||
Experience the new look and enhanced abilities of new fitering mechanism. | ||
Easily combine any criteria you want, and quickly browse their values. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...mponents/ConditionalFilter/API/initialState/productTypes/InitialProductTypesState.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { UrlEntry, UrlToken } from "../../../ValueProvider/UrlToken"; | ||
import { InitialProductTypesStateResponse } from "./InitialProductTypesState"; | ||
|
||
describe("ConditionalFilter / API / Page / InitialProductTypesState", () => { | ||
it("should filter by product type", () => { | ||
// Arrange | ||
const initialPageState = InitialProductTypesStateResponse.empty(); | ||
|
||
initialPageState.typeOfProduct = [ | ||
{ | ||
label: "Type 1", | ||
value: "type-1", | ||
slug: "type-1", | ||
}, | ||
{ | ||
label: "Type 2", | ||
value: "type-2", | ||
slug: "type-2", | ||
}, | ||
]; | ||
|
||
const token = UrlToken.fromUrlEntry(new UrlEntry("s0.typeOfProduct", "type-2")); | ||
const expectedOutput = [ | ||
{ | ||
label: "Type 2", | ||
value: "type-2", | ||
slug: "type-2", | ||
}, | ||
]; | ||
|
||
// Act | ||
const result = initialPageState.filterByUrlToken(token); | ||
|
||
// Assert | ||
expect(result).toEqual(expectedOutput); | ||
}); | ||
|
||
it("should filter by configurable", () => { | ||
// Arrange | ||
const initialPageState = InitialProductTypesStateResponse.empty(); | ||
|
||
initialPageState.configurable = [ | ||
{ | ||
label: "Yes", | ||
value: "CONFIGURABLE", | ||
slug: "yes", | ||
}, | ||
{ | ||
label: "No", | ||
value: "SIMPLE", | ||
slug: "no", | ||
}, | ||
]; | ||
|
||
const token = UrlToken.fromUrlEntry(new UrlEntry("s0.configurable", "no")); | ||
const expectedOutput = [ | ||
{ | ||
label: "No", | ||
value: "SIMPLE", | ||
slug: "no", | ||
}, | ||
]; | ||
|
||
// Act | ||
const result = initialPageState.filterByUrlToken(token); | ||
|
||
// Assert | ||
expect(result).toEqual(expectedOutput); | ||
}); | ||
}); |
39 changes: 39 additions & 0 deletions
39
src/components/ConditionalFilter/API/initialState/productTypes/InitialProductTypesState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { ItemOption } from "@dashboard/components/ConditionalFilter/FilterElement/ConditionValue"; | ||
import { UrlToken } from "@dashboard/components/ConditionalFilter/ValueProvider/UrlToken"; | ||
|
||
export interface InitialProductTypesState { | ||
typeOfProduct: ItemOption[]; | ||
configurable: ItemOption[]; | ||
} | ||
|
||
export class InitialProductTypesStateResponse implements InitialProductTypesState { | ||
constructor( | ||
public typeOfProduct: ItemOption[] = [], | ||
public configurable: ItemOption[] = [], | ||
) {} | ||
|
||
public static empty() { | ||
return new InitialProductTypesStateResponse(); | ||
} | ||
|
||
public filterByUrlToken(token: UrlToken) { | ||
const entry = this.getEntryByName(token.name); | ||
|
||
if (!token.isLoadable()) { | ||
return [token.value] as string[]; | ||
} | ||
|
||
return (entry as ItemOption[]).filter(({ slug }) => slug && token.value.includes(slug)); | ||
} | ||
|
||
private getEntryByName(name: string): ItemOption[] { | ||
switch (name) { | ||
case "typeOfProduct": | ||
return this.typeOfProduct; | ||
case "configurable": | ||
return this.configurable; | ||
default: | ||
return []; | ||
} | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/components/ConditionalFilter/API/initialState/productTypes/useInitialProdutTypesState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { InitialProductTypesStateResponse } from "@dashboard/components/ConditionalFilter/API/initialState/productTypes/InitialProductTypesState"; | ||
import { ProductTypeConfigurable, ProductTypeEnum } from "@dashboard/graphql"; | ||
import { useState } from "react"; | ||
import { useIntl } from "react-intl"; | ||
|
||
import { ProductTypesFetchingParams } from "../../../ValueProvider/TokenArray/fetchingParams"; | ||
import { BooleanValuesHandler, EnumValuesHandler } from "../../Handler"; | ||
|
||
export interface InitialProductTypesAPIState { | ||
data: InitialProductTypesStateResponse; | ||
loading: boolean; | ||
fetchQueries: (params: ProductTypesFetchingParams) => Promise<void>; | ||
} | ||
|
||
export const useInitialProductTypesState = (): InitialProductTypesAPIState => { | ||
const intl = useIntl(); | ||
const [data, setData] = useState<InitialProductTypesStateResponse>( | ||
InitialProductTypesStateResponse.empty(), | ||
); | ||
const [loading, setLoading] = useState(true); | ||
|
||
const fetchQueries = async ({ typeOfProduct }: ProductTypesFetchingParams) => { | ||
const typeOfProductInit = new EnumValuesHandler( | ||
ProductTypeEnum, | ||
"typeOfProduct", | ||
intl, | ||
typeOfProduct, | ||
); | ||
|
||
const configurableInit = new BooleanValuesHandler([ | ||
{ | ||
label: "Yes", | ||
value: ProductTypeConfigurable.CONFIGURABLE, | ||
type: "configurable", | ||
slug: "true", | ||
}, | ||
{ | ||
label: "No", | ||
value: ProductTypeConfigurable.SIMPLE, | ||
type: "configurable", | ||
slug: "false", | ||
}, | ||
]); | ||
|
||
const initialState = { | ||
typeOfProduct: await typeOfProductInit.fetch(), | ||
configurable: await configurableInit.fetch(), | ||
}; | ||
|
||
setData( | ||
new InitialProductTypesStateResponse(initialState.typeOfProduct, initialState.configurable), | ||
); | ||
setLoading(false); | ||
}; | ||
|
||
return { | ||
data, | ||
loading, | ||
fetchQueries, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/components/ConditionalFilter/API/providers/DiscountFiltersAPIProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/components/ConditionalFilter/API/providers/DraftOrderFilterAPIProvider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.