Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] - Add export buttons to lists #193

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@ant-design/icons": "^5.2.6",
"@loadable/component": "^5.16.2",
"@refinedev/antd": "^5.37.0",
"@refinedev/core": "^4.46.0",
"@refinedev/core": "^4.47.0",
"@refinedev/kbar": "^1.3.4",
"@refinedev/react-router-v6": "^4.5.4",
"@refinedev/simple-rest": "^5.0.0",
Expand Down Expand Up @@ -65,4 +65,4 @@
"last 1 safari version"
]
}
}
}
3 changes: 2 additions & 1 deletion client/public/locales/hu/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@
"unArchive": "Arhiválás visszavonása",
"clone": "Másolás",
"clear": "Törlés",
"saveAndAdd": "Mentés és hozzáadás"
"saveAndAdd": "Mentés és hozzáadás",
"export": "Exportálás"
},
"filament": {
"fields_help": {
Expand Down
3 changes: 2 additions & 1 deletion client/public/locales/it/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@
"unArchive": "Ripristina",
"clone": "Clona",
"clear": "Pulisci",
"saveAndAdd": "Salva e aggiungi"
"saveAndAdd": "Salva e aggiungi",
"export": "Esporta"
},
"filament": {
"fields_help": {
Expand Down
3 changes: 2 additions & 1 deletion client/public/locales/ru/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"notAccessTitle": "У вас нет разрешения на доступ",
"hideColumns": "Скрыть столбцы",
"clearFilters": "Очистить фильтр",
"saveAndAdd": "Сохранить и добавить"
"saveAndAdd": "Сохранить и добавить",
"export": "Экспорт"
},
"warnWhenUnsavedChanges": "Вы уверены, что хотите выйти? У вас есть несохраненные изменения.",
"notifications": {
Expand Down
3 changes: 2 additions & 1 deletion client/public/locales/uk/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"notAccessTitle": "У Вас бракує прав для доступу",
"clone": "Клонувати",
"unArchive": "Розархівувати",
"saveAndAdd": "Зберегти та додати"
"saveAndAdd": "Зберегти та додати",
"export": "Експорт"
},
"spool": {
"fields": {
Expand Down
3 changes: 2 additions & 1 deletion client/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"notAccessTitle": "您没有访问权限",
"hideColumns": "隐藏列",
"clearFilters": "清除筛选器",
"saveAndAdd": "保存并添加"
"saveAndAdd": "保存并添加",
"export": "导出到"
},
"warnWhenUnsavedChanges": "您确定要离开吗?您有未保存的更改。",
"notifications": {
Expand Down
15 changes: 13 additions & 2 deletions client/src/pages/filaments/list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { IResourceComponentsProps, useTranslate, useInvalidate, useNavigation } from "@refinedev/core";
import { useTable, List } from "@refinedev/antd";
import { IResourceComponentsProps, useTranslate, useInvalidate, useNavigation, useExport } from "@refinedev/core";
import { useTable, List, ExportButton } from "@refinedev/antd";
import { Table, Button, Dropdown } from "antd";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
Expand Down Expand Up @@ -28,6 +28,7 @@ import { removeUndefined } from "../../utils/filtering";
import { EntityType, useGetFields } from "../../utils/queryFields";
import { useNavigate } from "react-router-dom";
import { useCurrency } from "../../utils/settings";
import { flatten } from "../../utils/objects";

dayjs.extend(utc);

Expand Down Expand Up @@ -84,6 +85,13 @@ export const FilamentList: React.FC<IResourceComponentsProps> = () => {
// Load initial state
const initialState = useInitialTableState(namespace);

const { triggerExport, isLoading } = useExport<IFilament>({
mapData: item => flatten(item),
unparseConfig: {
columns: allColumnsWithExtraFields
}
});

// Fetch data from the API
// To provide the live updates, we use a custom solution (useLiveify) instead of the built-in refine "liveMode" feature.
// This is because the built-in feature does not call the liveProvider subscriber with a list of IDs, but instead
Expand Down Expand Up @@ -213,6 +221,9 @@ export const FilamentList: React.FC<IResourceComponentsProps> = () => {
</Button>
</Dropdown>
{defaultButtons}
<ExportButton type="dashed" onClick={triggerExport} loading={isLoading} >
{t("buttons.export")}
</ExportButton>
</>
)}
>
Expand Down
17 changes: 15 additions & 2 deletions client/src/pages/spools/list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { IResourceComponentsProps, useInvalidate, useNavigation, useTranslate } from "@refinedev/core";
import { useTable, List } from "@refinedev/antd";
import { IResourceComponentsProps, useInvalidate, useNavigation, useTranslate, useExport } from "@refinedev/core";
import { useTable, List, ExportButton } from "@refinedev/antd";
import { Table, Button, Dropdown, Modal } from "antd";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
Expand Down Expand Up @@ -38,6 +38,7 @@ import { removeUndefined } from "../../utils/filtering";
import { EntityType, useGetFields } from "../../utils/queryFields";
import { useNavigate } from "react-router-dom";
import { useCurrency } from "../../utils/settings";
import { flatten } from "../../utils/objects";

dayjs.extend(utc);

Expand Down Expand Up @@ -111,6 +112,15 @@ export const SpoolList: React.FC<IResourceComponentsProps> = () => {
// State for the switch to show archived spools
const [showArchived, setShowArchived] = useSavedState("spoolList-showArchived", false);

const { triggerExport, isLoading } = useExport<ISpool>(
{
mapData: item => flatten(item),
unparseConfig: {
columns: allColumnsWithExtraFields
}
}
);

// Fetch data from the API
// To provide the live updates, we use a custom solution (useLiveify) instead of the built-in refine "liveMode" feature.
// This is because the built-in feature does not call the liveProvider subscriber with a list of IDs, but instead
Expand Down Expand Up @@ -308,6 +318,9 @@ export const SpoolList: React.FC<IResourceComponentsProps> = () => {
</Button>
</Dropdown>
{defaultButtons}
<ExportButton type="dashed" onClick={triggerExport} loading={isLoading} >
{t("buttons.export")}
</ExportButton>
</>
)}
>
Expand Down
15 changes: 13 additions & 2 deletions client/src/pages/vendors/list.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { IResourceComponentsProps, useTranslate, useInvalidate, useNavigation } from "@refinedev/core";
import { useTable, List } from "@refinedev/antd";
import { IResourceComponentsProps, useTranslate, useInvalidate, useNavigation, useExport } from "@refinedev/core";
import { useTable, List, ExportButton } from "@refinedev/antd";
import { Table, Button, Dropdown } from "antd";
import dayjs from "dayjs";
import utc from "dayjs/plugin/utc";
Expand All @@ -12,6 +12,7 @@ import { useLiveify } from "../../components/liveify";
import { removeUndefined } from "../../utils/filtering";
import { EntityType, useGetFields } from "../../utils/queryFields";
import { useNavigate } from "react-router-dom";
import { flatten } from "../../utils/objects";

dayjs.extend(utc);

Expand All @@ -30,6 +31,13 @@ export const VendorList: React.FC<IResourceComponentsProps> = () => {
// Load initial state
const initialState = useInitialTableState(namespace);

const { triggerExport, isLoading } = useExport<IVendor>({
mapData: item => flatten(item),
unparseConfig: {
columns: allColumnsWithExtraFields
}
});

// Fetch data from the API
const { tableProps, sorters, setSorters, filters, setFilters, current, pageSize, setCurrent } = useTable<IVendor>({
syncWithLocation: false,
Expand Down Expand Up @@ -145,6 +153,9 @@ export const VendorList: React.FC<IResourceComponentsProps> = () => {
</Button>
</Dropdown>
{defaultButtons}
<ExportButton type="dashed" onClick={triggerExport} loading={isLoading} >
{t("buttons.export")}
</ExportButton>
</>
)}
>
Expand Down
13 changes: 13 additions & 0 deletions client/src/utils/objects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export const flatten = (data: object, prefix: string = '', delimiter: string = '.') => {
const result: { [key: string]: string | number | null } = {};

Object.entries(data).forEach(([key, value]) => {
if (typeof value === 'object') {
Object.assign(result, flatten(value, `${prefix}${key}${delimiter}`, delimiter));
} else {
result[`${prefix}${key}`] = value;
}
});

return result;
};