Skip to content

Commit 4e1813a

Browse files
v3.5.0 (#947)
* feat(storage): upload file metadata to existing firestore document (#936) - @JonnyBoy333 * chore(deps): update babel dev dependencies to 7.10.1 * feat(ci): add creating of release to publish workflow Co-authored-by: Jon <[email protected]>
1 parent 75ea1f5 commit 4e1813a

File tree

10 files changed

+3047
-2221
lines changed

10 files changed

+3047
-2221
lines changed

.github/workflows/publish.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,15 @@ jobs:
3434

3535
- name: Install Dependencies
3636
if: steps.check.outputs.changed == 'true'
37-
env:
38-
CI: true
3937
run: npm ci
4038

4139
- name: Check For Lint
4240
if: steps.check.outputs.changed == 'true'
43-
env:
44-
CI: true
4541
run: npm run lint
4642

4743
- name: Run Unit Tests + Coverage
4844
if: steps.check.outputs.changed == 'true'
4945
env:
50-
CI: true
5146
CODE_CLIMATE: ${{ secrets.CODE_CLIMATE }}
5247
run: npm run test:cov
5348

@@ -57,22 +52,27 @@ jobs:
5752
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
5853
GITHUB_REF: ${{ github.ref }}
5954
run: |
60-
export GIT_BRANCH=${GITHUB_REF##*/}
61-
export PUBLISH_FLAG=$(if [ "$GITHUB_REF" != 'refs/heads/master' ]; then eval echo '--tag $GIT_BRANCH'; else echo ''; fi;)
62-
npm publish $PUBLISH_FLAG
63-
64-
- name: Archive Build Artifact
65-
if: steps.check.outputs.changed == 'true'
66-
uses: actions/upload-artifact@master
67-
with:
68-
name: build
69-
path: lib
55+
gitBranch=${GITHUB_REF##*/}
56+
publishFlag=$(if [ "$GITHUB_REF" != 'refs/heads/master' ]; then eval echo '--tag $gitBranch'; else echo ''; fi;)
57+
echo "::set-env name=PACKAGE_VERSION::$(cat package.json | jq -r '.version')"
58+
npm publish $publishFlag
7059
7160
- name: Upload Coverage
7261
if: steps.check.outputs.changed == 'true'
7362
env:
74-
CI: true
7563
CODE_COV: ${{ secrets.CODE_COV }}
7664
# Upload to Code Cover. Curl used in place of codecov/codecov-action
7765
# due to long build time. See https://github.com/codecov/codecov-action/issues/21
7866
run: curl -s https://codecov.io/bash | bash -s -- -t $CODE_COV
67+
68+
- name: Create Release
69+
if: github.ref == 'refs/heads/master' && steps.check.outputs.changed == 'true'
70+
id: create_release
71+
uses: actions/create-release@latest
72+
env:
73+
GITHUB_TOKEN: ${{ github.token }}
74+
with:
75+
tag_name: v${{ env.PACKAGE_VERSION }}
76+
release_name: v${{ env.PACKAGE_VERSION }}
77+
draft: false
78+
prerelease: false

.github/workflows/verify.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,20 @@ jobs:
2525
key: ${{ runner.os }}-npm-${{ hashFiles('package-lock.json') }}
2626

2727
- name: Install Dependencies
28-
env:
29-
CI: true
3028
run: npm ci
3129

3230
- name: Check For Lint
33-
env:
34-
CI: true
3531
run: npm run lint
3632

3733
- name: Run Unit Tests + Coverage
38-
if: success()
3934
run: npm run test:cov
4035

4136
- name: Run Build
4237
run: npm run build
4338

4439
- name: Upload Coverage
45-
if: matrix.node-version == '10.x' && success()
40+
if: matrix.node-version == '10.x'
4641
env:
47-
CI: true
4842
CODE_COV: ${{ secrets.CODE_COV }}
4943
# Upload to codecov.io. Curl used in place of codecov/codecov-action
5044
# due to long build time. See https://github.com/codecov/codecov-action/issues/21

README.md

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ The [Material Example](https://github.com/prescottprue/react-redux-firebase/tree
2020

2121
## Features
2222

23-
* Out of the box support for authentication (with auto loading user profile from database/firestore)
24-
* Full Firebase Platform Support Including Real Time Database, Firestore, and Storage
25-
* Automatic binding/unbinding of listeners through React Hooks (`useFirebaseConnect`, `useFirestoreConnect`) or Higher Order Components (`firebaseConnect` and `firestoreConnect`)
26-
* [Population capability](http://react-redux-firebase.com/docs/populate) (similar to mongoose's `populate` or SQL's `JOIN`)
27-
* Support small data ( using `value` ) or large datasets ( using `child_added`, `child_removed`, `child_changed` )
28-
* Multiple queries types supported including `orderByChild`, `orderByKey`, `orderByValue`, `orderByPriority`, `limitToLast`, `limitToFirst`, `startAt`, `endAt`, `equalTo`
29-
* Tons of examples of integrations including [`redux-thunk`](https://github.com/gaearon/redux-thunk) and [`redux-observable`](https://redux-observable.js.org/)
30-
* Server Side Rendering Support
31-
* [`react-native` support](http://react-redux-firebase.com/docs/integrations/react-native.html) using [native modules](http://react-redux-firebase.com/docs/integrations/react-native.html#native-modules) or [web sdk](http://react-redux-firebase.com/docs/integrations/react-native.html#jsweb)
23+
- Out of the box support for authentication (with auto loading user profile from database/firestore)
24+
- Full Firebase Platform Support Including Real Time Database, Firestore, and Storage
25+
- Automatic binding/unbinding of listeners through React Hooks (`useFirebaseConnect`, `useFirestoreConnect`) or Higher Order Components (`firebaseConnect` and `firestoreConnect`)
26+
- [Population capability](http://react-redux-firebase.com/docs/populate) (similar to mongoose's `populate` or SQL's `JOIN`)
27+
- Support small data ( using `value` ) or large datasets ( using `child_added`, `child_removed`, `child_changed` )
28+
- Multiple queries types supported including `orderByChild`, `orderByKey`, `orderByValue`, `orderByPriority`, `limitToLast`, `limitToFirst`, `startAt`, `endAt`, `equalTo`
29+
- Tons of examples of integrations including [`redux-thunk`](https://github.com/gaearon/redux-thunk) and [`redux-observable`](https://redux-observable.js.org/)
30+
- Server Side Rendering Support
31+
- [`react-native` support](http://react-redux-firebase.com/docs/integrations/react-native.html) using [native modules](http://react-redux-firebase.com/docs/integrations/react-native.html#native-modules) or [web sdk](http://react-redux-firebase.com/docs/integrations/react-native.html#jsweb)
3232

3333
## Installation
3434

@@ -147,7 +147,7 @@ export default function Todos() {
147147
'todos' // { path: '/todos' } // object notation
148148
])
149149

150-
const todos = useSelector(state => state.firebase.ordered.todos)
150+
const todos = useSelector((state) => state.firebase.ordered.todos)
151151

152152
if (!isLoaded(todos)) {
153153
return <div>Loading...</div>
@@ -219,7 +219,7 @@ import { useSelector } from 'react-redux'
219219
import { useFirebase, isLoaded, isEmpty } from 'react-redux-firebase'
220220

221221
function TodosList() {
222-
const todos = useSelector(state => state.firebase.ordered.todos)
222+
const todos = useSelector((state) => state.firebase.ordered.todos)
223223

224224
if (!isLoaded(todos)) {
225225
return <div>Loading...</div>
@@ -268,21 +268,15 @@ Currently `react-redux-firebase` still handles auth when using [`redux-firestore
268268

269269
See full documentation at [react-redux-firebase.com](http://react-redux-firebase.com)
270270

271-
* [Getting Started](http://react-redux-firebase.com/docs/getting_started)
272-
* [Auth](http://react-redux-firebase.com/docs/auth)
273-
* [Queries](http://react-redux-firebase.com/docs/queries)
274-
* [Firestore](http://react-redux-firebase.com/docs/firestore)
275-
* [Populate](http://react-redux-firebase.com/docs/populate)
276-
* [API Reference](http://react-redux-firebase.com/docs/api)
271+
- [Getting Started](http://react-redux-firebase.com/docs/getting_started)
272+
- [Auth](http://react-redux-firebase.com/docs/auth)
273+
- [Queries](http://react-redux-firebase.com/docs/queries)
274+
- [Firestore](http://react-redux-firebase.com/docs/firestore)
275+
- [Populate](http://react-redux-firebase.com/docs/populate)
276+
- [API Reference](http://react-redux-firebase.com/docs/api)
277277

278278
## [Examples](examples)
279279

280-
### Real World Applications
281-
282-
* [fireadmin.io](http://fireadmin.io) - Firebase Instance Management Tool (source [available here](https://github.com/prescottprue/fireadmin))
283-
284-
If you would like a project added to this section please reach out [over gitter][gitter-url]
285-
286280
### [Examples Folder](examples)
287281

288282
Examples folder is broken into two categories [snippets](examples/snippets) and [complete](examples/complete). `/complete` contains full applications that can be run as is, where as `/snippets` contains small amounts of code to highlight specific functionality (dev tools and deps not included).
@@ -311,16 +305,16 @@ Join us on the [redux-firebase gitter](https://gitter.im/redux-firebase/Lobby).
311305

312306
View docs for recipes on integrations with:
313307

314-
* [redux-firestore](http://react-redux-firebase.com/docs/firestore.html)
315-
* [redux-thunk](http://react-redux-firebase.com/docs/integrations/thunks.html)
316-
* [reselect](http://react-redux-firebase.com/docs/integrations/integrations/reselect.html)
317-
* [redux-observable](http://react-redux-firebase.com/docs/integrations/redux-observable.html)
318-
* [redux-saga](http://react-redux-firebase.com/docs/integrations/redux-saga.html)
319-
* [redux-form](http://react-redux-firebase.com/docs/integrations/redux-form.html)
320-
* [redux-auth-wrapper](http://react-redux-firebase.com/docs/recipes/routing.html#advanced)
321-
* [redux-persist](http://react-redux-firebase.com/docs/integrations/redux-persist.html)
322-
* [react-native](http://react-redux-firebase.com/docs/integrations/react-native.html)
323-
* [react-native-firebase](http://react-redux-firebase.com/docs/integrations/react-native.html#native-modules)
308+
- [redux-firestore](http://react-redux-firebase.com/docs/firestore.html)
309+
- [redux-thunk](http://react-redux-firebase.com/docs/integrations/thunks.html)
310+
- [reselect](http://react-redux-firebase.com/docs/integrations/integrations/reselect.html)
311+
- [redux-observable](http://react-redux-firebase.com/docs/integrations/redux-observable.html)
312+
- [redux-saga](http://react-redux-firebase.com/docs/integrations/redux-saga.html)
313+
- [redux-form](http://react-redux-firebase.com/docs/integrations/redux-form.html)
314+
- [redux-auth-wrapper](http://react-redux-firebase.com/docs/recipes/routing.html#advanced)
315+
- [redux-persist](http://react-redux-firebase.com/docs/integrations/redux-persist.html)
316+
- [react-native](http://react-redux-firebase.com/docs/integrations/react-native.html)
317+
- [react-native-firebase](http://react-redux-firebase.com/docs/integrations/react-native.html#native-modules)
324318

325319
## Starting A Project
326320

@@ -353,7 +347,9 @@ It can be imported like so:
353347
<script src="../node_modules/redux-firestore/dist/redux-firestore.min.js"></script>
354348
<!-- or through cdn: <script src="https://unpkg.com/react-redux-firebase@latest/dist/react-redux-firebase.min.js"></script> -->
355349
<!-- or through cdn: <script src="https://unpkg.com/redux-firestore@latest/dist/redux-firestore.min.js"></script> -->
356-
<script>console.log('react redux firebase:', window.ReactReduxFirebase)</script>
350+
<script>
351+
console.log('react redux firebase:', window.ReactReduxFirebase)
352+
</script>
357353
```
358354

359355
Note: In an effort to keep things simple, the wording from this explanation was modeled after [the installation section of the Redux Docs](https://redux.js.org/#installation).
@@ -364,12 +360,6 @@ This project exists thanks to all the people who contribute.
364360

365361
<a href="https://github.com/prescottprue/react-redux-firebase/graphs/contributors"><img src="https://opencollective.com/react-redux-firebase/contributors.svg?width=890" /></a>
366362

367-
## Backers
368-
369-
Thank you to all our backers! 🙏
370-
371-
* [Side Inc.](https://github.com/reside-eng)
372-
373363
[npm-image]: https://img.shields.io/npm/v/react-redux-firebase.svg?style=flat-square
374364
[npm-url]: https://npmjs.org/package/react-redux-firebase
375365
[npm-downloads-image]: https://img.shields.io/npm/dm/react-redux-firebase.svg?style=flat-square

docs/recipes/upload.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ This example component uses `react-dropzone` to allow for drag/drop uploading di
77
**NOTE:** The third argument provided to the `uploadFiles` and `deleteFiles` calls below is the database path where File Metadata will be written/deleted from. This is out of convenience only, simply remove the third argument if you don't want metadata written/deleted to/from database.
88

99
```js
10-
import React from 'react';
11-
import PropTypes from 'prop-types';
12-
import { map } from 'lodash';
13-
import { useSelector } from 'react-redux';
14-
import { useFirebase, useFirebaseConnect } from 'react-redux-firebase';
15-
import Dropzone from 'react-dropzone';
10+
import React from 'react'
11+
import PropTypes from 'prop-types'
12+
import { map } from 'lodash'
13+
import { useSelector } from 'react-redux'
14+
import { useFirebase, useFirebaseConnect } from 'react-redux-firebase'
15+
import Dropzone from 'react-dropzone'
1616

1717
// Path within Database for metadata (also used for file Storage path)
1818
const filesPath = 'uploadedFiles'
@@ -22,10 +22,10 @@ export default function Uploader({ uploadedFiles, onFileDelete, onFilesDrop }) {
2222
const uploadedFiles = useSelector(({ firebase: { data } }) => data[filesPath])
2323

2424
function onFilesDrop(files) {
25-
return firebase.uploadFiles(filesPath, files, filesPath);
25+
return firebase.uploadFiles(filesPath, files, filesPath)
2626
}
2727
function onFileDelete(file, key) {
28-
return firebase.deleteFile(file.fullPath, `${filesPath}/${key}`);
28+
return firebase.deleteFile(file.fullPath, `${filesPath}/${key}`)
2929
}
3030

3131
return (
@@ -39,13 +39,15 @@ export default function Uploader({ uploadedFiles, onFileDelete, onFilesDrop }) {
3939
{map(uploadedFiles, (file, key) => (
4040
<div key={file.name + key}>
4141
<span>{file.name}</span>
42-
<button onClick={() => onFileDelete(file, key)}>Delete File</button>
42+
<button onClick={() => onFileDelete(file, key)}>
43+
Delete File
44+
</button>
4345
</div>
4446
))}
4547
</div>
4648
)}
4749
</div>
48-
);
50+
)
4951
}
5052
```
5153

@@ -74,7 +76,9 @@ When uploading files as in the above example, you can modify how the file's meta
7476
const config = {
7577
fileMetadataFactory: (uploadRes, firebase, metadata, downloadURL) => {
7678
// upload response from Firebase's storage upload
77-
const { metadata: { name, fullPath } } = uploadRes
79+
const {
80+
metadata: { name, fullPath }
81+
} = uploadRes
7882
// default factory includes name, fullPath, downloadURL
7983
return {
8084
name,
@@ -84,3 +88,23 @@ const config = {
8488
}
8589
}
8690
```
91+
92+
### Update Firestore Document
93+
94+
If using Firestore for you database and you would like to update a specific document after a file has uploaded you can specify the `options.documentId` property. In this example the document with id `12345` in the `contacts` collection will have the `fileUrl` property updated with the file's download url. More details can be found in the [upload file](https://firebase.google.com/docs/storage/web/upload-files#add_file_metadata) section of the Firebase docs.
95+
96+
```js
97+
const storagePath = 'contacts/sleepygary'
98+
const dbPath = 'contacts'
99+
100+
firebase
101+
.uploadFile(storagePath, file, dbPath, {
102+
metadataFactory: (uploadRes, firebase, metadata, downloadURL) => {
103+
return { fileUrl: downloadURL }
104+
},
105+
documentId: '12345'
106+
})
107+
.then(() => {
108+
console.log('File uploaded successfully')
109+
})
110+
```

0 commit comments

Comments
 (0)