Skip to content

Commit

Permalink
Add missing units (#4402)
Browse files Browse the repository at this point in the history
* Add missing units

* Add missing type annotation

* Create six-deers-exist.md

---------

Co-authored-by: Patryk Andrzejewski <vox3r69@gmail.com>
  • Loading branch information
2 people authored and poulch committed Dec 18, 2023
1 parent 1a7b055 commit ba106e2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/six-deers-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Add missing units for attributes
5 changes: 5 additions & 0 deletions src/attributes/components/AttributeDetails/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,22 @@ export const unitMessages = defineMessages({
});

export const units = {
cubicMillimeter: <>mm&sup3;</>,
cubicCentimeter: <>cm&sup3;</>,
cubicDecimeter: <>dm&sup3;</>,
cubicMeter: <>m&sup3;</>,
liter: "l",
centimeter: "cm",
decimeter: "dm",
meter: "m",
millimeter: "mm",
kilometer: "km",
gram: "g",
kilogram: "kg",
tonne: "t",
squareMillimeter: <>mm&sup2;</>,
squareCentimeter: <>cm&sup2;</>,
squareDecimeter: <>dm&sup2;</>,
squareMeter: <>m&sup2;</>,
squareKilometer: <>km&sup2;</>,
cubicFoot: <>ft&sup3;</>,
Expand Down
12 changes: 11 additions & 1 deletion src/attributes/components/AttributeDetails/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,22 @@ const UNIT_MESSAGES_MAPPING = {
[MeasurementUnitsEnum.SQ_FT]: M.units.squareFt,
[MeasurementUnitsEnum.SQ_YD]: M.units.squareYd,
[MeasurementUnitsEnum.SQ_INCH]: M.units.squareInch,
[MeasurementUnitsEnum.CUBIC_MILLIMETER]: M.units.cubicMillimeter,
[MeasurementUnitsEnum.CUBIC_CENTIMETER]: M.units.cubicCentimeter,
[MeasurementUnitsEnum.CUBIC_DECIMETER]: M.units.cubicDecimeter,
[MeasurementUnitsEnum.CUBIC_METER]: M.units.cubicMeter,
[MeasurementUnitsEnum.LITER]: M.units.liter,
[MeasurementUnitsEnum.CM]: M.units.centimeter,
[MeasurementUnitsEnum.DM]: M.units.decimeter,
[MeasurementUnitsEnum.MM]: M.units.millimeter,
[MeasurementUnitsEnum.M]: M.units.meter,
[MeasurementUnitsEnum.KM]: M.units.kilometer,
[MeasurementUnitsEnum.G]: M.units.gram,
[MeasurementUnitsEnum.KG]: M.units.kilogram,
[MeasurementUnitsEnum.TONNE]: M.units.tonne,
[MeasurementUnitsEnum.SQ_MM]: M.units.squareMillimeter,
[MeasurementUnitsEnum.SQ_CM]: M.units.squareCentimeter,
[MeasurementUnitsEnum.SQ_DM]: M.units.squareDecimeter,
[MeasurementUnitsEnum.SQ_M]: M.units.squareMeter,
[MeasurementUnitsEnum.SQ_KM]: M.units.squareKilometer,
};
Expand All @@ -48,7 +53,7 @@ export const getMeasurementUnitMessage = (
const message = UNIT_MESSAGES_MAPPING[unit];
return typeof message === "string" || React.isValidElement(message)
? message
: formatMessage(message);
: formatMessage(message as MessageDescriptor);
};

export const unitSystemChoices: Array<Choice<UnitSystem, MessageDescriptor>> = [
Expand Down Expand Up @@ -107,13 +112,16 @@ export const unitMapping = {
},
metric: {
volume: [
MeasurementUnitsEnum.CUBIC_MILLIMETER,
MeasurementUnitsEnum.CUBIC_CENTIMETER,
MeasurementUnitsEnum.CUBIC_DECIMETER,
MeasurementUnitsEnum.CUBIC_METER,
MeasurementUnitsEnum.LITER,
],
distance: [
MeasurementUnitsEnum.MM,
MeasurementUnitsEnum.CM,
MeasurementUnitsEnum.DM,
MeasurementUnitsEnum.M,
MeasurementUnitsEnum.KM,
],
Expand All @@ -123,7 +131,9 @@ export const unitMapping = {
MeasurementUnitsEnum.TONNE,
],
area: [
MeasurementUnitsEnum.SQ_MM,
MeasurementUnitsEnum.SQ_CM,
MeasurementUnitsEnum.SQ_DM,
MeasurementUnitsEnum.SQ_M,
MeasurementUnitsEnum.SQ_KM,
],
Expand Down

0 comments on commit ba106e2

Please sign in to comment.