Skip to content

Commit

Permalink
feat: api integration new analytics (#1521)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeeva Ramachandran <[email protected]>
  • Loading branch information
sagarnaikjuspay and JeevaRamu0104 authored Oct 1, 2024
1 parent de08357 commit 8f71786
Show file tree
Hide file tree
Showing 22 changed files with 443 additions and 294 deletions.
39 changes: 26 additions & 13 deletions src/container/NewAnalyticsContainer.res
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,34 @@ let make = () => {
None
}, [])

let tabs: array<Tabs.tab> = [
{
title: "Payments",
renderContent: () =>
<div className="mt-5">
<NewPaymentAnalytics />
</div>,
},
]

<div>
<PageUtils.PageHeading title="Analytics" />
<DynamicFilter
initialFilters=[]
options=[]
popupFilterFields=[]
initialFixedFilters={initialFixedFilterFields()}
defaultFilterKeys=[]
tabNames=[]
updateUrlWith=updateExistingKeys //
key="1"
filterFieldsPortalName={HSAnalyticsUtils.filterFieldsPortalName}
showCustomFilter=false
refreshFilters=false
/>
<div
className="-ml-1 sticky top-0 z-30 p-1 bg-hyperswitch_background py-1 rounded-lg border my-2">
<DynamicFilter
initialFilters=[]
options=[]
popupFilterFields=[]
initialFixedFilters={initialFixedFilterFields()}
defaultFilterKeys=[startTimeFilterKey, endTimeFilterKey]
tabNames=[]
key="0"
updateUrlWith=updateExistingKeys
filterFieldsPortalName={HSAnalyticsUtils.filterFieldsPortalName}
showCustomFilter=false
refreshFilters=false
/>
</div>
<Tabs
initialIndex={url->getPageIndex}
tabs
Expand Down
2 changes: 1 addition & 1 deletion src/libraries/FramerMotion.res
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type animate = {
y?: int,
x?: int,
opacity?: float,
backgroundPosition?: array<string>,
backgroundPosition?: string,
height?: string,
width?: string,
background?: string,
Expand Down
26 changes: 26 additions & 0 deletions src/screens/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,33 @@ let useGetURL = () => {
}
| _ => ""
}
| NEW_ANALYTICS =>
switch methodType {
| Get =>
switch id {
// Need to write seperate enum for info api
| Some(domain) =>
switch analyticsEntity {
| #Organization => `analytics/v2/org/${domain}/info`
| #Merchant => `analytics/v2/merchant/${domain}/info`
| #Profile => `analytics/v2/profile/${domain}/info`
}

| _ => ""
}
| Post =>
switch id {
| Some(domain) =>
switch analyticsEntity {
| #Organization => `analytics/v2/org/metrics/${domain}`
| #Merchant => `analytics/v2/merchant/metrics/${domain}`
| #Profile => `analytics/v2/profile/metrics/${domain}`
}

| _ => ""
}
| _ => ""
}
/* PAYOUTS ROUTING */
| PAYOUT_DEFAULT_FALLBACK => `routing/payouts/default`
| PAYOUT_ROUTING =>
Expand Down
1 change: 1 addition & 0 deletions src/screens/APIUtils/APIUtilsTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type entityName =
| ANALYTICS_REFUNDS
| ANALYTICS_AUTHENTICATION
| ANALYTICS_ACTIVE_PAYMENTS
| NEW_ANALYTICS
| API_KEYS
| ORDERS
| ORDER_FILTERS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type lineGraphOptions = {
xAxis: xAxis,
yAxis: yAxis,
plotOptions: plotOptions,
series: array<data>,
series: data,
credits: credits,
tooltip: tooltip,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ let getLineGraphOptions = (lineGraphOptions: lineGraphPayload) => {
},
},
},
series: [data],
series: data,
credits: {
enabled: false,
},
Expand Down
10 changes: 0 additions & 10 deletions src/screens/NewAnalytics/NewAnalyticsContainerUtils.res
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
open NewAnalyticsTypes

let tabs: array<Tabs.tab> = [
{
title: "Payments",
renderContent: () =>
<div className="mt-5">
<NewPaymentAnalytics />
</div>,
},
]

