Skip to content

Commit

Permalink
chore: new analytics bar file refactor (#1880)
Browse files Browse the repository at this point in the history
  • Loading branch information
sagarnaikjuspay authored Dec 9, 2024
1 parent 25c9d23 commit 71714a4
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 116 deletions.
1 change: 0 additions & 1 deletion src/container/NewAnalyticsContainer.res
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ let make = () => {
"YYYY-MM-DDTHH:mm:00[Z]",
)
let body = NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime=date,
~endTime=date,
~metrics=[#sessionized_payment_processed_amount],
Expand Down
83 changes: 76 additions & 7 deletions src/screens/NewAnalytics/NewAnalyticsUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,17 @@ let fillMissingDataPoints = (
}

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,
~filter: option<JSON.t>=None,
~delta: option<bool>=None,
~granularity: option<string>=None,
~distributionValues: option<JSON.t>=None,
) => {
let metrics = metrics->Array.map(v => (v: metrics :> string))
let filter = Dict.make()->JSON.Encode.object->Some

[
AnalyticsUtils.getFilterRequestBody(
Expand Down Expand Up @@ -210,3 +204,78 @@ let getMetaDataValue = (~data, ~index, ~key) => {
->getDictFromJsonObject
->getFloat(key, 0.0)
}

let getBarGraphObj = (
~array: array<JSON.t>,
~key: string,
~name: string,
~color,
): BarGraphTypes.dataObj => {
let data = array->Array.map(item => {
item->getDictFromJsonObject->getFloat(key, 0.0)
})
let dataObj: BarGraphTypes.dataObj = {
showInLegend: false,
name,
data,
color,
}
dataObj
}

let bargraphTooltipFormatter = (~title, ~metricType) => {
open BarGraphTypes

(
@this
(this: pointFormatter) => {
let title = `<div style="font-size: 16px; font-weight: bold;">${title}</div>`

let defaultValue = {color: "", x: "", y: 0.0, point: {index: 0}}
let primartPoint = this.points->getValueFromArray(0, defaultValue)

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>`
}

let tableItems =
[
getRowsHtml(~iconColor=primartPoint.color, ~date=primartPoint.x, ~value=primartPoint.y),
]->Array.joinWith("")

let content = `
<div style="
padding:5px 12px;
display:flex;
flex-direction:column;
justify-content: space-between;
gap: 7px;">
${title}
<div style="
margin-top: 5px;
display:flex;
flex-direction:column;
gap: 7px;">
${tableItems}
</div>
</div>`

`<div style="
padding: 10px;
width:fit-content;
border-radius: 7px;
background-color:#FFFFFF;
padding:10px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
border: 1px solid #E5E5E5;
position:relative;">
${content}
</div>`
}
)->asTooltipPointFormatter
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,11 @@ let make = (
)

let body = NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime=startTimeVal,
~endTime=endTimeVal,
~delta=entity.requestBodyConfig.delta,
~filters=entity.requestBodyConfig.filters,
~metrics=entity.requestBodyConfig.metrics,
~groupByNames=[groupBy.value]->Some,
~customFilter=entity.requestBodyConfig.customFilter,
~applyFilterFor=entity.requestBodyConfig.applyFilterFor,
)

let response = await updateDetails(url, body, Post)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open NewPaymentAnalyticsUtils
open FailedPaymentsDistributionTypes
open LogicUtils

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,6 @@ let getLineGraphObj = (
dataObj
}

let getBarGraphObj = (
~array: array<JSON.t>,
~key: string,
~name: string,
~color,
): BarGraphTypes.dataObj => {
let data = array->Array.map(item => {
item->getDictFromJsonObject->getFloat(key, 0.0)
})
let dataObj: BarGraphTypes.dataObj = {
showInLegend: false,
name,
data,
color,
}
dataObj
}

let getBarGraphData = (json: JSON.t, key: string, barColor: string): BarGraphTypes.data => {
json
->getArrayFromJson([])
Expand Down Expand Up @@ -183,64 +165,6 @@ let tooltipFormatter = (
)->asTooltipPointFormatter
}

let bargraphTooltipFormatter = (~title, ~metricType) => {
open BarGraphTypes
open NewAnalyticsUtils

(
@this
(this: pointFormatter) => {
let title = `<div style="font-size: 16px; font-weight: bold;">${title}</div>`

let defaultValue = {color: "", x: "", y: 0.0, point: {index: 0}}
let primartPoint = this.points->getValueFromArray(0, defaultValue)

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>`
}

let tableItems =
[
getRowsHtml(~iconColor=primartPoint.color, ~date=primartPoint.x, ~value=primartPoint.y),
]->Array.joinWith("")

let content = `
<div style="
padding:5px 12px;
display:flex;
flex-direction:column;
justify-content: space-between;
gap: 7px;">
${title}
<div style="
margin-top: 5px;
display:flex;
flex-direction:column;
gap: 7px;">
${tableItems}
</div>
</div>`

`<div style="
padding: 10px;
width:fit-content;
border-radius: 7px;
background-color:#FFFFFF;
padding:10px;
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2);
border: 1px solid #E5E5E5;
position:relative;">
${content}
</div>`
}
)->asTooltipPointFormatter
}

let getSmartRetryMetricType = isSmartRetryEnabled => {
open NewAnalyticsTypes
switch isSmartRetryEnabled {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ let defaultValue =
let getPayload = (~entity, ~metrics, ~startTime, ~endTime) => {
open NewAnalyticsTypes
NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime,
~endTime,
~delta=entity.requestBodyConfig.delta,
~filters=entity.requestBodyConfig.filters,
~metrics,
~customFilter=entity.requestBodyConfig.customFilter,
~applyFilterFor=entity.requestBodyConfig.applyFilterFor,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,26 +185,18 @@ let make = (
)

let primaryBody = NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime=startTimeVal,
~endTime=endTimeVal,
~delta=entity.requestBodyConfig.delta,
~filters=entity.requestBodyConfig.filters,
~metrics=entity.requestBodyConfig.metrics,
~customFilter=entity.requestBodyConfig.customFilter,
~applyFilterFor=entity.requestBodyConfig.applyFilterFor,
~granularity=granularity.value->Some,
)

let secondaryBody = NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime=compareToStartTime,
~endTime=compareToEndTime,
~delta=entity.requestBodyConfig.delta,
~filters=entity.requestBodyConfig.filters,
~metrics=entity.requestBodyConfig.metrics,
~customFilter=entity.requestBodyConfig.customFilter,
~applyFilterFor=entity.requestBodyConfig.applyFilterFor,
~granularity=granularity.value->Some,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,18 @@ let make = (
)

let primaryBody = NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime=startTimeVal,
~endTime=endTimeVal,
~delta=entity.requestBodyConfig.delta,
~filters=entity.requestBodyConfig.filters,
~metrics=entity.requestBodyConfig.metrics,
~customFilter=entity.requestBodyConfig.customFilter,
~applyFilterFor=entity.requestBodyConfig.applyFilterFor,
~granularity=granularity.value->Some,
)

let secondaryBody = NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime=compareToStartTime,
~endTime=compareToEndTime,
~delta=entity.requestBodyConfig.delta,
~filters=entity.requestBodyConfig.filters,
~metrics=entity.requestBodyConfig.metrics,
~customFilter=entity.requestBodyConfig.customFilter,
~applyFilterFor=entity.requestBodyConfig.applyFilterFor,
~granularity=granularity.value->Some,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,11 @@ let make = (
)

let body = NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime=startTimeVal,
~endTime=endTimeVal,
~delta=entity.requestBodyConfig.delta,
~filters=entity.requestBodyConfig.filters,
~metrics=entity.requestBodyConfig.metrics,
~groupByNames=[groupBy.value]->Some,
~customFilter=entity.requestBodyConfig.customFilter,
~applyFilterFor=entity.requestBodyConfig.applyFilterFor,
)

let response = await updateDetails(url, body, Post)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
open NewPaymentAnalyticsUtils
open SuccessfulPaymentsDistributionTypes
open LogicUtils

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ let make = (
)

let primaryBody = NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime=startTimeVal,
~endTime=endTimeVal,
~delta=entity.requestBodyConfig.delta,
Expand All @@ -172,7 +171,6 @@ let make = (
)

let secondaryBody = NewAnalyticsUtils.requestBody(
~dimensions=[],
~startTime=compareToStartTime,
~endTime=compareToEndTime,
~delta=entity.requestBodyConfig.delta,
Expand Down

0 comments on commit 71714a4

Please sign in to comment.