Skip to content

Commit

Permalink
Merge pull request #310 from edenia/feat/election-date-isnt-shown-302
Browse files Browse the repository at this point in the history
feat(webapp, hapi): add election date to bar chart
  • Loading branch information
xavier506 authored Dec 9, 2022
2 parents 3bda906 + 3c33930 commit b83b244
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 37 deletions.
11 changes: 7 additions & 4 deletions hapi/src/gql/income-frontend.gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const getPercentAllElections = async (getMany = false) => {
return getMany ? getPercentAllElections : getPercentAllElections[0]
}

const getIncomeByElections = async (getMany = false) => {
const getIncomeByElections = async () => {
const query = `
query getIncomeByElections {
total_by_category_and_election(
Expand All @@ -50,13 +50,16 @@ const getIncomeByElections = async (getMany = false) => {
amount
usd_total
}
eden_historic_election {
election
date_election
}
}
`

const { total_by_category_and_election: getIncomeByElections } =
await hasuraUtil.instance.request(query)
const getIncomeByElections = await hasuraUtil.instance.request(query)

return getMany ? getIncomeByElections : getIncomeByElections[0]
return getIncomeByElections
}

module.exports = {
Expand Down
22 changes: 14 additions & 8 deletions hapi/src/services/income-frontend.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ const generateColor = () => {
}

const newDataFormatByElectionsIncome = electionsList => {
const dataElections = electionsList.total_by_category_and_election
const historicElections = electionsList.eden_historic_election
const elections = []
for (let pos = 0; pos < electionsList.length; pos = pos + 2) {
for (let pos = 0; pos < dataElections.length; pos = pos + 2) {
const date = historicElections.find(
element => element.election === dataElections[pos].election
)
const election = {
election: `Election ${electionsList[pos].election + 1}`,
EOS_CLAIMED: Number(electionsList[pos].amount),
EOS_UNCLAIMED: Number(electionsList[pos + 1]?.amount),
USD_CLAIMED: Number(electionsList[pos].usd_total),
USD_UNCLAIMED: Number(electionsList[pos + 1]?.usd_total),
election: `Election ${dataElections[pos].election + 1}`,
date: date.date_election,
EOS_CLAIMED: Number(dataElections[pos].amount),
EOS_UNCLAIMED: Number(dataElections[pos + 1]?.amount),
USD_CLAIMED: Number(dataElections[pos].usd_total),
USD_UNCLAIMED: Number(dataElections[pos + 1]?.usd_total),
EOS_TOTAL: Number(
electionsList[pos].amount + electionsList[pos + 1]?.amount
dataElections[pos].amount + dataElections[pos + 1]?.amount
),
USD_TOTAL: Number(
electionsList[pos].usd_total + electionsList[pos + 1]?.usd_total
dataElections[pos].usd_total + dataElections[pos + 1]?.usd_total
)
}
elections.push(election)
Expand Down
18 changes: 9 additions & 9 deletions webapp/src/components/BarChartReport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ const CustomTooltip = ({ payload = [], label = '', coinType = '' }) => {
{payload &&
payload.map((data, i) => (
<div key={`${i}-tooltip`}>
<div>
{i === 0 &&
data.payload?.date &&
`${
data.payload.date ? t('date', { ns: 'generalForm' }) : ''
}: ${
data.payload.date ? data.payload.date.split('T')[0] : ''
} `}
</div>
<div>
{`${t(
data.payload.category
Expand All @@ -86,15 +95,6 @@ const CustomTooltip = ({ payload = [], label = '', coinType = '' }) => {
4
)} ${coinType}`}
</div>
<div>
{i === 0 &&
data.payload?.date &&
`${
data.payload.date ? t('date', { ns: 'generalForm' }) : ''
}: ${
data.payload.date ? data.payload.date.split('T')[0] : ''
} `}
</div>
</div>
))}
</div>
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/gql/expense.gql.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export const GET_EXPENSE_BY_ELECTIONS = gql`
amount
usd_total
}
eden_historic_election {
election
date_election
}
}
`

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/hooks/customHooks/useExpenseReportState.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const useExpenseReportState = () => {
useEffect(() => {
setExpenseByElectionsList(
newDataFormatByCategorizedElectionsExpense(
expenseByElectionsData?.total_by_category_and_election || []
expenseByElectionsData || []
) || []
)
}, [expenseByElectionsData])
Expand Down
40 changes: 25 additions & 15 deletions webapp/src/utils/new-format-objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,39 +69,49 @@ export const newDataFormatByDelegatesIncome = transactionsList =>
}))

export const newDataFormatByCategorizedElectionsExpense = electionsList => {
const dataElections = electionsList?.total_by_category_and_election || []
const historicElections = electionsList?.eden_historic_election || []
const elections = []
let electionNum = 0
let usdTotal = 0
let eosTotal = 0
for (let pos = 0; pos < electionsList.length; pos++) {
if (electionsList[pos].election === electionNum) {
if (electionsList[pos].category !== 'uncategorized') {
usdTotal += electionsList[pos].usd_total
eosTotal += electionsList[pos].amount
for (let pos = 0; pos < dataElections.length; pos++) {
if (dataElections[pos].election === electionNum) {
if (dataElections[pos].category !== 'uncategorized') {
usdTotal += dataElections[pos].usd_total
eosTotal += dataElections[pos].amount
} else {
const date = historicElections.find(
element => element.election === dataElections[pos].election
)
const election = {
election: `Election ${electionsList[pos].election + 1}`,
EOS_TOTAL: Number(eosTotal + electionsList[pos].amount),
USD_TOTAL: Number(usdTotal + electionsList[pos].usd_total),
election: `Election ${dataElections[pos].election + 1}`,
date: date.date_election,
EOS_TOTAL: Number(eosTotal + dataElections[pos].amount),
USD_TOTAL: Number(usdTotal + dataElections[pos].usd_total),
EOS_CATEGORIZED: Number(eosTotal),
USD_CATEGORIZED: Number(usdTotal),
EOS_UNCATEGORIZED: Number(electionsList[pos].amount),
USD_UNCATEGORIZED: Number(electionsList[pos].usd_total)
EOS_UNCATEGORIZED: Number(dataElections[pos].amount),
USD_UNCATEGORIZED: Number(dataElections[pos].usd_total)
}
elections.push(election)
eosTotal = 0
usdTotal = 0
electionNum++
}
} else {
const date = historicElections.find(
element => element.election === dataElections[pos].election
)
const election = {
election: `Election ${electionsList[pos].electionNum + 1}`,
EOS_TOTAL: Number(eosTotal + electionsList[pos].amount),
USD_TOTAL: Number(usdTotal + electionsList[pos].usd_total),
election: `Election ${dataElections[pos].electionNum + 1}`,
date: date.date_election,
EOS_TOTAL: Number(eosTotal + dataElections[pos].amount),
USD_TOTAL: Number(usdTotal + dataElections[pos].usd_total),
EOS_CATEGORIZED: Number(eosTotal),
USD_CATEGORIZED: Number(usdTotal),
EOS_UNCATEGORIZED: Number(electionsList[pos].amount),
USD_UNCATEGORIZED: Number(electionsList[pos].usd_total)
EOS_UNCATEGORIZED: Number(dataElections[pos].amount),
USD_UNCATEGORIZED: Number(dataElections[pos].usd_total)
}
elections.push(election)
eosTotal = 0
Expand Down

0 comments on commit b83b244

Please sign in to comment.