From 749a267d2a1deba42cfa06b5699b1e206284b9cd Mon Sep 17 00:00:00 2001 From: Ben Hejkal Date: Thu, 19 Dec 2024 11:31:31 -0600 Subject: [PATCH] remove ramda from nonprofits (incomplete) --- client/js/nonprofits/dashboard/page.js | 3 +-- client/js/nonprofits/donate/amount-step.js | 6 ++--- .../info-step/customFields/legacy.ts | 3 +-- client/js/nonprofits/donate/get-params.js | 6 ++--- client/js/nonprofits/donate/info-step.js | 12 ++++----- client/js/nonprofits/donate/payment-step.js | 8 +++--- client/js/nonprofits/payments_chart.js | 25 ++++++++++--------- .../recurring_donations/index/index.es6 | 3 +-- client/js/nonprofits/reports/modal.js | 1 - client/js/nonprofits/supporter_form/index.es6 | 2 +- .../js/nonprofits/supporters/import/index.es6 | 2 +- .../supporters/index/merge_supporters.js | 3 +-- .../index/sidepanel/generate-content.js | 3 +-- .../supporters/index/sidepanel/index.js | 4 +-- .../index/sidepanel/offsite-donation-form.js | 1 - .../index/sidepanel/supporter-actions.js | 1 - .../index/sidepanel/supporter-activities.js | 7 +++--- 17 files changed, 40 insertions(+), 50 deletions(-) diff --git a/client/js/nonprofits/dashboard/page.js b/client/js/nonprofits/dashboard/page.js index 0208b98a8..750e0375b 100644 --- a/client/js/nonprofits/dashboard/page.js +++ b/client/js/nonprofits/dashboard/page.js @@ -35,7 +35,6 @@ todos(function(data, url) { }) // the only ff component so far on this page is events listings -const R = require('ramda') const h = require('snabbdom/h') const flyd = require('flyd') const render = require('ff-core/render') @@ -54,7 +53,7 @@ const view = state => { return mixin([h('p.u-padding--15.u-centered', 'Loading...')]) if(!state.resp$().body.length) return mixin([h('p.u-padding--15.u-centered', `None currently`)]) - return mixin(R.map(listing, state.resp$().body)) + return mixin(state.resp$().body.map(listing)); } var container = document.querySelector('#js-eventsListing') diff --git a/client/js/nonprofits/donate/amount-step.js b/client/js/nonprofits/donate/amount-step.js index 85ebeaf0e..c2f271ae9 100644 --- a/client/js/nonprofits/donate/amount-step.js +++ b/client/js/nonprofits/donate/amount-step.js @@ -158,7 +158,7 @@ function amountFields(state) { h('button.button.u-width--full.white.amount', { class: {'is-selected': state.buttonAmountSelected$() && state.donation$().amount === amt.amount*100} , on: {click: ev => { - state.evolveDonation$({amount: R.always(dollarsToCents(amt.amount))}) + state.evolveDonation$({amount: () => dollarsToCents(amt.amount)}) state.buttonAmountSelected$(true) state.currentStep$(1) // immediately advance steps when selecting an amount button } } @@ -172,10 +172,10 @@ function amountFields(state) { , on: { focus: ev => { state.buttonAmountSelected$(false) - state.evolveDonation$({amount: R.always(dollarsToCents(ev.currentTarget.value))}) + state.evolveDonation$({amount: () => dollarsToCents(ev.currentTarget.value)}) } , input: ev => { - state.evolveDonation$({amount: R.always(dollarsToCentsSafe(ev.currentTarget.value))}) + state.evolveDonation$({amount: () => dollarsToCentsSafe(ev.currentTarget.value)}) } } }) diff --git a/client/js/nonprofits/donate/components/info-step/customFields/legacy.ts b/client/js/nonprofits/donate/components/info-step/customFields/legacy.ts index e1a356ac6..c7ec3a64b 100644 --- a/client/js/nonprofits/donate/components/info-step/customFields/legacy.ts +++ b/client/js/nonprofits/donate/components/info-step/customFields/legacy.ts @@ -1,5 +1,4 @@ // License: LGPL-3.0-or-later -import {map as Rmap} from 'ramda'; import { CustomFieldDescription } from '../../../types'; import customField from './customField'; const h = require('snabbdom/h'); @@ -7,5 +6,5 @@ const h = require('snabbdom/h'); export function customFields(fields?:CustomFieldDescription[]|null): ReturnType | '' { if (!fields) return ''; - return h('div', Rmap(customField, fields)); + return h('div', fields.map(customField)); } diff --git a/client/js/nonprofits/donate/get-params.js b/client/js/nonprofits/donate/get-params.js index 9fe05dcf5..098e2d8cf 100644 --- a/client/js/nonprofits/donate/get-params.js +++ b/client/js/nonprofits/donate/get-params.js @@ -10,12 +10,10 @@ module.exports = params => { multiple_designations: splitParam , custom_amounts: parseCustomAmounts , custom_fields: parseCustomFields - , tags: tags => R.map(tag => { - return tag.trim() - }, R.split(',', tags)) + , tags: tags => tags.split(',').map(tag => tag.trim()) }) - const outputParams = R.compose(evolve, merge)(params) + const outputParams = evolve(merge(params)) if (window.app && window.app.widget && window.app.widget.custom_amounts) { outputParams.custom_amounts = window.app.widget.custom_amounts } diff --git a/client/js/nonprofits/donate/info-step.js b/client/js/nonprofits/donate/info-step.js index 045ae8136..af2de0a28 100644 --- a/client/js/nonprofits/donate/info-step.js +++ b/client/js/nonprofits/donate/info-step.js @@ -1,6 +1,6 @@ // License: LGPL-3.0-or-later const h = require('snabbdom/h') -const R = require('ramda') +const pick = require('lodash/pick'); const flyd = require('flyd') const uuid = require('uuid') const supporterFields = require('../../components/supporter-fields') @@ -30,10 +30,10 @@ function init(donation$, parentState) { // Save supporter for dedication logic state.dedicationData$ = flyd.map(form => serialize(form, {hash: true}), state.submitDedication$) const dedicationSuppData$ = flyd.map( - data => R.merge( - R.pick(['phone', 'email', 'address'], data) - , {name: `${data.first_name||''} ${data.last_name||''}`} - ) + data => ({ + ...pick(data, ['phone', 'email', 'address']) + , name: `${data.first_name||''} ${data.last_name||''}` + }) , state.dedicationData$ ) state.showDedicationForm$ = flyd.map(()=> false, state.submitDedication$) @@ -64,7 +64,7 @@ const postSupporter = supporter => , request({ method: 'post' , path: `/nonprofits/${app.nonprofit_id}/supporters` - , send: {supporter: R.merge(supporter, {locale: I18n.locale})} + , send: {supporter: {...supporter, locale: I18n.locale } } }).load ) diff --git a/client/js/nonprofits/donate/payment-step.js b/client/js/nonprofits/donate/payment-step.js index e14a05bd6..298c5d445 100644 --- a/client/js/nonprofits/donate/payment-step.js +++ b/client/js/nonprofits/donate/payment-step.js @@ -121,7 +121,7 @@ function init(state) { const donationWithCardToken$ = flyd.lift(R.assoc('token'), cardToken$, donationWithAmount$) // Set the sepa transfer details ID into the donation object when it is saved - const sepaId$ = flyd.map(R.prop('id'), state.sepaForm.saved$) + const sepaId$ = flyd.map(s => s.id, state.sepaForm.saved$) const donationWithSepaId$ = flyd.lift(R.assoc('direct_debit_detail_id'), sepaId$, state.donation$) state.donationParams$ = flyd.immediate( @@ -193,7 +193,7 @@ function init(state) { } const postGiftOption = (campaign_gift_option_id, result) => { - return flyd.map(R.prop('body'), request({ + return flyd.map(r => r.body, request({ path: '/campaign_gifts' , method: 'post' , send: { @@ -211,7 +211,7 @@ const postTracking = (utmParams, donationResponse) => { const params = R.merge(utmParams, { donation_id: donationResponse().donation.id }) if (utmParams.utm_source || utmParams.utm_medium || utmParams.utm_content || utmParams.utm_campaign) { - return flyd.map(R.prop('body'), request({ + return flyd.map(r => r.body, request({ path: `/nonprofits/${app.nonprofit_id}/tracking` , method: 'post' , send: params @@ -246,7 +246,7 @@ const postDonation = (donation) => { delete donation.weekly; // needs to be removed to be processed if (donation.recurring) donation = { recurring_donation: donation } - return flyd.map(R.prop('body'), request({ + return flyd.map(r => r.body, request({ path: prefix + postfix , method: 'post' , send: donation diff --git a/client/js/nonprofits/payments_chart.js b/client/js/nonprofits/payments_chart.js index 9a971d03c..0e4992b9a 100644 --- a/client/js/nonprofits/payments_chart.js +++ b/client/js/nonprofits/payments_chart.js @@ -1,6 +1,5 @@ // License: LGPL-3.0-or-later const request = require('../common/client') -const R = require('ramda') const Chart = require('chart.js') const Pikaday = require('pikaday') const moment = require('moment') @@ -28,18 +27,20 @@ appl.def('updateChartParams', function(formObj) { }) // start date Pickaday -new Pikaday(R.merge({ +new Pikaday({ field: document.getElementById('js-paymentsChart-startDate') , maxDate: moment().subtract(1, 'week').toDate() , defaultDate: moment().subtract(1, 'years').toDate() -}, pickadayDefaults)) + , ...pickadayDefaults +}) // end date Pickaday -new Pikaday(R.merge({ +new Pikaday({ field: document.getElementById('js-paymentsChart-endDate') , maxDate: moment().toDate() , defaultDate: moment().toDate() -}, pickadayDefaults)) + , ...pickadayDefaults +}) var ctx = document.getElementById('js-paymentsChart').getContext('2d') @@ -56,7 +57,7 @@ function updateChart(params) { request.get(url) .query(params) .end(function(err, resp) { - chart.data.labels = formatLabels(R.pluck('time_span', resp.body), params.timeSpan) + chart.data.labels = formatLabels(resp.body.map(i => i['time_span']), params.timeSpan) chart.data.datasets = formatDatasets(resp.body) chart.update() appl.def('loading_chart', false) @@ -66,15 +67,15 @@ function updateChart(params) { function formatLabels(dates, type) { switch (type) { case "year": - return R.map(st => moment(st).format('YYYY'), dates) + return dates.map(st => moment(st).format('YYYY')) case "month": - return R.map(st => moment(st).format('MMM YYYY'), dates) + return dates.map(st => moment(st).format('MMM YYYY')) case "week": - return R.map(st => + return dates.map(st => `${moment(st).format('M/D/YY')} - ${moment(st).add(7, 'days').format('M/D/YY')}` - , dates) + ) default: - return R.map(st => moment(st).format(frontendFormat), dates) + return dates.map(st => moment(st).format(frontendFormat)) } } @@ -100,7 +101,7 @@ const formatDatasets = (data) => [ function dataset(label, key, rgb, data) { return { label: label - , data: R.pluck(key, data) + , data: data.map(i => i[key]) , borderWidth: 1 , borderColor: `rgb(${rgb})` , backgroundColor: `rgba(${rgb},0.3)` diff --git a/client/js/nonprofits/recurring_donations/index/index.es6 b/client/js/nonprofits/recurring_donations/index/index.es6 index b32e703a1..981360218 100644 --- a/client/js/nonprofits/recurring_donations/index/index.es6 +++ b/client/js/nonprofits/recurring_donations/index/index.es6 @@ -2,7 +2,6 @@ const snabbdom = require('snabbdom') const flyd = require('flyd') const h = require('snabbdom/h') -const R = require('ramda') const modal = require('ff-core/modal') const render = require('ff-core/render') const request = require('../../../common/request') @@ -10,7 +9,7 @@ const request = require('../../../common/request') function init() { var state = {} state.modalID$ = flyd.stream() - state.data$ = flyd.map(R.prop('body'), request({ + state.data$ = flyd.map(r => r.body, request({ path: `/nonprofits/${app.nonprofit_id}/recurring_donation_stats` , method: 'get' }).load) diff --git a/client/js/nonprofits/reports/modal.js b/client/js/nonprofits/reports/modal.js index cba69b2d7..1bc462ef1 100644 --- a/client/js/nonprofits/reports/modal.js +++ b/client/js/nonprofits/reports/modal.js @@ -1,7 +1,6 @@ // License: LGPL-3.0-or-later const flyd = require('flyd') const flyd_filter = require('flyd/module/filter') -const R = require('ramda') const h = require('snabbdom/h') const moment = require('moment') diff --git a/client/js/nonprofits/supporter_form/index.es6 b/client/js/nonprofits/supporter_form/index.es6 index a9a4200e1..0b091bd34 100644 --- a/client/js/nonprofits/supporter_form/index.es6 +++ b/client/js/nonprofits/supporter_form/index.es6 @@ -23,7 +23,7 @@ const postRequest = ev => { }).load } -const getReqBody = flyd.map(R.prop('body')) +const getReqBody = flyd.map(r => r.body) const response$ = getReqBody(flatMap(postRequest, submit$)) diff --git a/client/js/nonprofits/supporters/import/index.es6 b/client/js/nonprofits/supporters/import/index.es6 index 27733ff3b..851a8b78b 100644 --- a/client/js/nonprofits/supporters/import/index.es6 +++ b/client/js/nonprofits/supporters/import/index.es6 @@ -99,7 +99,7 @@ function init() { // post to /imports after the file is uploaded to S3 const postImport = R.curry((headers, file) => { - return flyd.map(R.prop('body'), request({ + return flyd.map(r => r.body, request({ method: 'post' , path: `/nonprofits/${app.nonprofit_id}/imports` , send: {file_uri: file.uri, header_matches: headers} diff --git a/client/js/nonprofits/supporters/index/merge_supporters.js b/client/js/nonprofits/supporters/index/merge_supporters.js index 507ee1e62..22160b82d 100644 --- a/client/js/nonprofits/supporters/index/merge_supporters.js +++ b/client/js/nonprofits/supporters/index/merge_supporters.js @@ -3,7 +3,6 @@ var action_recipient = require("./action_recipient") var request = require('../../../common/client') require('../../../components/wizard') var formatErr = require('../../../common/format_response_error') -const R = require('ramda') appl.def('merge.has_any', function(arr) { var supporters = appl.merge.data.supporters @@ -42,7 +41,7 @@ appl.def('merge.init', function(){ appl.def('merge.set', function(form_obj, node) { var supp = appl.merge.data.new_supporter - appl.def('merge.data.new_supporter', R.merge(supp, form_obj)) + appl.def('merge.data.new_supporter', {...supp, ...form_obj}) }) appl.def('merge.select_address', function(supp, node) { diff --git a/client/js/nonprofits/supporters/index/sidepanel/generate-content.js b/client/js/nonprofits/supporters/index/sidepanel/generate-content.js index acdd5cfd8..1a49b0dd9 100644 --- a/client/js/nonprofits/supporters/index/sidepanel/generate-content.js +++ b/client/js/nonprofits/supporters/index/sidepanel/generate-content.js @@ -1,6 +1,5 @@ // License: LGPL-3.0-or-later const h = require('snabbdom/h') -const R = require('ramda') const marked = require('marked') const format = require('../../../../common/format') @@ -164,7 +163,7 @@ exports.SupporterEmail = (data, state) => { title: `Email thread started by ${jd.from}` , icon: 'fa-envelope' , body: body - // , body: canView ? R.concat(body, thread) : R.concat(body, signIn) + // , body: canView ? [...body, ...thread] : [...body, ...signIn] } } diff --git a/client/js/nonprofits/supporters/index/sidepanel/index.js b/client/js/nonprofits/supporters/index/sidepanel/index.js index 6dc508414..5ffbca906 100644 --- a/client/js/nonprofits/supporters/index/sidepanel/index.js +++ b/client/js/nonprofits/supporters/index/sidepanel/index.js @@ -58,8 +58,8 @@ const init = _ => { const deleteNoteId$ = flyd.map(d => d.attachment_id, state.deleteNote$) state.noteAjaxMethod$ = mergeAll([ - flyd.map(R.always('post'), state.newNote$) - , flyd.map(R.always('put'), state.editNote$) + flyd.map(() => 'post', state.newNote$) + , flyd.map(() => 'put', state.editNote$) ]) state.supporterNoteForm = supporterNoteForm.init(state) diff --git a/client/js/nonprofits/supporters/index/sidepanel/offsite-donation-form.js b/client/js/nonprofits/supporters/index/sidepanel/offsite-donation-form.js index a75b722af..1b5ad1b18 100644 --- a/client/js/nonprofits/supporters/index/sidepanel/offsite-donation-form.js +++ b/client/js/nonprofits/supporters/index/sidepanel/offsite-donation-form.js @@ -1,5 +1,4 @@ // License: LGPL-3.0-or-later -const R = require('ramda') const h = require('snabbdom/h') const flyd = require('flyd') const modal = require('ff-core/modal') diff --git a/client/js/nonprofits/supporters/index/sidepanel/supporter-actions.js b/client/js/nonprofits/supporters/index/sidepanel/supporter-actions.js index 304d0ba3e..d8e58942a 100644 --- a/client/js/nonprofits/supporters/index/sidepanel/supporter-actions.js +++ b/client/js/nonprofits/supporters/index/sidepanel/supporter-actions.js @@ -1,5 +1,4 @@ // License: LGPL-3.0-or-later -const R = require('ramda') const flatMap = require('flyd/module/flatmap') const flyd = require('flyd') const h = require('snabbdom/h') diff --git a/client/js/nonprofits/supporters/index/sidepanel/supporter-activities.js b/client/js/nonprofits/supporters/index/sidepanel/supporter-activities.js index b44e47b1e..303a91abd 100644 --- a/client/js/nonprofits/supporters/index/sidepanel/supporter-activities.js +++ b/client/js/nonprofits/supporters/index/sidepanel/supporter-activities.js @@ -1,5 +1,4 @@ // License: LGPL-3.0-or-later -const R = require('ramda') const h = require('snabbdom/h') const flyd = require('flyd') const moment = require('moment') @@ -11,7 +10,7 @@ const generateContent = require('./generate-content') function init(parentState) { const activitiesWithJson$ = flyd.map( - R.map(parseActivityJson) + i => i.map(parseActivityJson) , parentState.activities$ ) const response$ = flyd.merge( @@ -49,7 +48,7 @@ function jsonOrNull(testObj) { const parseActivityJson = data => { let json_data = jsonOrNull(data.json_data) || {}; json_data.dedication = tryJSON(json_data.dedication) - return R.merge(data, {json_data}) + return {...data, json_data} } const view = parentState => { @@ -64,7 +63,7 @@ const view = parentState => { h('p.u-color--grey', 'No activity yet...') ]) } - return h('ul.timeline-activities', R.map(activityContent(parentState), state.response$())) + return h('ul.timeline-activities', state.response$().map(activityContent(parentState))); } // used to construct each activitiy list element