Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: analytics revamp bug fixes #1703

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type yAxis = {
gridLineColor: gridLineColor,
gridLineDashStyle: gridLineDashStyle,
min: min,
max?: option<int>,
}

type xAxis = {
Expand Down Expand Up @@ -115,5 +116,6 @@ type lineGraphPayload = {
categories: categories,
data: data,
title: title,
yAxisMaxValue: option<int>,
tooltipFormatter: pointFormatter => string,
}
22 changes: 16 additions & 6 deletions src/screens/NewAnalytics/Graphs/LineGraph/LineGraphUtils.res
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
open LineGraphTypes

let getLineGraphOptions = (lineGraphOptions: lineGraphPayload) => {
let {categories, data, title, tooltipFormatter} = lineGraphOptions
let {categories, data, title, tooltipFormatter, yAxisMaxValue} = lineGraphOptions

let stepInterval = Js.Math.max_int(
Js.Math.ceil_int(categories->Array.length->Int.toFloat /. 20.0),
1,
)

let yAxis: LineGraphTypes.yAxis = {
title,
gridLineWidth: 1,
gridLineColor: "#e6e6e6",
gridLineDashStyle: "Dash",
min: 0,
}

{
chart: {
\"type": "line",
Expand Down Expand Up @@ -52,11 +60,13 @@ let getLineGraphOptions = (lineGraphOptions: lineGraphPayload) => {
shared: true, // Allows multiple series' data to be shown in a single tooltip
},
yAxis: {
title,
gridLineWidth: 1,
gridLineColor: "#e6e6e6",
gridLineDashStyle: "Dash",
min: 0,
switch yAxisMaxValue {
| Some(val) => {
...yAxis,
max: val->Some,
}
| _ => yAxis
}
},
plotOptions: {
line: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let getCategories = (data: JSON.t, index: int, key: string) => {
->getValueFromArray(index, []->JSON.Encode.array)
->getArrayFromJson([])
->Array.map(item => {
let value = item->getDictFromJsonObject->getString(key, "")
let value = item->getDictFromJsonObject->getString(key, "NA")

if value->isNonEmptyString && key == "time_bucket" {
let dateObj = value->DayJs.getDayJsForString
Expand Down Expand Up @@ -142,12 +142,15 @@ let tooltipFormatter = (
let primartPoint = this.points->getValueFromArray(0, defaultValue)
let secondaryPoint = this.points->getValueFromArray(1, defaultValue)

// TODO:Currency need to be picked from filter
let suffix = metricType == NewAnalyticsTypes.Amount ? "USD" : ""

let getRowsHtml = (~iconColor, ~date, ~value, ~comparisionComponent="") => {
let valueString = valueFormatter(value, metricType)
`<div style="display: flex; align-items: center;">
<div style="width: 10px; height: 10px; background-color:${iconColor}; border-radius:3px;"></div>
<div style="margin-left: 8px;">${date}${comparisionComponent}</div>
<div style="flex: 1; text-align: right; font-weight: bold;margin-left: 25px;">${valueString}</div>
<div style="flex: 1; text-align: right; font-weight: bold;margin-left: 25px;">${valueString} ${suffix}</div>
</div>`
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module SmartRetryCard = {
<img alt="connector-list" className="h-20 w-fit" src="/assets/smart-retry.svg" />
<div className="flex gap-1 items-center">
<div className="font-semibold text-2xl dark:text-white">
{`Saved ${valueFormatter(primaryValue, config.valueType)}`->React.string}
{`Saved ${valueFormatter(primaryValue, config.valueType)} USD`->React.string} // TODO:Currency need to be picked from filter
</div>
<div className="scale-[0.9]">
<RenderIf condition={comparison === EnableComparison}>
Expand Down Expand Up @@ -57,7 +57,12 @@ module OverViewStat = {
<div className="flex justify-between w-full items-end">
<div className="flex gap-1 items-center">
<div className="font-bold text-3xl">
{valueFormatter(primaryValue, config.valueType)->React.string}
{
let value = valueFormatter(primaryValue, config.valueType)
let suffix = config.valueType == Amount ? "USD" : ""

`${value} ${suffix}`->React.string
}
</div>
<div className="scale-[0.9]">
<RenderIf condition={comparison === EnableComparison}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ type overviewColumns =
| Total_Dispute

type dataObj = {
total_smart_retried_amount_usd: float,
total_smart_retried_amount_without_smart_retries_usd: float,
total_smart_retried_amount_in_usd: float,
total_smart_retried_amount_without_smart_retries_in_usd: float,
total_success_rate: float,
total_success_rate_without_smart_retries: float,
total_payment_processed_amount_usd: float,
total_payment_processed_amount_in_usd: float,
total_payment_processed_count: int,
total_payment_processed_amount_without_smart_retries_usd: float,
total_payment_processed_amount_without_smart_retries_in_usd: float,
total_payment_processed_count_without_smart_retries: int,
refund_processed_amount: float,
total_dispute: int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@ open NewPaymentsOverviewSectionTypes

let getStringFromVariant = value => {
switch value {
| Total_Smart_Retried_Amount => "total_smart_retried_amount_usd"
| Total_Smart_Retried_Amount_Without_Smart_Retries => "total_smart_retried_amount_without_smart_retries_usd"
| Total_Smart_Retried_Amount => "total_smart_retried_amount_in_usd"
| Total_Smart_Retried_Amount_Without_Smart_Retries => "total_smart_retried_amount_without_smart_retries_in_usd"
| Total_Success_Rate => "total_success_rate"
| Total_Success_Rate_Without_Smart_Retries => "total_success_rate_without_smart_retries"
| Total_Payment_Processed_Amount => "total_payment_processed_amount_usd"
| Total_Payment_Processed_Amount_Without_Smart_Retries => "total_payment_processed_amount_without_smart_retries_usd"
| Total_Payment_Processed_Amount => "total_payment_processed_amount_in_usd"
| Total_Payment_Processed_Amount_Without_Smart_Retries => "total_payment_processed_amount_without_smart_retries_in_usd"
| Refund_Processed_Amount => "refund_processed_amount"
| Total_Dispute => "total_dispute"
}
}

let defaultValue =
{
total_smart_retried_amount_usd: 0.0,
total_smart_retried_amount_without_smart_retries_usd: 0.0,
total_smart_retried_amount_in_usd: 0.0,
total_smart_retried_amount_without_smart_retries_in_usd: 0.0,
total_success_rate: 0.0,
total_success_rate_without_smart_retries: 0.0,
total_payment_processed_amount_usd: 0.0,
total_payment_processed_amount_in_usd: 0.0,
total_payment_processed_count: 0,
total_payment_processed_amount_without_smart_retries_usd: 0.0,
total_payment_processed_amount_without_smart_retries_in_usd: 0.0,
total_payment_processed_count_without_smart_retries: 0,
refund_processed_amount: 0.0,
total_dispute: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ module PaymentsProcessedHeader = {
<div className="w-full px-7 py-8 grid grid-cols-1">
<div className="flex gap-2 items-center">
<div className="text-3xl font-600">
{primaryValue->valueFormatter(Amount)->React.string}
{`${primaryValue->valueFormatter(Amount)} USD`->React.string} // TODO:Currency need to be picked from filter
</div>
<RenderIf condition={comparison == EnableComparison}>
<StatisticsCard value direction />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ type paymentsProcessedCols =
| Time_Bucket

type paymentsProcessedObject = {
payment_processed_amount_usd: float,
payment_processed_amount_in_usd: float,
payment_processed_count: int,
payment_processed_amount_without_smart_retries_usd: float,
payment_processed_amount_without_smart_retries_in_usd: float,
payment_processed_count_without_smart_retries: int,
total_payment_processed_amount_usd: float,
total_payment_processed_amount_in_usd: float,
total_payment_processed_count: int,
total_payment_processed_amount_without_smart_retries_usd: float,
total_payment_processed_amount_without_smart_retries_in_usd: float,
total_payment_processed_count_without_smart_retries: int,
time_bucket: string,
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ open LogicUtils

let getStringFromVariant = value => {
switch value {
| Payment_Processed_Amount => "payment_processed_amount_usd"
| Payment_Processed_Amount => "payment_processed_amount_in_usd"
| Payment_Processed_Count => "payment_processed_count"
| Payment_Processed_Amount_Without_Smart_Retries => "payment_processed_amount_without_smart_retries_usd"
| Payment_Processed_Amount_Without_Smart_Retries => "payment_processed_amount_without_smart_retries_in_usd"
| Payment_Processed_Count_Without_Smart_Retries => "payment_processed_count_without_smart_retries"
| Total_Payment_Processed_Amount => "total_payment_processed_amount_usd"
| Total_Payment_Processed_Amount => "total_payment_processed_amount_in_usd"
| Total_Payment_Processed_Count => "total_payment_processed_count"
| Total_Payment_Processed_Amount_Without_Smart_Retries => "total_payment_processed_amount_without_smart_retries_usd"
| Total_Payment_Processed_Amount_Without_Smart_Retries => "total_payment_processed_amount_without_smart_retries_in_usd"
| Total_Payment_Processed_Count_Without_Smart_Retriess => "total_payment_processed_count_without_smart_retries"
| Time_Bucket => "time_bucket"
}
}

let getVariantValueFromString = value => {
switch value {
| "payment_processed_amount_usd" => Payment_Processed_Amount
| "payment_processed_amount_in_usd" => Payment_Processed_Amount
| "payment_processed_count" => Payment_Processed_Count
| "payment_processed_amount_without_smart_retries_usd" =>
| "payment_processed_amount_without_smart_retries_in_usd" =>
Payment_Processed_Amount_Without_Smart_Retries
| "payment_processed_count_without_smart_retries" => Payment_Processed_Count_Without_Smart_Retries
| "total_payment_processed_amount_usd" => Total_Payment_Processed_Amount
| "total_payment_processed_amount_in_usd" => Total_Payment_Processed_Amount
| "total_payment_processed_count" => Total_Payment_Processed_Count
| "total_payment_processed_amount_without_smart_retries_usd" =>
| "total_payment_processed_amount_without_smart_retries_in_usd" =>
Total_Payment_Processed_Amount_Without_Smart_Retries
| "total_payment_processed_count_without_smart_retries" =>
Total_Payment_Processed_Count_Without_Smart_Retriess
Expand Down Expand Up @@ -76,6 +76,7 @@ let paymentsProcessedMapper = (
categories: primaryCategories,
data: lineGraphData,
title,
yAxisMaxValue: None,
tooltipFormatter: tooltipFormatter(
~secondaryCategories,
~title="Payments Processed",
Expand All @@ -98,25 +99,25 @@ let visibleColumns = [Time_Bucket]

let tableItemToObjMapper: Dict.t<JSON.t> => paymentsProcessedObject = dict => {
{
payment_processed_amount_usd: dict->getAmountValue(
payment_processed_amount_in_usd: dict->getAmountValue(
~id=Payment_Processed_Amount->getStringFromVariant,
),
payment_processed_count: dict->getInt(Payment_Processed_Count->getStringFromVariant, 0),
payment_processed_amount_without_smart_retries_usd: dict->getAmountValue(
payment_processed_amount_without_smart_retries_in_usd: dict->getAmountValue(
~id=Payment_Processed_Amount_Without_Smart_Retries->getStringFromVariant,
),
payment_processed_count_without_smart_retries: dict->getInt(
Payment_Processed_Count_Without_Smart_Retries->getStringFromVariant,
0,
),
total_payment_processed_amount_usd: dict->getAmountValue(
total_payment_processed_amount_in_usd: dict->getAmountValue(
~id=Total_Payment_Processed_Amount->getStringFromVariant,
),
total_payment_processed_count: dict->getInt(
Total_Payment_Processed_Count->getStringFromVariant,
0,
),
total_payment_processed_amount_without_smart_retries_usd: dict->getAmountValue(
total_payment_processed_amount_without_smart_retries_in_usd: dict->getAmountValue(
~id=Total_Payment_Processed_Amount_Without_Smart_Retries->getStringFromVariant,
),
total_payment_processed_count_without_smart_retries: dict->getInt(
Expand Down Expand Up @@ -175,9 +176,9 @@ let getHeading = colType => {
let getCell = (obj, colType): Table.cell => {
open NewAnalyticsUtils
switch colType {
| Payment_Processed_Amount => Text(obj.payment_processed_amount_usd->valueFormatter(Amount))
| Payment_Processed_Amount => Text(obj.payment_processed_amount_in_usd->valueFormatter(Amount))
| Payment_Processed_Amount_Without_Smart_Retries =>
Text(obj.payment_processed_amount_without_smart_retries_usd->valueFormatter(Amount))
Text(obj.payment_processed_amount_without_smart_retries_in_usd->valueFormatter(Amount))
| Payment_Processed_Count => Text(obj.payment_processed_count->Int.toString)
| Payment_Processed_Count_Without_Smart_Retries =>
Text(obj.payment_processed_count_without_smart_retries->Int.toString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ let paymentsSuccessRateMapper = (
categories: primaryCategories,
data: lineGraphData,
title,
yAxisMaxValue: 100->Some,
tooltipFormatter: tooltipFormatter(
~secondaryCategories,
~title="Payments Success Rate",
Expand Down
Loading