-
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.
Support order conditions in rule summary (#4647)
* Refactor rule model * Add changeset * Add discount type component * Add type to initial form values * Bump macaw * Refactor Add button * Update test * Refactor DiscountRule isLoaded * Add type support * Remve useeffect * Add changeset * Extract messages * Init context * Context intro * Remove empty import * Fix tests, fix useDiscountRulesContext imports * Add changeset * Support mutliple condition types * Update label map after rule add * Add sorting * Extract messages * Add changeset * Refactor RuleList * Refactor rule summary to support order conditions * Update test * Add changeset * Improve useVariantOptions * Remove unused hooks
- Loading branch information
Showing
23 changed files
with
329 additions
and
122 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": minor | ||
--- | ||
|
||
Support order conditions in rule summary |
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
39 changes: 39 additions & 0 deletions
39
...nts/components/DiscountRules/componenets/RulesList/components/RuleActions/RuleActions.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useDiscountRulesContext } from "@dashboard/discounts/components/DiscountRules/context"; | ||
import { Box, Button, EditIcon, TrashBinIcon } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
|
||
interface RuleActionsProps { | ||
onEdit: () => void; | ||
onDelete: () => void; | ||
} | ||
|
||
export const RuleActions = ({ onEdit, onDelete }: RuleActionsProps) => { | ||
const { disabled } = useDiscountRulesContext(); | ||
|
||
return ( | ||
<Box display="flex"> | ||
<Button | ||
size="small" | ||
variant="tertiary" | ||
onClick={onEdit} | ||
cursor={disabled ? "not-allowed" : "pointer"} | ||
disabled={disabled} | ||
data-test-id="rule-edit-button" | ||
> | ||
<EditIcon /> | ||
</Button> | ||
<Button | ||
size="small" | ||
disabled={disabled} | ||
variant="tertiary" | ||
data-test-id="rule-delete-button" | ||
onClick={e => { | ||
e.stopPropagation(); | ||
onDelete(); | ||
}} | ||
> | ||
<TrashBinIcon /> | ||
</Button> | ||
</Box> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/discounts/components/DiscountRules/componenets/RulesList/components/RuleActions/index.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 @@ | ||
export * from "./RuleActions"; |
30 changes: 30 additions & 0 deletions
30
...scounts/components/DiscountRules/componenets/RulesList/components/RuleLabel/RuleLabel.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { messages } from "@dashboard/discounts/components/DiscountRules/messages"; | ||
import React from "react"; | ||
import { useIntl } from "react-intl"; | ||
|
||
interface RuleLabelProps { | ||
ruleName: string | undefined; | ||
} | ||
|
||
export const RuleLabel = ({ ruleName }: RuleLabelProps) => { | ||
const intl = useIntl(); | ||
|
||
const getRuleName = (name: string | undefined) => { | ||
if (name) { | ||
return `: ${name}`; | ||
} | ||
return ""; | ||
}; | ||
|
||
// const ruleTypeLabel = useMemo(() => { | ||
// if (discountType === PromotionTypeEnum.CATALOGUE) { | ||
// return intl.formatMessage(messages.catalogRule); | ||
// } | ||
|
||
// return intl.formatMessage(messages.orderRule); | ||
// }, [discountType]); | ||
|
||
return ( | ||
<>{intl.formatMessage(messages.catalogRule) + getRuleName(ruleName)}</> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
src/discounts/components/DiscountRules/componenets/RulesList/components/RuleLabel/index.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 @@ | ||
export * from "./RuleLabel"; |
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
1 change: 1 addition & 0 deletions
1
...ntRules/componenets/RulesList/components/RuleSummary/components/RuleChannelChips/index.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 @@ | ||
export * from "./RuleChannelChips"; |
35 changes: 0 additions & 35 deletions
35
...ountRules/componenets/RulesList/components/RuleSummary/components/RuleChips/RuleChips.tsx
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
.../DiscountRules/componenets/RulesList/components/RuleSummary/components/RuleChips/index.ts
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
...s/RulesList/components/RuleSummary/components/RuleConditionsChips/RuleConditionsChips.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Rule } from "@dashboard/discounts/models"; | ||
import React from "react"; | ||
|
||
import { mapConditionToOption, splitConditions } from "../../utils"; | ||
import { RuleSummaryChips } from "../RuleSummaryChips"; | ||
import { RuleSummaryTooltip } from "../RuleSummaryTooltip"; | ||
import { useEnrichConditions } from "./useEnrichConditions"; | ||
|
||
interface RuleChipsProps { | ||
rule: Rule; | ||
currencySymbol: string; | ||
} | ||
|
||
export const RuleConditionsChips = ({ | ||
rule, | ||
currencySymbol, | ||
}: RuleChipsProps) => { | ||
const enrichConditions = useEnrichConditions(rule.conditions, currencySymbol); | ||
|
||
const conditions = mapConditionToOption(enrichConditions); | ||
|
||
const { conditionsInSummary, conditionsInTooltip } = | ||
splitConditions(conditions); | ||
|
||
const hasConditionInTooltip = conditionsInTooltip.length > 0; | ||
|
||
return ( | ||
<> | ||
{conditionsInSummary.map(({ label, value }) => ( | ||
<RuleSummaryChips key={value} value={value} label={label} /> | ||
))} | ||
{hasConditionInTooltip ? ( | ||
<RuleSummaryTooltip conditionsValues={conditionsInTooltip} /> | ||
) : null} | ||
</> | ||
); | ||
}; |
42 changes: 42 additions & 0 deletions
42
...omponenets/RulesList/components/RuleSummary/components/RuleConditionsChips/formatLable.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,42 @@ | ||
import { Locale } from "@dashboard/components/Locale"; | ||
import { | ||
formatMoney as formatMoneyUtils, | ||
formatMoneyRange as formatMoneyRangeUtils, | ||
} from "@dashboard/components/Money"; | ||
import { Condition, isTuple } from "@dashboard/discounts/models"; | ||
|
||
export const formatMoneyRange = ( | ||
condition: Condition, | ||
currencySymbol: string, | ||
locale: Locale, | ||
) => { | ||
if (!isTuple(condition.value)) { | ||
return ""; | ||
} | ||
|
||
return formatMoneyRangeUtils( | ||
{ | ||
amount: Number(condition.value[0]), | ||
currency: currencySymbol, | ||
}, | ||
{ | ||
amount: Number(condition.value[1]), | ||
currency: currencySymbol, | ||
}, | ||
locale, | ||
); | ||
}; | ||
|
||
export const formatMoney = ( | ||
condition: Condition, | ||
currencySymbol: string, | ||
locale: Locale, | ||
) => { | ||
return formatMoneyUtils( | ||
{ | ||
amount: Number(condition.value), | ||
currency: currencySymbol, | ||
}, | ||
locale, | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
...ules/componenets/RulesList/components/RuleSummary/components/RuleConditionsChips/index.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 @@ | ||
export * from "./RuleConditionsChips"; |
Oops, something went wrong.