From 05189c4cb7572f74c7a1436d8e8254edcac60756 Mon Sep 17 00:00:00 2001 From: James Baxley Date: Sat, 31 Dec 2016 22:05:46 -0500 Subject: [PATCH] =?UTF-8?q?switch=20out=20giving=20query=20and=20handle=20?= =?UTF-8?q?graceful=20fallbacks=20for=20studies=20con=E2=80=A6=20(#1693)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * switch out giving query and handle graceful fallbacks for studies content * fix lint error --- .../givingSummaryEnhancer.js.snap | 196 +++++++++++++++++- .../home/__tests__/givingSummaryEnhancer.js | 75 +++---- .../pages/give/home/givingSummaryEnhancer.js | 46 ++-- imports/pages/studies/Single.js | 18 ++ imports/pages/studies/__tests__/Single.js | 10 + .../__tests__/__snapshots__/Single.js.snap | 9 + 6 files changed, 288 insertions(+), 66 deletions(-) diff --git a/imports/pages/give/home/__tests__/__snapshots__/givingSummaryEnhancer.js.snap b/imports/pages/give/home/__tests__/__snapshots__/givingSummaryEnhancer.js.snap index 662ed83ce..fabded360 100644 --- a/imports/pages/give/home/__tests__/__snapshots__/givingSummaryEnhancer.js.snap +++ b/imports/pages/give/home/__tests__/__snapshots__/givingSummaryEnhancer.js.snap @@ -1,9 +1,7 @@ exports[`data format should return an object with correct keys 1`] = ` Object { "accounts": Object { - "Christmas Offering": 0, "General Fund": 66, - "Step Up Fund": 0, }, "chartData": Array [ Object { @@ -68,5 +66,199 @@ Object { }, ], "total": 66, + "transactions": Array [ + Object { + "date": "Tue Nov 01 2016 07:53:00 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 1, + }, + ], + "id": "123456781", + }, + Object { + "date": "Mon Oct 03 2016 07:55:09 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 2, + }, + ], + "id": "123456782", + }, + Object { + "date": "Thu Sep 01 2016 09:41:39 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 3, + }, + ], + "id": "123456783", + }, + Object { + "date": "Mon Aug 01 2016 13:13:31 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 4, + }, + ], + "id": "123456784", + }, + Object { + "date": "Fri Jul 01 2016 10:26:52 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 5, + }, + ], + "id": "123456785", + }, + Object { + "date": "Wed Jun 01 2016 07:51:23 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 6, + }, + ], + "id": "123456786", + }, + Object { + "date": "Fri May 13 2016 15:08:35 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 7, + }, + ], + "id": "123456787", + }, + Object { + "date": "Sat Apr 30 2016 09:50:11 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 8, + }, + ], + "id": "12345678", + }, + Object { + "date": "Sat Apr 30 2016 09:49:35 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 9, + }, + ], + "id": "12345678", + }, + Object { + "date": "Mon Apr 18 2016 15:42:15 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 0, + }, + ], + "id": "12345678", + }, + Object { + "date": "Fri Apr 01 2016 11:12:21 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 1, + }, + ], + "id": "12345678", + }, + Object { + "date": "Thu Mar 31 2016 09:30:01 GMT-0400 (EDT)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 2, + }, + ], + "id": "12345678", + }, + Object { + "date": "Thu Mar 03 2016 02:42:37 GMT-0500 (EST)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 3, + }, + ], + "id": "12345678", + }, + Object { + "date": "Tue Mar 01 2016 06:20:39 GMT-0500 (EST)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 4, + }, + ], + "id": "12345678", + }, + Object { + "date": "Sat Jan 30 2016 07:37:32 GMT-0500 (EST)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 5, + }, + ], + "id": "12345678", + }, + Object { + "date": "Fri Jan 01 2016 15:47:43 GMT-0500 (EST)", + "details": Array [ + Object { + "account": Object { + "name": "General Fund", + }, + "amount": 6, + }, + ], + "id": "12345678", + }, + ], } `; diff --git a/imports/pages/give/home/__tests__/givingSummaryEnhancer.js b/imports/pages/give/home/__tests__/givingSummaryEnhancer.js index 5cc881270..949bd4590 100644 --- a/imports/pages/give/home/__tests__/givingSummaryEnhancer.js +++ b/imports/pages/give/home/__tests__/givingSummaryEnhancer.js @@ -3,47 +3,40 @@ import {formatGivingSummaryData} from "../givingSummaryEnhancer"; const mockGQLData = { "data": { - "accounts": [ - { - "total": 66, "name": "General Fund", - "transactions": [ - {"id": "123456781", "date": "Tue Nov 01 2016 07:53:00 GMT-0400 (EDT)", - "details": [{ "amount": 1 }]}, - {"id": "123456782", "date": "Mon Oct 03 2016 07:55:09 GMT-0400 (EDT)", - "details": [{ "amount": 2 }]}, - {"id": "123456783", "date": "Thu Sep 01 2016 09:41:39 GMT-0400 (EDT)", - "details": [{ "amount": 3 }]}, - {"id": "123456784", "date": "Mon Aug 01 2016 13:13:31 GMT-0400 (EDT)", - "details": [{ "amount": 4 }]}, - {"id": "123456785", "date": "Fri Jul 01 2016 10:26:52 GMT-0400 (EDT)", - "details": [{ "amount": 5 }]}, - {"id": "123456786", "date": "Wed Jun 01 2016 07:51:23 GMT-0400 (EDT)", - "details": [{ "amount": 6 }]}, - {"id": "123456787", "date": "Fri May 13 2016 15:08:35 GMT-0400 (EDT)", - "details": [{ "amount": 7 }]}, - {"id": "12345678", "date": "Sat Apr 30 2016 09:50:11 GMT-0400 (EDT)", - "details": [{ "amount": 8 }]}, - {"id": "12345678", "date": "Sat Apr 30 2016 09:49:35 GMT-0400 (EDT)", - "details": [{ "amount": 9 }]}, - {"id": "12345678", "date": "Mon Apr 18 2016 15:42:15 GMT-0400 (EDT)", - "details": [{ "amount": 0 }]}, - {"id": "12345678", "date": "Fri Apr 01 2016 11:12:21 GMT-0400 (EDT)", - "details": [{ "amount": 1 }]}, - {"id": "12345678", "date": "Thu Mar 31 2016 09:30:01 GMT-0400 (EDT)", - "details": [{ "amount": 2 }]}, - {"id": "12345678", "date": "Thu Mar 03 2016 02:42:37 GMT-0500 (EST)", - "details": [{ "amount": 3 }]}, - {"id": "12345678", "date": "Tue Mar 01 2016 06:20:39 GMT-0500 (EST)", - "details": [{ "amount": 4 }]}, - {"id": "12345678", "date": "Sat Jan 30 2016 07:37:32 GMT-0500 (EST)", - "details": [{ "amount": 5 }]}, - {"id": "12345678", "date": "Fri Jan 01 2016 15:47:43 GMT-0500 (EST)", - "details": [{ "amount": 6 }] } - ], - }, - { "total": 0, "name": "Christmas Offering", "transactions": []}, - { "total": 0, "name": "Step Up Fund", "transactions": []} - ] + "transactions": [ + {"id": "123456781", "date": "Tue Nov 01 2016 07:53:00 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 1 }]}, + {"id": "123456782", "date": "Mon Oct 03 2016 07:55:09 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 2 }]}, + {"id": "123456783", "date": "Thu Sep 01 2016 09:41:39 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 3 }]}, + {"id": "123456784", "date": "Mon Aug 01 2016 13:13:31 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 4 }]}, + {"id": "123456785", "date": "Fri Jul 01 2016 10:26:52 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 5 }]}, + {"id": "123456786", "date": "Wed Jun 01 2016 07:51:23 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 6 }]}, + {"id": "123456787", "date": "Fri May 13 2016 15:08:35 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 7 }]}, + {"id": "12345678", "date": "Sat Apr 30 2016 09:50:11 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 8 }]}, + {"id": "12345678", "date": "Sat Apr 30 2016 09:49:35 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 9 }]}, + {"id": "12345678", "date": "Mon Apr 18 2016 15:42:15 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 0 }]}, + {"id": "12345678", "date": "Fri Apr 01 2016 11:12:21 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 1 }]}, + {"id": "12345678", "date": "Thu Mar 31 2016 09:30:01 GMT-0400 (EDT)", + "details": [{ "account": { "name": "General Fund"}, "amount": 2 }]}, + {"id": "12345678", "date": "Thu Mar 03 2016 02:42:37 GMT-0500 (EST)", + "details": [{ "account": { "name": "General Fund"}, "amount": 3 }]}, + {"id": "12345678", "date": "Tue Mar 01 2016 06:20:39 GMT-0500 (EST)", + "details": [{ "account": { "name": "General Fund"}, "amount": 4 }]}, + {"id": "12345678", "date": "Sat Jan 30 2016 07:37:32 GMT-0500 (EST)", + "details": [{ "account": { "name": "General Fund"}, "amount": 5 }]}, + {"id": "12345678", "date": "Fri Jan 01 2016 15:47:43 GMT-0500 (EST)", + "details": [{ "account": { "name": "General Fund"}, "amount": 6 }] } + ], } } diff --git a/imports/pages/give/home/givingSummaryEnhancer.js b/imports/pages/give/home/givingSummaryEnhancer.js index f364c6478..b0f828b17 100644 --- a/imports/pages/give/home/givingSummaryEnhancer.js +++ b/imports/pages/give/home/givingSummaryEnhancer.js @@ -23,29 +23,30 @@ export const formatGivingSummaryData = (data: Object): ?Object => { { month: "December", amount: 0, tick: "D" }, ]; - if (!data || !data.accounts) return null; - const accountsData = data.accounts; + if (!data || !data.transactions) return null; + const transactions = data.transactions; - if (!Array.isArray(accountsData)) return null; + if (!Array.isArray(transactions)) return null; const summaryData = [...baseData]; let total = 0; const accounts = {}; - accountsData.map((account) => { - accounts[account.name] = account.total; - if (!account.transactions) return null; - + transactions.map((transaction) => { // iterate over every transaction, and sum up the months - account.transactions.map((transaction) => { - const month = moment(new Date(transaction.date)).format("M"); - if (!transaction.details || !transaction.details.length) return transaction; - summaryData[Number(month) - 1].amount += transaction.details - .reduce((prev, { amount }) => prev + amount, 0); - total += transaction.details.reduce((prev, { amount }) => prev + amount, 0); - return transaction; + const month = moment(new Date(transaction.date)).format("M"); + if (!transaction.details || !transaction.details.length) return transaction; + + summaryData[Number(month) - 1].amount += transaction.details + .reduce((prev, { amount }) => prev + amount, 0); + + total += transaction.details.reduce((prev, { amount }) => prev + amount, 0); + transaction.details.forEach(({ amount, account }) => { + if (!account) return; + if (!accounts[account.name]) accounts[account.name] = 0; + accounts[account.name] += amount; }); - return null; + return transaction; }); return ({ @@ -58,14 +59,13 @@ export const formatGivingSummaryData = (data: Object): ?Object => { const YTD_QUERY = gql` query givingSummary($start: String!, $end: String!) { - accounts(allFunds: true) { - total(start: $start, end: $end) - name - transactions(limit: 0, start: $start, end: $end) { - id - date - details { - amount + transactions(start: $start, end: $end, limit: 0) { + id + date + details { + amount + account { + name } } } diff --git a/imports/pages/studies/Single.js b/imports/pages/studies/Single.js index 59284eea3..9c9839122 100644 --- a/imports/pages/studies/Single.js +++ b/imports/pages/studies/Single.js @@ -19,8 +19,11 @@ import Shareable from "../../mixins/mixins.Shareable"; import RelatedContent from "../../blocks/related-content"; import collections from "../../util/collections"; +import contentHelpers from "../../util/content"; import styles from "../../util/styles"; import react from "../../util/react"; +import inAppLink from "../../util/inAppLink"; + import StudyHero from "./Hero"; import StudyEntryList from "./EntryList"; @@ -88,6 +91,7 @@ class StudiesSingleWithoutData extends Component { } const study = content; + const { isLight } = study.content; return (
+ {!study.children.length && ( +
+ + View Study + +
+ )}
@@ -126,6 +141,9 @@ const STUDY_SINGLE_QUERY = gql` title status channelName + children { + id + } meta { urlTitle siteId diff --git a/imports/pages/studies/__tests__/Single.js b/imports/pages/studies/__tests__/Single.js index a824a24ba..591e9ec6a 100644 --- a/imports/pages/studies/__tests__/Single.js +++ b/imports/pages/studies/__tests__/Single.js @@ -37,6 +37,11 @@ const defaultProps = { study: { content: { id: "1", + meta: { + urlTitle: "study", + }, + channelName: "studies", + children: [], content: { description: "

study

", images: [], @@ -80,6 +85,11 @@ it("renders studies content", () => { study: { content: { id: "1", + children: [{ id: "1"}], + meta: { + urlTitle: "study", + }, + channelName: "studies", content: { description: "

study

", images: [ diff --git a/imports/pages/studies/__tests__/__snapshots__/Single.js.snap b/imports/pages/studies/__tests__/__snapshots__/Single.js.snap index fd79e283c..8d27fed5e 100644 --- a/imports/pages/studies/__tests__/__snapshots__/Single.js.snap +++ b/imports/pages/studies/__tests__/__snapshots__/Single.js.snap @@ -96,6 +96,15 @@ exports[`test renders with no image 1`] = ` } } /> +
+ + View Study + +
`;