Fix throw error when no description data in product list datagrid (#3946)
This commit is contained in:
parent
5e6794fa99
commit
9a3c9de817
3 changed files with 47 additions and 13 deletions
5
.changeset/heavy-dingos-sell.md
Normal file
5
.changeset/heavy-dingos-sell.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"saleor-dashboard": patch
|
||||
---
|
||||
|
||||
Fix throw error when there is not description data in product list datagrid
|
25
src/products/components/ProductListDatagrid/datagrid.test.ts
Normal file
25
src/products/components/ProductListDatagrid/datagrid.test.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { getDescriptionValue } from "./datagrid";
|
||||
|
||||
describe("getDescriptionValue", () => {
|
||||
it("should return description value", () => {
|
||||
expect(
|
||||
getDescriptionValue(
|
||||
'{"time": 1634014163888, "blocks": [{"data": {"text": "description"}, "type": "paragraph"}], "version": "2.20.0"}',
|
||||
),
|
||||
).toBe("description");
|
||||
});
|
||||
|
||||
it("should return empty string when no description data", () => {
|
||||
expect(
|
||||
getDescriptionValue('{"blocks": [{"data": {}, "type": "paragraph"}]}'),
|
||||
).toBe("");
|
||||
});
|
||||
|
||||
it("should return empty string when description contains  ", () => {
|
||||
expect(
|
||||
getDescriptionValue(
|
||||
'{"time": 1637142885936, "blocks": [{"data": {"text": " "}, "type": "paragraph"}], "version": "2.20.0"}',
|
||||
),
|
||||
).toBe("");
|
||||
});
|
||||
});
|
|
@ -277,19 +277,7 @@ function getDescriptionCellContent(
|
|||
return readonlyTextCell("");
|
||||
}
|
||||
|
||||
const parsed = JSON.parse(value);
|
||||
|
||||
if (parsed) {
|
||||
const descriptionFirstParagraph = parsed.blocks.find(
|
||||
block => block.type === "paragraph",
|
||||
);
|
||||
|
||||
if (descriptionFirstParagraph) {
|
||||
return readonlyTextCell(descriptionFirstParagraph.data.text);
|
||||
}
|
||||
}
|
||||
|
||||
return readonlyTextCell(value || "");
|
||||
return readonlyTextCell(getDescriptionValue(value));
|
||||
}
|
||||
|
||||
function getNameCellContent(
|
||||
|
@ -357,6 +345,22 @@ function getAttributeCellContent(
|
|||
return readonlyTextCell("");
|
||||
}
|
||||
|
||||
export function getDescriptionValue(value: string) {
|
||||
const parsed = JSON.parse(value);
|
||||
|
||||
if (parsed) {
|
||||
const descriptionFirstParagraph = parsed?.blocks.find(
|
||||
block => block.type === "paragraph",
|
||||
);
|
||||
|
||||
if (descriptionFirstParagraph) {
|
||||
return (descriptionFirstParagraph.data?.text ?? "").replace(" ", "");
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
export function getColumnMetadata(column: string) {
|
||||
if (column.includes(":")) {
|
||||
const [columnName, columnId] = column.split(":");
|
||||
|
|
Loading…
Reference in a new issue