let getPageVariant = string => {
switch string {
| "new-analytics-payment" | _ => NewAnalyticsPayment
Expand Down
24 changes: 18 additions & 6 deletions src/screens/NewAnalytics/NewAnalyticsHelper.res
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,24 @@ module Card = {
module NoData = {
@react.component
let make = (~height="h-96") => {
<Card>
<div
className={`${height} border-2 flex justify-center items-center border-dashed opacity-70 rounded-lg p-5 m-7`}>
{"No Data"->React.string}
</div>
</Card>
<div
className={`${height} border-2 flex justify-center items-center border-dashed opacity-70 rounded-lg p-5 m-7`}>
{"No entires in selected time period."->React.string}
</div>
}
}

module Shimmer = {
@react.component
let make = (~className="w-full h-96", ~layoutId) => {
<FramerMotion.Motion.Div
className={`${className} bg-gradient-to-r from-gray-100 via-gray-200 to-gray-100`}
initial={{backgroundPosition: "-200% 0"}}
animate={{backgroundPosition: "200% 0"}}
transition={{duration: 1.5, ease: "easeInOut", repeat: 10000}}
style={{backgroundSize: "200% 100%"}}
layoutId
/>
}
}

Expand Down
16 changes: 12 additions & 4 deletions src/screens/NewAnalytics/NewAnalyticsTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ type dimension = [
| #authentication_type
]
type status = [#charged | #failure]
type metrics = [#payment_processed_amount | #payment_success_rate]
type metrics = [
| #payment_processed_amount
| #payment_count
| #payment_success_rate
| #time_bucket
| #connector
| #payment_method
| #payment_method_type
| #card_network
| #authentication_type
]
type granularity = [
| #hour_wise
| #day_wise
| #week_wise
| #G_ONEDAY
]
// will change this once we get the api srtcuture
type requestBodyConfig = {
Expand Down
33 changes: 32 additions & 1 deletion src/screens/NewAnalytics/NewAnalyticsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let fillMissingDataPoints = (

for x in 1 to endingPoint.diff(startingPoint.toString(), gap) {
let newDict = defaultValue->getDictFromJsonObject->Dict.copy
let timeVal = startingPoint.add(x, gap).endOf(gap).format("YYYY-MM-DD")
let timeVal = startingPoint.add(x, gap).endOf(gap).format("YYYY-MM-DD 00:00:00")
newDict->Dict.set(timeKey, timeVal->JSON.Encode.string)
dataPoints->Dict.set(timeVal, newDict->JSON.Encode.object)
}
Expand All @@ -34,3 +34,34 @@ let fillMissingDataPoints = (

dataPoints->Dict.valuesToArray
}

open NewAnalyticsTypes

let requestBody = (
~dimensions as _: array<dimension>,
~startTime: string,
~endTime: string,
~metrics: array<metrics>,
~groupByNames: option<array<string>>=None,
~filters as _: option<array<dimension>>=[]->Some,
~customFilter as _: option<dimension>=None,
~excludeFilterValue as _: option<array<status>>=None,
~applyFilterFor as _: option<array<status>>=None,
~delta: option<bool>=None,
~granularity: option<string>=None,
) => {
let metrics = metrics->Array.map(v => (v: metrics :> string))
let filter = Dict.make()->JSON.Encode.object->Some

[
AnalyticsUtils.getFilterRequestBody(
~metrics=Some(metrics),
~delta=delta->Option.getOr(false),
~groupByNames,
~filter,
~startDateTime=startTime,
~endDateTime=endTime,
~granularity,
)->JSON.Encode.object,
]->JSON.Encode.array
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ let make = () => {
<PaymentsProcessed
entity={paymentsProcessedEntity} chartEntity={paymentsProcessedChartEntity}
/>
<PaymentsSuccessRate
entity={paymentsSuccessRateEntity} chartEntity={paymentsSuccessRateChartEntity}
/>
<SuccessfulPaymentsDistribution
entity={successfulPaymentsDistributionEntity}
chartEntity={successfulPaymentsDistributionChartEntity}
/>
// <PaymentsSuccessRate
// entity={paymentsSuccessRateEntity} chartEntity={paymentsSuccessRateChartEntity}
// />
// <SuccessfulPaymentsDistribution
// entity={successfulPaymentsDistributionEntity}
// chartEntity={successfulPaymentsDistributionChartEntity}
// />
</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let paymentsLifeCycleChartEntity: chartEntity<
let paymentsProcessedEntity: moduleEntity = {
requestBodyConfig: {
delta: false,
metrics: [#payment_processed_amount],
metrics: [#payment_processed_amount, #payment_count],
},
title: "Payments Processed",
domain: #payments,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
open LogicUtils

let getMonthName = month => {
switch month {
| 0 => "Jan"
| 1 => "Feb"
| 2 => "Mar"
| 3 => "Apr"
| 4 => "May"
| 5 => "Jun"
| 6 => "Jul"
| 7 => "Aug"
| 8 => "Sep"
| 9 => "Oct"
| 10 => "Nov"
| 11 => "Dec"
| _ => ""
}
}

let getCategories = (json: JSON.t, key: string): array<string> => {
json
->getArrayFromJson([])
->Array.flatMap(item => {
item
->getDictFromJsonObject
->getArrayFromDict("queryData", [])
->Array.map(item => item->getDictFromJsonObject->getString(key, ""))
->Array.map(item => {
let value = item->getDictFromJsonObject->getString(key, "")

if value->LogicUtils.isNonEmptyString && key == "time_bucket" {
let dateObj = value->DayJs.getDayJsForString
`${dateObj.month()->getMonthName} ${dateObj.format("DD")}`
} else {
value
}
})
})
}

Expand Down
Loading

0 comments on commit 8f71786

Please sign in to comment.