Skip to content

Commit

Permalink
refactor(web): improve-csv-layout
Browse files Browse the repository at this point in the history
  • Loading branch information
Harman-singh-waraich committed Aug 27, 2024
1 parent baa00ff commit 7a9d6f3
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions web/src/pages/AllLists/RegistryDetails/ItemsDownloadLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,28 @@ const ItemsDownloadLabel: React.FC<{ registryAddress?: string }> = ({ registryAd
useEffect(() => {
if (!items || !ref.current) return;
setIsPreparing(true);
const flattenedItems = items.flatMap((item) => {
let isFirstRow = true;
const flattenedItems = items.map((item) => {
const row = {
id: item.id,
status: item.status,
disputed: item.disputed,
};

return item.props.map((prop) => {
// Create the row with the item details for the first row, otherwise leave them empty
const row = {
id: isFirstRow ? item.id : "",
status: isFirstRow ? item.status : "",
disputed: isFirstRow ? item.disputed : "",
propLabel: prop.label,
propDescription: prop.description,
propValue: prop.value,
propIsIdentifier: prop.isIdentifier,
propType: prop.type,
};

isFirstRow = false;

return row;
item.props.forEach((prop) => {
row[`${prop.label} (${prop.description})`] = prop.value;
});

return row;
});

const csvData = json2csv(flattenedItems);
const blob = new Blob([csvData], { type: "text/csv;charset=utf-8;" });
const link = ref.current;

if (link.download !== undefined) {
const url = URL.createObjectURL(blob);
link.setAttribute("href", url);
link.setAttribute("download", `${registryAddress}.csv`);
link.setAttribute("download", `Kleros-Curate-${registryAddress}.csv`);
link.click();
}

Expand Down

0 comments on commit 7a9d6f3

Please sign in to comment.