Skip to content

Commit

Permalink
feat: export to csv
Browse files Browse the repository at this point in the history
  • Loading branch information
avp1598 committed Apr 4, 2023
1 parent 2b2d33a commit 7739dad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/modules/Collection/CollectionHeading/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { useQuery } from "react-query";
import { UserType } from "@/app/types";
import useRoleGate from "@/app/services/RoleGate/useRoleGate";
import { Embed } from "../Embed";
import { EyeOutlined, SendOutlined, ShareAltOutlined } from "@ant-design/icons";
import { SendOutlined } from "@ant-design/icons";
import { smartTrim } from "@/app/common/utils/utils";
import FormSettings from "../Form/FormSettings";
import WarnConnectWallet from "./WarnConnectWallet";
Expand Down
35 changes: 27 additions & 8 deletions app/modules/Collection/TableView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { motion, AnimatePresence } from "framer-motion";
import _ from "lodash";
import { matchSorter } from "match-sorter";
import { useRouter } from "next/router";
import React, { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import {
Column,
DataSheetGrid,
Expand Down Expand Up @@ -662,17 +662,38 @@ export default function TableView() {
<PrimaryButton
variant="tertiary"
onClick={() => {
let out = [] as any[];
const d = data?.map((da) => {
const csvData: {
[key: string]: string;
} = {};
Object.entries(da)
.filter(
([key, value]) =>
key !== "slug" && key !== "id" && key !== "anonymous"
)
.filter(([key, value]) => key !== "id")
.forEach(([key, value]: [string, any]) => {
if (key === "slug") {
csvData["Data Slug"] = value;
return;
}
if (key === "__lookup__") {
value = value.map((v: any) => ({
contractAddress: undefined,
tokenType: undefined,
metadata: undefined,
token: v.metadata?.name,
balance: v.balance,
chainId: v.chainId,
}));
csvData["Tokens Lookup"] = JSON.stringify(value);
return;
}
if (key === "anonymous") {
const value =
collection?.profiles?.[collection?.dataOwner[da.slug]];
csvData["Responder Profile"] = JSON.stringify({
username: value?.username,
ethAddress: value?.ethAddress,
});
return;
}
if (!collection.properties[key]) return;
if (collection.properties[key].type === "reward") {
csvData[key] = JSON.stringify({
Expand Down Expand Up @@ -716,8 +737,6 @@ export default function TableView() {
csvData[key] = value;
}
});
// delete csvData["id"] && delete csvData["anonymous"];
csvData["slug"] = da.slug;
return csvData;
});
console.log({ d });
Expand Down

0 comments on commit 7739dad

Please sign in to comment.