我会用更详细的文件、配置选项和更好的例子来增强README:
FireCMS 数据导出插件
此插件可直接从 FireCMS 界面导出 Firestore 收藏到 CSV 或 JSON 格式 。 它又说 导出用于收集视图的按钮,从而提供一个简单的支持数据或与他人共享数据的方法.
安装
npm install @firecms/data_export
# or
yarn add @firecms/data_export
特征
- 导出收集数据为 CSV 或 JSON 格式
- 根据收藏大小或自定义逻辑配置导出权限
- 与 FireCMS 分析活动合并
- 对不支持的导出方案自定义 UI
基本用途
import React from "react";
import { FireCMS } from "@firecms/core";
import { useExportPlugin } from "@firecms/data_export";
export default function App() {
// Basic setup with default options
const exportPlugin = useExportPlugin();
const plugins = [exportPlugin];
const navigationController = useBuildNavigationController({
// ... rest of your config
plugins
});
return <FireCMS
name={"My Online Shop"}
navigationController={navigationController}
authentication={myAuthenticator}
collections={myCollections}
firebaseConfig={firebaseConfig}
/>;
}
高级配置
您可以用这些选项自定义导出行为 :
const exportPlugin = useExportPlugin({
// Control when exports are allowed
exportAllowed: ({ collectionEntitiesCount, path, collection }) => {
// Prevent export of large collections
if (collectionEntitiesCount > 5000) return false;
// Only allow export for specific collections
return ["products", "orders"].includes(path);
},
// Custom view when export is not allowed
notAllowedView: <div>Export is not available for this collection</div>,
// Track export events
onAnalyticsEvent: (event, params) => {
console.log("Export event:", event, params);
}
});
配置选项
| 选项 | 类型 | 说明 |
|---|---|---|
exportAllowed | (params: ExportAllowedParams) => boolean | 用于确定是否允许导出收藏的函数 |
notAllowedView | React.ReactNode | 自定义不允许导出时显示的组件 |
onAnalyticsEvent | (event: string, params?: any) => void | 调用以跟踪导出事件 |
何处 ExportAllowedParams 包括:
collectionEntitiesCount: 收藏中的实体数目path: 收藏的路径collection: 收藏配置对象
补充说明
- 导出由客户端执行,可能受浏览器能力的限制,用于非常大的收藏
- CSV 导出在可能情况下保持数据类型,但复杂的对象可以简化
- JSON出口保留完整的数据结构