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

Fix #974 Extra infromation on Profile #1032

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
df8cf12
Merge pull request #477 from OneArmyWorld/v0.3.0
chrismclarke May 9, 2019
603198b
Merge pull request #478 from OneArmyWorld/v0.3.0
chrismclarke May 9, 2019
b6da044
Merge pull request #479 from OneArmyWorld/master
BenGamma May 9, 2019
7817316
Merge pull request #480 from OneArmyWorld/master
BenGamma May 9, 2019
ea2a3cb
Merge pull request #482 from OneArmyWorld/master
BenGamma May 9, 2019
06ad863
Merge pull request #485 from OneArmyWorld/master
chrismclarke May 9, 2019
8095819
Merge pull request #486 from OneArmyWorld/master
chrismclarke May 9, 2019
7bd8f17
Merge pull request #489 from OneArmyWorld/master
chrismclarke May 10, 2019
a15fd88
Merge pull request #502 from OneArmyWorld/master
chrismclarke May 29, 2019
dac531a
Merge pull request #510 from OneArmyWorld/master
chrismclarke Jun 20, 2019
6106242
Merge pull request #538 from OneArmyWorld/master
chrismclarke Aug 13, 2019
a556c3a
Merge pull request #543 from OneArmyWorld/master
chrismclarke Aug 20, 2019
6ec258b
Merge pull request #552 from ONEARMY/master
chrismclarke Aug 30, 2019
daa72cc
Merge pull request #556 from ONEARMY/master
BenGamma Sep 2, 2019
c50e97e
Merge pull request #579 from ONEARMY/master
chrismclarke Sep 15, 2019
ae96300
Merge pull request #580 from ONEARMY/master
BenGamma Sep 15, 2019
0e13245
Merge pull request #581 from ONEARMY/master
chrismclarke Sep 15, 2019
3dc13a2
Merge pull request #583 from ONEARMY/master
chrismclarke Sep 16, 2019
fd94731
Merge pull request #623 from ONEARMY/master
chrismclarke Oct 8, 2019
7c08ebb
Merge pull request #625 from ONEARMY/master
BenGamma Oct 8, 2019
bf53768
Merge pull request #748 from ONEARMY/master
chrismclarke Nov 5, 2019
8c2cedc
Merge pull request #749 from ONEARMY/master
chrismclarke Nov 5, 2019
6a78ab7
Merge pull request #767 from ONEARMY/master
BenGamma Nov 13, 2019
c5a4f9b
Merge pull request #770 from ONEARMY/master
BenGamma Nov 15, 2019
cf9c84b
Merge pull request #794 from ONEARMY/master
chrismclarke Nov 26, 2019
a201620
Merge pull request #812 from ONEARMY/master
BenGamma Dec 3, 2019
5585f21
Merge pull request #814 from ONEARMY/master
chrismclarke Dec 4, 2019
4bdd632
Merge pull request #855 from ONEARMY/master
BenGamma Jan 6, 2020
b6ae865
Merge pull request #857 from ONEARMY/master
BenGamma Jan 7, 2020
e0f84e7
Merge pull request #861 from ONEARMY/master
BenGamma Jan 7, 2020
a449b56
Merge pull request #862 from ONEARMY/master
BenGamma Jan 7, 2020
ee89fe0
Merge pull request #865 from ONEARMY/master
BenGamma Jan 8, 2020
1184ee5
Merge pull request #878 from ONEARMY/master
BenGamma Jan 16, 2020
000bdd5
Merge pull request #884 from ONEARMY/master
chrismclarke Feb 3, 2020
f00f162
Merge pull request #911 from ONEARMY/master
BenGamma Mar 11, 2020
65a8cb1
Merge pull request #914 from ONEARMY/master
BenGamma Mar 22, 2020
1d0f37e
Merge pull request #924 from ONEARMY/master
BenGamma Mar 28, 2020
ca6b738
Merge pull request #959 from ONEARMY/master
chrismclarke Apr 23, 2020
793746b
Merge pull request #978 from ONEARMY/master
chrismclarke Jun 9, 2020
de03f2e
Bump dot-prop from 5.1.0 to 5.2.0 in /functions
dependabot[bot] Jul 30, 2020
5f3d24c
Bump elliptic from 6.5.2 to 6.5.3
dependabot[bot] Jul 30, 2020
4226350
Merge pull request #1004 from ONEARMY/dependabot/npm_and_yarn/functio…
BenGamma Aug 5, 2020
535f9f1
Merge pull request #1005 from ONEARMY/dependabot/npm_and_yarn/ellipti…
BenGamma Aug 5, 2020
be1fd12
Change map to cluster pins from different types together
tudi2d Aug 12, 2020
47fa3f2
Merge pull request #996 from ONEARMY/master
BenGamma Aug 19, 2020
f17461d
Merge pull request #1007 from tudi2d/1006-cluster-all-pins
BenGamma Aug 19, 2020
e68b1dc
update CI Production deploy
BenGamma Aug 19, 2020
635d140
deactivate CI for build
BenGamma Aug 21, 2020
252df32
Avoid notification when user edits pin or howto and it was previuosly…
alromh87 Aug 22, 2020
65266c2
update build script
BenGamma Aug 22, 2020
2bbc662
set declaration: false in tsconfig
BenGamma Aug 22, 2020
195a205
use type any for exported pages
BenGamma Aug 22, 2020
a7b1246
remove CI=true from build script in package.json
BenGamma Aug 22, 2020
b866c65
disable e2e test
BenGamma Aug 22, 2020
b6cfa4b
use latest firebase-admin package version
BenGamma Aug 22, 2020
2181b96
Merge pull request #1010 from ONEARMY/master
BenGamma Aug 22, 2020
04132f3
Revert "Fix deploys"
tudi2d Aug 24, 2020
4aa84b5
Merge pull request #1012 from tudi2d/revert-1010-master
davehakkens Aug 24, 2020
a1439eb
Revert "v1.2.1"
tudi2d Aug 24, 2020
8153d32
Merge pull request #1013 from tudi2d/revert-996-master
davehakkens Aug 24, 2020
4dcc417
set env.process.CI back to default true
BenGamma Aug 24, 2020
6ffdb70
Merge pull request #1014 from ONEARMY/master
BenGamma Aug 24, 2020
4da5f7b
fix all eslint warnings
BenGamma Aug 24, 2020
e1010bc
fix conflicts .eslintrc
BenGamma Aug 24, 2020
b01114b
fix conflicts again
BenGamma Aug 24, 2020
fb7f6ba
cherry pick fix eslint warnings
BenGamma Aug 24, 2020
000fc0d
Merge pull request #1018 from ONEARMY/master-good
BenGamma Aug 24, 2020
8c07079
revert commit a1439eb2769ef010104ed699356e2cf43beeb95a
BenGamma Aug 25, 2020
ba95377
cherry pick 195a2054a5a137ba7f6e76524c6fad21e60cb8bf
BenGamma Aug 22, 2020
494e203
use latest version of firebase-admin package
BenGamma Aug 25, 2020
4751f56
remove ts warning
BenGamma Aug 25, 2020
4d75866
cherry pick f17461dbd89174ba7ad71deb47026129312b1ad7
BenGamma Aug 19, 2020
aa5529a
Merge branch 'master' into alrhomh87-1008
BenGamma Aug 25, 2020
953ece8
Merge pull request #1020 from ONEARMY/alrhomh87-1008
BenGamma Aug 25, 2020
025b0d6
bump version 1.2.1
BenGamma Aug 25, 2020
1a20e43
Merge branch 'master' of https://github.com/ONEARMY/community-platform
BenGamma Aug 25, 2020
1a90ccc
feat: Adds more time options to how-to form
darigovresearch Aug 29, 2020
ef0e666
feat: Adds makePair to FormSettings.tsx following review
darigovresearch Aug 31, 2020
b49c9b5
refactor: Adjusts makePair to makeEntry in FormSettings.tsx
darigovresearch Aug 31, 2020
e59c90a
Merge branch 'master' into feat/974-extra-infos-profile
alromh87 Sep 2, 2020
85723eb
add extra logs for login issue
chrismclarke Sep 3, 2020
e84d1e9
fix: Removes <10 hours from FormSettings.tsx
darigovresearch Sep 5, 2020
372b225
Merge pull request #1024 from darigovresearch/master
davehakkens Sep 5, 2020
40b7deb
Fix #974 Extra infromation on Profile
alromh87 Sep 5, 2020
87e9ac9
Merge branch 'master' into feat/974-extra-infos-profile
alromh87 Sep 5, 2020
8b6e0c7
Added missing text for User Stats (How-to: , Events:)
alromh87 Sep 6, 2020
03b17a9
Profile extra info in correct order and in single line
alromh87 Sep 6, 2020
4152e7c
Right color for pin link in profile extras
alromh87 Sep 6, 2020
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
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
"@typescript-eslint/no-empty-interface": "warn",
"react/prop-types": "off",
"react/no-unknown-property": "warn",
"@typescript-eslint/no-var-requires":"off"
"@typescript-eslint/no-var-requires": "off"
}
}
1 change: 0 additions & 1 deletion cypress/support/custom-assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ const eqHowto = (chaiObj, utils) => {
expected.cover_image.name,
)


