Skip to content

Commit

Permalink
Fix pasting float number into datagrid (#4335)
Browse files Browse the repository at this point in the history
  • Loading branch information
poulch authored Oct 19, 2023
1 parent 466914f commit 3f6dcfa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-shirts-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-dashboard": patch
---

Fix pasting float number into datagrid
9 changes: 7 additions & 2 deletions src/components/Datagrid/customCells/NumberCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ export interface NumberCellProps {
readonly kind: "number-cell";
readonly value: number | typeof numberCellEmptyValue;
readonly options?: {
format: "number" | "percent";
format?: "number" | "percent";
hasFloatingPoint?: boolean;
};
}

export type NumberCell = CustomCell<NumberCellProps>;

const onlyDigitsRegExp = /^\d+$/;
const flaotingPointDigits = /^[0-9]+[.,]?[0-9]+$/;

const NumberCellEdit: ReturnType<ProvideEditorCallback<NumberCell>> = ({
value: cell,
Expand Down Expand Up @@ -80,7 +82,10 @@ export const numberCellRenderer = (
}),
}),
onPaste: (value, data) => {
if (!onlyDigitsRegExp.test(value)) {
const testRegExp = data.options?.hasFloatingPoint
? flaotingPointDigits
: onlyDigitsRegExp;
if (!testRegExp.test(value)) {
return undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion src/products/components/ProductVariants/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export function getData({

if (!available) {
return {
...numberCell(numberCellEmptyValue),
...numberCell(numberCellEmptyValue, { hasFloatingPoint: true }),
readonly: false,
allowOverlay: false,
};
Expand Down

0 comments on commit 3f6dcfa

Please sign in to comment.