-
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.
Improvments for discount catalog (#4565)
* Add empty column to datagrid * Fix loading of rules * Update rule validation * Show rule summary when no conditions * Handle labels on rule update * Improve loading rules * Handle show selected labels * Fix rules tests * Update labels on rule add * Improve adding condtions * Move reward value to left * Remove optional from description * Fix show channel error * Add changeset * Update test * Bump macaw * Sort rule by name * Improve details form submission * Prevent refetch, write data into cache * Improve rule sorting and update mutations * Fix loading issue * Fix ts issues * Refactor to separate hooks * Fix richtext * Refactor useRulesHandlers to get rid of rules state and get data from api * Show only initial loading * Refactor and improve loading conditions options * Fix jumpy condition multiselect * Fix input heigh equal * Change discount type switch height * After CR improvments * Fix ts issues
- Loading branch information
Showing
56 changed files
with
875 additions
and
236 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 | ||
--- | ||
|
||
Improvments for discount rules |
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
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
34 changes: 34 additions & 0 deletions
34
src/discounts/components/DiscountDetailsForm/utils.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,34 @@ | ||
import { Rule } from "@dashboard/discounts/models"; | ||
|
||
import { getCurrentConditionsValuesLabels } from "./utils"; | ||
|
||
describe("getCurrentConditionsValuesLabels", () => { | ||
it("should return empty object if no rules", () => { | ||
expect(getCurrentConditionsValuesLabels([])).toEqual({}); | ||
}); | ||
|
||
it("should return empty object if no conditions", () => { | ||
expect( | ||
getCurrentConditionsValuesLabels([ | ||
{ conditions: [] }, | ||
] as unknown as Rule[]), | ||
).toEqual({}); | ||
}); | ||
|
||
it("should return empty object if no values", () => { | ||
expect( | ||
getCurrentConditionsValuesLabels([ | ||
{ conditions: [{ values: [] }] }, | ||
] as unknown as Rule[]), | ||
).toEqual({}); | ||
}); | ||
|
||
it("should return object with value as key and label as value", () => { | ||
expect( | ||
getCurrentConditionsValuesLabels([ | ||
{ conditions: [{ values: [{ value: "test", label: "test2" }] }] }, | ||
{ conditions: [{ values: [{ value: "test3", label: "test4" }] }] }, | ||
] as unknown as Rule[]), | ||
).toEqual({ test: "test2", test3: "test4" }); | ||
}); | ||
}); |
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,14 @@ | ||
import { Rule } from "@dashboard/discounts/models"; | ||
|
||
export const getCurrentConditionsValuesLabels = (rules: Rule[]) => { | ||
return rules | ||
.flatMap(rule => rule.conditions) | ||
.flatMap(condition => condition.values) | ||
.reduce((acc, value) => { | ||
// Initali value and label might contain id | ||
if (value.value !== value.label) { | ||
acc[value.value] = value.label; | ||
} | ||
return acc; | ||
}, {} as Record<string, string>); | ||
}; |
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
Oops, something went wrong.