|
1 |
| -## FireCMS Data enhancement plugin |
| 1 | +I'll enhance the README with more detailed documentation, configuration options, and better examples: |
2 | 2 |
|
3 |
| -This plugin allows you to enhance data in your [FireCMS](https://firecms.co) |
4 |
| -project, using ChatGPT. |
| 3 | +# FireCMS Data Export Plugin |
5 | 4 |
|
6 |
| -The ChatGPT plugin allows you to use the OpenAI API to generate content using |
7 |
| -the latest GPT models. This plugin is able to understand the structure of your |
8 |
| -data and generate content that fits your schema. |
| 5 | +This plugin enables exporting Firestore collections to CSV or JSON formats directly from your FireCMS interface. It adds an export button to collection views, providing a simple way to back up data or share it with others. |
9 | 6 |
|
10 |
| -<p align="center"> |
11 |
| - <img src="https://firecms.co/img/data_import.png" width="800px" alt="Data enhancement UI" /> |
12 |
| -</p> |
| 7 | +## Installation |
13 | 8 |
|
14 |
| -In order to be able to use this plugin you need to have a valid subscription. |
| 9 | +```bash |
| 10 | +npm install @firecms/data_export |
| 11 | +# or |
| 12 | +yarn add @firecms/data_export |
| 13 | +``` |
15 | 14 |
|
16 |
| -You can get a subscription in |
17 |
| -the [FireCMS dashboard](https://app.firecms.co/subscriptions). |
| 15 | +## Features |
18 | 16 |
|
19 |
| -You need to specify the Firebase project id you would like to use the plugin |
20 |
| -with, |
21 |
| -in the website. And that's it! |
| 17 | +- Export collection data to CSV or JSON formats |
| 18 | +- Configure export permissions based on collection size or custom logic |
| 19 | +- Integration with FireCMS analytics events |
| 20 | +- Custom UI for unsupported export scenarios |
22 | 21 |
|
23 |
| -No need to add any subscription key or anything like that. |
| 22 | +## Basic Usage |
24 | 23 |
|
25 | 24 | ```tsx
|
26 | 25 | import React from "react";
|
27 | 26 | import { FirebaseCMSApp } from "@firecms/core";
|
28 |
| -import "typeface-rubik"; |
29 |
| -import "@fontsource/jetbrains-mono"; |
30 |
| - |
31 |
| -import { useDataImportPlugin } from "@firecms/data_import_export"; |
| 27 | +import { useExportPlugin } from "@firecms/data_export"; |
32 | 28 |
|
33 |
| -// TODO: Replace with your Firebase config |
34 |
| -const firebaseConfig = { |
35 |
| - apiKey: "", |
36 |
| - authDomain: "", |
37 |
| - projectId: "", |
38 |
| - storageBucket: "", |
39 |
| - messagingSenderId: "", |
40 |
| - appId: "" |
41 |
| -}; |
| 29 | +// Basic setup with default options |
| 30 | +const exportPlugin = useExportPlugin(); |
42 | 31 |
|
43 | 32 | export default function App() {
|
44 |
| - |
45 |
| - const dataImportPlugin = useDataImportPlugin({ |
46 |
| - // Optional callback for defining which collections should be enhanced |
47 |
| - getConfigForPath: ({ path }) => { |
48 |
| - if (path === "books") |
49 |
| - return true; |
50 |
| - return false; |
51 |
| - } |
52 |
| - }); |
53 |
| - |
54 | 33 | return <FirebaseCMSApp
|
55 | 34 | name={"My Online Shop"}
|
56 |
| - plugins={[dataImportPlugin]} |
| 35 | + plugins={[exportPlugin]} |
57 | 36 | authentication={myAuthenticator}
|
58 |
| - collections={[ |
59 |
| - //... |
60 |
| - ]} |
| 37 | + collections={myCollections} |
61 | 38 | firebaseConfig={firebaseConfig}
|
62 | 39 | />;
|
63 | 40 | }
|
64 | 41 | ```
|
65 | 42 |
|
66 |
| -## How does it work? |
67 |
| - |
68 |
| -This plugin uses the OpenAI API to generate content using the latest GPT models. |
69 |
| -This plugin is able to understand the structure of your data and generate |
70 |
| -content that fits your schema. |
71 |
| - |
72 |
| -Some tips in order to get the best results: |
73 |
| - |
74 |
| -- Make sure you select the **right data** type for your fields. |
75 |
| -- The **field names** are used to generate the content and are usually enough to |
76 |
| - generate good results. If you want to get even better results, you can |
77 |
| - **add a description** to your fields. This will help the plugin understand the |
78 |
| - context of your data and generate better results. |
79 |
| -- The **collection name** is important as well. |
80 |
| -- You can establish **relations between fields** and the plugin will pick it up. |
81 |
| - e.g. if you have a field called `author` and another field called `book`, the |
82 |
| - plugin will understand that the author is related to the book and will |
83 |
| - generate content accordingly. You can use this for making **summaries, reviews, |
84 |
| - translations, SEO content**, etc. |
| 43 | +## Advanced Configuration |
| 44 | + |
| 45 | +You can customize the export behavior with these options: |
| 46 | + |
| 47 | +```tsx |
| 48 | +const exportPlugin = useExportPlugin({ |
| 49 | + // Control when exports are allowed |
| 50 | + exportAllowed: ({ collectionEntitiesCount, path, collection }) => { |
| 51 | + // Prevent export of large collections |
| 52 | + if (collectionEntitiesCount > 5000) return false; |
| 53 | + |
| 54 | + // Only allow export for specific collections |
| 55 | + return ["products", "orders"].includes(path); |
| 56 | + }, |
| 57 | + |
| 58 | + // Custom view when export is not allowed |
| 59 | + notAllowedView: <div>Export is not available for this collection</div>, |
| 60 | + |
| 61 | + // Track export events |
| 62 | + onAnalyticsEvent: (event, params) => { |
| 63 | + console.log("Export event:", event, params); |
| 64 | + } |
| 65 | +}); |
| 66 | +``` |
| 67 | + |
| 68 | +## Configuration Options |
| 69 | + |
| 70 | +| Option | Type | Description | |
| 71 | +|--------|------|-------------| |
| 72 | +| `exportAllowed` | `(params: ExportAllowedParams) => boolean` | Function to determine if export is allowed for a collection | |
| 73 | +| `notAllowedView` | `React.ReactNode` | Custom component to display when export is not allowed | |
| 74 | +| `onAnalyticsEvent` | `(event: string, params?: any) => void` | Callback for tracking export events | |
| 75 | + |
| 76 | +Where `ExportAllowedParams` includes: |
| 77 | +- `collectionEntitiesCount`: Number of entities in the collection |
| 78 | +- `path`: Path of the collection |
| 79 | +- `collection`: Collection configuration object |
| 80 | + |
| 81 | + |
| 82 | +## Additional Notes |
| 83 | + |
| 84 | +- Exports are performed client-side and may be limited by browser capabilities for very large collections |
| 85 | +- CSV exports maintain data types where possible but complex objects may be simplified |
| 86 | +- JSON exports preserve the complete data structure |
0 commit comments