expected.steps.forEach((step, index) => {
expect(subject.steps[index], `Have step ${index}`).to.eqHowtoStep(
step,
Expand Down
2 changes: 1 addition & 1 deletion functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"cors": "^2.8.5",
"dateformat": "^3.0.3",
"express": "^4.16.4",
"firebase-admin": "8.3.0",
"firebase-admin": "^8.3.0",
"firebase-functions": "^3.2.0",
"fs-extra": "^7.0.1",
"google-auth-library": "^2.0.1",
Expand Down
5 changes: 4 additions & 1 deletion functions/src/Integrations/firebase-discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export const notifyHowToAccepted = functions.firestore
.document('v3_howtos/{id}')
.onWrite(async (change, context) => {
const info = change.after.exists ? change.after.data() : null
if (info === null || info.moderation !== 'accepted') {
const prevInfo = change.before.exists ? change.before.data() : null
const beenAccepted =
prevInfo !== null ? prevInfo.moderation === 'accepted' : null
if (info === null || info.moderation !== 'accepted' || beenAccepted) {
return
}
const { _createdBy, title, slug } = info
Expand Down
8 changes: 8 additions & 0 deletions functions/src/Integrations/firebase-slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export const notifyNewPin = functions.firestore
if (info === null || info.moderation !== 'awaiting-moderation' || prevModeration === 'awaiting-moderation') {
return
}
if (prevModeration === 'accepted' && info.moderation !== 'awaiting-moderation'){ // If edited after being accepted keep it accepted and avoid message #1008
return change.after.ref.parent.child('moderation').set('accepted');
}

const id = info._id
const type = info.type
Expand All @@ -42,9 +45,14 @@ export const notifyNewHowTo = functions.firestore
.document('v3_howtos/{id}')
.onWrite((change, context) => {
const info = change.after.exists ? change.after.data() : null
const prevInfo = change.before.exists ? change.before.data() : null
const prevModeration = (prevInfo !== null) ? prevInfo.moderation : null;
if (info === null || info.moderation !== 'awaiting-moderation') {
return
}
if (prevModeration === 'accepted' && info.moderation !== 'awaiting-moderation'){ // If edited after being accepted keep it accepted and avoid message #1008
return change.after.ref.parent.child('moderation').set('accepted');
}

const user = info._createdBy
const title = info.title
Expand Down
81 changes: 81 additions & 0 deletions functions/src/Integrations/user-stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as functions from 'firebase-functions'
import { db } from '../Firebase/firestoreDB'


export const countHowTos = functions.firestore
.document('v3_howtos/{id}')
.onWrite(async (change, context) => {

updateStats(change, 'v3_howtos', 'howToCount')

})

export const countEvents = functions.firestore
.document('v3_events/{id}')
.onWrite(async (change, context) => {

updateStats(change, 'v3_events', 'eventCount')

})

function updateStats(change, collection, target){

const info = change.after.exists ? change.after.data() : null
const prevInfo = change.before.exists ? change.before.data() : null
const userStatsRef = db.collection('v3_users/');

let delta = 0

if (info !== null && info.moderation === 'accepted' && prevInfo !== null && prevInfo.Moderation !== 'accepted') { // Increment if now accepted and previously different
delta = 1
} else if (prevInfo !== null && prevInfo.moderation === 'accepted' && (info === null || info.moderation !== 'accepted')) { // Decrement if previously accepted and now erased or moderation changed
delta = -1
} else {
return null
}

console.log('Update ', collection, ' delta: ', delta )

return userStatsRef.doc(info._createdBy).update({'_stats':{
[target]: admin.firestore.FieldValue.increment(delta)
}}).catch(e => {
console.log(e);
// In case stats for user are inexistent we compute from all his records, Only triggers if no user exist (new Collection)
// computeUserStats(info._createdBy)
})
}

// Compute one user stats
function computeUserStats(owner){

const userStatsRef = db.collection('v3_users/')

db.collection('v3_howtos').where("_createdBy", "==", owner).where("moderation", "==", "accepted")
.get()
.then(querySnapshot => {
let count = 0;
querySnapshot.forEach(doc => {
count++;
});
console.log('Accepted howtos for', owner ,',count: ', count);
userStatsRef.doc(owner).set({'_stats':{
howToCount: count
}}, {merge: true});
return null
}).catch(() => null);

db.collection('v3_events').where("_createdBy", "==", owner).where("moderation", "==", "accepted")
.get()
.then(querySnapshot => {
let count = 0;
querySnapshot.forEach(doc => {
count++;
});
console.log('Accepted events for', owner ,',count: ', count);
userStatsRef.doc(owner).set({'_stats':{
eventCount: count
}}, {merge: true});
return null
}).catch(() => null);
}

3 changes: 3 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as IntegrationsSlack from './Integrations/firebase-slack'
import * as IntegrationsDiscord from './Integrations/firebase-discord'
import { FirebaseUserBackup } from './Integrations/firebase-userBackup'
import * as IntegrationsEmail from './Integrations/firebase-email'
import * as UserStats from './Integrations/user-stats'
import * as Admin from './admin'

// the following endpoints are exposed for use by various triggers
Expand All @@ -23,6 +24,8 @@ exports.notifyHowToAccepted = IntegrationsDiscord.notifyHowToAccepted
exports.notifyEventAccepted = IntegrationsDiscord.notifyEventAccepted
exports.firebaseUserBackup = FirebaseUserBackup
exports.emailNotificationDemo = IntegrationsEmail.notifyEmailDemo
exports.countEvents = UserStats.countEvents
exports.countHowTos = UserStats.countHowTos
// CC Note, 2020-04-40
// folder-based naming conventions should be encourage from now on
exports.adminGetUserEmail = Admin.getUserEmail
6 changes: 3 additions & 3 deletions functions/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -837,9 +837,9 @@ diff@^3.2.0:
integrity sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==

dot-prop@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-5.1.0.tgz#bdd8c986a77b83e3fca524e53786df916cabbd8a"
integrity sha512-n1oC6NBF+KM9oVXtjmen4Yo7HyAVWV2UUl50dCYJdw2924K6dX9bf9TTTWaKtYlRn0FEtxG27KS80ayVLixxJA==
version "5.2.0"
resolved "https://registry.yarnpkg.com/dot-prop/-/dot-prop-5.2.0.tgz#c34ecc29556dc45f1f4c22697b6f4904e0cc4fcb"
integrity sha512-uEUyaDKoSQ1M4Oq8l45hSE26SnTxL6snNnqvK/VWx5wJhmff5z0FUVJDKDanor/6w3kzE3i7XZOk+7wC0EXr1A==
dependencies:
is-obj "^2.0.0"

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "precious-plastic-community-platform",
"version": "1.2.0",
"version": "1.2.1",
"private": true,
"scripts": {
"start": "react-app-rewired start",
Expand Down
190 changes: 190 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
'use strict'

// Do this as the first thing so that any code reading it knows the right env.
process.env.BABEL_ENV = 'production'
process.env.NODE_ENV = 'production'

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', err => {
throw err
})

// Ensure environment variables are read.
require('../config/env')

const path = require('path')
const chalk = require('react-dev-utils/chalk')
const fs = require('fs-extra')
const webpack = require('webpack')
const bfj = require('bfj')
const configFactory = require('../config/webpack.config')
const paths = require('../config/paths')
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles')
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages')
const printHostingInstructions = require('react-dev-utils/printHostingInstructions')
const FileSizeReporter = require('react-dev-utils/FileSizeReporter')
const printBuildError = require('react-dev-utils/printBuildError')

const measureFileSizesBeforeBuild = FileSizeReporter.measureFileSizesBeforeBuild
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild
const useYarn = fs.existsSync(paths.yarnLockFile)

// These sizes are pretty large. We'll warn for bundles exceeding them.
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024

const isInteractive = process.stdout.isTTY

// Warn and crash if required files are missing
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
process.exit(1)
}

// Process CLI arguments
const argv = process.argv.slice(2)
const writeStatsJson = argv.indexOf('--stats') !== -1

// Generate configuration
const config = configFactory('production')

// We require that you explicitly set browsers and do not fall back to
// browserslist defaults.
const { checkBrowsers } = require('react-dev-utils/browsersHelper')
checkBrowsers(paths.appPath, isInteractive)
.then(() => {
// First, read the current file sizes in build directory.
// This lets us display how much they changed later.
return measureFileSizesBeforeBuild(paths.appBuild)
})
.then(previousFileSizes => {
// Remove all content but keep the directory so that
// if you're in it, you don't end up in Trash
fs.emptyDirSync(paths.appBuild)
// Merge with the public folder
copyPublicFolder()
// Start the webpack build
return build(previousFileSizes)
})
.then(
({ stats, previousFileSizes, warnings }) => {
if (warnings.length) {
console.log(chalk.yellow('Compiled with warnings.\n'))
console.log(warnings.join('\n\n'))
console.log(
'\nSearch for the ' +
chalk.underline(chalk.yellow('keywords')) +
' to learn more about each warning.',
)
console.log(
'To ignore, add ' +
chalk.cyan('// eslint-disable-next-line') +
' to the line before.\n',
)
} else {
console.log(chalk.green('Compiled successfully.\n'))
}

console.log('File sizes after gzip:\n')
printFileSizesAfterBuild(
stats,
previousFileSizes,
paths.appBuild,
WARN_AFTER_BUNDLE_GZIP_SIZE,
WARN_AFTER_CHUNK_GZIP_SIZE,
)
console.log()

const appPackage = require(paths.appPackageJson)
const publicUrl = paths.publicUrl
const publicPath = config.output.publicPath
const buildFolder = path.relative(process.cwd(), paths.appBuild)
printHostingInstructions(
appPackage,
publicUrl,
publicPath,
buildFolder,
useYarn,
)
},
err => {
console.log(chalk.red('Failed to compile.\n'))
printBuildError(err)
process.exit(1)
},
)
.catch(err => {
if (err && err.message) {
console.log(err.message)
}
process.exit(1)
})

// Create the production build and print the deployment instructions.
function build(previousFileSizes) {
console.log('Creating an optimized production build...')

const compiler = webpack(config)
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
let messages
if (err) {
if (!err.message) {
return reject(err)
}
messages = formatWebpackMessages({
errors: [err.message],
warnings: [],
})
} else {
messages = formatWebpackMessages(
stats.toJson({ all: false, warnings: true, errors: true }),
)
}
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
if (messages.errors.length > 1) {
messages.errors.length = 1
}
return reject(new Error(messages.errors.join('\n\n')))
}
if (
process.env.CI &&
(typeof process.env.CI !== 'string' ||
process.env.CI.toLowerCase() !== 'false') &&
messages.warnings.length
) {
console.log(
chalk.yellow(
'\nTreating warnings as errors because process.env.CI = true.\n' +
'Most CI servers set it automatically.\n',
),
)
return reject(new Error(messages.warnings.join('\n\n')))
}

const resolveArgs = {
stats,
previousFileSizes,
warnings: messages.warnings,
}
if (writeStatsJson) {
return bfj
.write(paths.appBuild + '/bundle-stats.json', stats.toJson())
.then(() => resolve(resolveArgs))
.catch(error => reject(new Error(error)))
}

return resolve(resolveArgs)
})
})
}

function copyPublicFolder() {
fs.copySync(paths.appPublic, paths.appBuild, {
dereference: true,
filter: file => file !== paths.appHtml,
})
}
Loading