Skip to content

Commit

Permalink
feat: lender stats data import updated
Browse files Browse the repository at this point in the history
  • Loading branch information
roger-in-kiva committed Aug 28, 2024
1 parent 9dd507e commit fd82793
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 53 deletions.
6 changes: 5 additions & 1 deletion src/components/LenderProfile/LenderMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export default {
type: Object,
required: true,
},
lenderStats: {
type: Object,
required: true,
},
},
data() {
return {
Expand All @@ -125,7 +129,7 @@ export default {
: 'Lending Activity by Country';
},
countriesData() {
return (this.lenderInfo?.statsPerCountry?.values ?? []).map(stat => ({
return (this.lenderStats?.statsPerCountry?.values ?? []).map(stat => ({
label: stat.country?.name ?? '',
value: stat.loanCount ?? '',
lat: stat.country?.geocode?.latitude ?? 0,
Expand Down
29 changes: 28 additions & 1 deletion src/components/LenderProfile/LenderProfileWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,21 @@
/>

<lender-stats
:lender-info="lenderInfo"
:public-id="publicId"
:lender-stats="lenderStats"
@get-lender-stats="fetchLenderStats"
/>

<lender-map
:lender-info="lenderInfo"
:lender-stats="lenderStats"
/>
</div>
</template>

<script>
import lenderStatsQuery from '@/graphql/query/lenderStats.graphql';
import logReadQueryError from '@/util/logReadQueryError';
import LenderSummary from '@/components/LenderProfile/LenderSummary';
import LenderLoansList from '@/components/LenderProfile/LenderLoansList';
import LenderStats from '@/components/LenderProfile/LenderStats';
Expand All @@ -53,6 +58,7 @@ import LenderMap from '@/components/LenderProfile/LenderMap';
export default {
name: 'LenderProfileWrapper',
inject: ['apollo', 'cookieStore'],
props: {
publicId: {
type: String,
Expand All @@ -72,6 +78,11 @@ export default {
default: () => ([]),
},
},
data() {
return {
lenderStats: {},
};
},
components: {
LenderSummary,
LenderLoansList,
Expand All @@ -82,5 +93,21 @@ export default {
LenderDedicationsList,
LenderMap,
},
methods: {
async fetchLenderStats() {
try {
const { data } = await this.apollo.query({
query: lenderStatsQuery,
variables: {
publicId: this.publicId,
},
});
this.lenderStats = data.community?.lender ?? {};
} catch (e) {
logReadQueryError(e, 'LenderStats lenderStatsQuery');
}
},
},
};
</script>
27 changes: 18 additions & 9 deletions src/components/LenderProfile/LenderStats.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<async-lender-section @visible="() => isLoading = false">
<async-lender-section @visible="$emit('get-lender-stats')">
<section class="tw-my-8">
<div v-if="isLoading">
<kv-loading-placeholder
Expand Down Expand Up @@ -35,11 +35,13 @@ import AsyncLenderSection from './AsyncLenderSection';
export default {
name: 'LenderStats',
inject: ['apollo', 'cookieStore'],
props: {
lenderInfo: {
publicId: {
type: String,
required: true,
},
lenderStats: {
type: Object,
default: () => ({}),
required: true,
},
},
Expand All @@ -66,29 +68,36 @@ export default {
},
computed: {
locationStats() {
return this.statsWithPercent((this.lenderInfo?.statsPerCountry?.values ?? []).map(stat => ({
return this.statsWithPercent((this.lenderStats?.statsPerCountry?.values ?? []).map(stat => ({
label: stat.country.name,
value: stat.loanCount,
})));
},
genderStats() {
return this.statsWithPercent((this.lenderInfo?.statsPerGender?.values ?? []).map(stat => ({
return this.statsWithPercent((this.lenderStats?.statsPerGender?.values ?? []).map(stat => ({
label: `${stat.gender.charAt(0).toUpperCase()}${stat.gender.slice(1)}`,
value: stat.loanCount,
})));
},
sectorStats() {
return this.statsWithPercent((this.lenderInfo?.statsPerSector?.values ?? []).map(stat => ({
return this.statsWithPercent((this.lenderStats?.statsPerSector?.values ?? []).map(stat => ({
label: stat.sector.name,
value: stat.loanCount,
})));
},
partnerStats() {
return this.statsWithPercent((this.lenderInfo?.statsPerPartner?.values ?? []).map(stat => ({
return this.statsWithPercent((this.lenderStats?.statsPerPartner?.values ?? []).map(stat => ({
label: stat.partner?.name ?? 'No partner',
value: stat.loanCount,
})));
},
}
},
watch: {
lenderStats() {
if (Object.keys(this.lenderStats).length !== 0) {
this.isLoading = false;
}
},
},
};
</script>
42 changes: 0 additions & 42 deletions src/graphql/query/lenderPublicProfile.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -24,48 +24,6 @@ query LenderPublicProfile ($publicId: String!) {
otherInfo
url
}
statsPerCountry {
values {
id
loanCount
country {
name
numLoansFundraising
geocode {
latitude
longitude
}
isoCode
}
}
}
statsPerGender {
values {
id
loanCount
gender
}
}
statsPerPartner {
values {
id
loanCount
partner {
id
name
}
}
}
statsPerSector {
values {
id
loanCount
sector {
id
name
}
}
}
}
}
userAchievementProgress(publicId: $publicId) {
Expand Down
49 changes: 49 additions & 0 deletions src/graphql/query/lenderStats.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
query LenderStats ($publicId: String!) {
community {
lender(publicId: $publicId) {
id
statsPerCountry {
values {
id
loanCount
country {
name
numLoansFundraising
geocode {
latitude
longitude
}
isoCode
}
}
}
statsPerGender {
values {
id
loanCount
gender
}
}
statsPerPartner {
values {
id
loanCount
partner {
id
name
}
}
}
statsPerSector {
values {
id
loanCount
sector {
id
name
}
}
}
}
}
}

0 comments on commit fd82793

Please sign in to comment.