Skip to content

Commit

Permalink
chore: remove Belt API from codebase (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja authored Jan 30, 2024
1 parent 4038dff commit 089c051
Show file tree
Hide file tree
Showing 120 changed files with 489 additions and 570 deletions.
2 changes: 1 addition & 1 deletion src/components/Button.res
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ let make = (
~customTextPaddingClass=?,
~allowButtonTextMinWidth=true,
~badge: badge={
value: 1->Belt.Int.toString,
value: 1->Int.toString,
color: NoBadge,
},
~buttonRightText=?,
Expand Down
22 changes: 11 additions & 11 deletions src/components/Calendar.res
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module TableRow = {
)

let renderingDate = (
getDate([Belt.Float.toString(year), Belt.Float.toString(month +. 1.0), obj])
getDate([Float.toString(year), Float.toString(month +. 1.0), obj])
->Js.Date.toString
->DayJs.getDayJsForString
).format(. "YYYY-MM-DD")
Expand Down Expand Up @@ -223,8 +223,8 @@ module TableRow = {
startDate,
endDate,
obj,
Belt.Float.toString(month +. 1.0),
Belt.Float.toString(year),
Float.toString(month +. 1.0),
Float.toString(year),
)
}
let handleHover = () => {
Expand Down Expand Up @@ -313,7 +313,7 @@ let make = (
let months = [Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
let heading = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]
let isMobileView = MatchMedia.useMobileChecker()
let getMonthInFloat = mon => Array.indexOf(months, mon)->Belt.Float.fromInt
let getMonthInFloat = mon => Array.indexOf(months, mon)->Float.fromInt
let getMonthInStr = mon => {
switch mon {
| Jan => "January, "
Expand All @@ -332,7 +332,7 @@ let make = (
}
// get first day
let firstDay = Js.Date.getDay(
Js.Date.makeWithYM(~year=Belt.Int.toFloat(year), ~month=getMonthInFloat(month), ()),
Js.Date.makeWithYM(~year=Int.toFloat(year), ~month=getMonthInFloat(month), ()),
)
// get Days in month
let daysInMonth = switch month {
Expand All @@ -355,15 +355,15 @@ let make = (

let rowMapper = (row, indexRow) => {
Array.mapWithIndex(row, (_item, index) => {
let subFactor = Belt.Float.toInt(firstDay)
if indexRow == 0 && index < Belt.Float.toInt(firstDay) {
let subFactor = Float.toInt(firstDay)
if indexRow == 0 && index < Float.toInt(firstDay) {
""
} else if indexRow == 0 {
Belt.Int.toString(indexRow + (index + 1) - subFactor)
Int.toString(indexRow + (index + 1) - subFactor)
} else if indexRow * 7 + (index + 1) - subFactor > daysInMonth {
""
} else {
Belt.Int.toString(indexRow * 7 + (index + 1) - subFactor)
Int.toString(indexRow * 7 + (index + 1) - subFactor)
}
})
}
Expand All @@ -374,7 +374,7 @@ let make = (
? {
<h3 className="text-center font-bold text-lg text-gray-500 ">
{React.string(month->getMonthInStr)}
<span className="font-fira-code"> {React.string(year->Belt.Int.toString)} </span>
<span className="font-fira-code"> {React.string(year->Int.toString)} </span>
</h3>
}
: {
Expand Down Expand Up @@ -412,7 +412,7 @@ let make = (
?cellHighlighter
?cellRenderer
month={getMonthInFloat(month)}
year={Belt.Int.toFloat(year)}
year={Int.toFloat(year)}
startDate
endDate
disablePastDates
Expand Down
18 changes: 9 additions & 9 deletions src/components/CalendarList.res
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ let make = (
let _ = onDateClick
// check whether month and date has value
let getMonthFromFloat = value => {
let valueInt = value->Belt.Float.toInt
let valueInt = value->Float.toInt
months[valueInt]->Option.getOr(Jan)
}
let getMonthInFloat = mon => {
Array.indexOf(months, mon)->Belt.Float.fromInt
Array.indexOf(months, mon)->Float.fromInt
}
let getMonthInStr = mon => {
switch mon {
Expand All @@ -52,14 +52,14 @@ let make = (
}
}
let startMonth = switch month {
| Some(m) => Belt.Int.toFloat(Belt.Float.toInt(getMonthInFloat(m)))
| Some(m) => Int.toFloat(Float.toInt(getMonthInFloat(m)))
| None => {
let tMonth = Belt.Int.toFloat(Belt.Float.toInt(Js.Date.getMonth(Js.Date.make())))
let tMonth = Int.toFloat(Float.toInt(Js.Date.getMonth(Js.Date.make())))
disableFutureDates && count > 1 ? tMonth -. 1.0 : tMonth
}
}
let startYear = switch year {
| Some(y) => Belt.Int.toFloat(y)
| Some(y) => Int.toFloat(y)
| None => Js.Date.getFullYear(Js.Date.make())
}
let (currDateIm, setCurrDate) = React.useState(() =>
Expand All @@ -70,7 +70,7 @@ let make = (
let newDate = Js.Date.fromFloat(
Js.Date.setMonth(
currDateTemp,
Belt.Int.toFloat(Belt.Float.toInt(Js.Date.getMonth(currDateTemp)) + month),
Int.toFloat(Float.toInt(Js.Date.getMonth(currDateTemp)) + month),
),
)
setCurrDate(_ => newDate)
Expand All @@ -84,7 +84,7 @@ let make = (
let currDateTemp = Js.Date.fromFloat(Js.Date.valueOf(currDateIm))
let tempDate = Js.Date.setMonth(
currDateTemp,
Belt.Int.toFloat(Belt.Float.toInt(Js.Date.getMonth(currDateTemp)) + i),
Int.toFloat(Float.toInt(Js.Date.getMonth(currDateTemp)) + i),
)
let tempMonth = if disableFutureDates {
(Js.Date.fromFloat(tempDate)->DayJs.getDayJsForJsDate).toString(.)
Expand All @@ -99,7 +99,7 @@ let make = (
let showRight = i + 1 == Array.length(dummyRow) && !firstCalendar
let monthAndYear = String.concat(
getMonthInStr(getMonthFromFloat(tempMonth)),
Belt.Float.toString(tempYear),
Float.toString(tempYear),
)

let iconClass = "inline-block text-jp-gray-600 dark:text-jp-gray-text_darktheme dark:text-opacity-25 cursor-pointer"
Expand Down Expand Up @@ -142,7 +142,7 @@ let make = (
<Calendar
key={string_of_int(i)}
month={getMonthFromFloat(tempMonth)}
year={Belt.Float.toInt(tempYear)}
year={Float.toInt(tempYear)}
showTitle=false
hoverdDate
setHoverdDate
Expand Down
7 changes: 3 additions & 4 deletions src/components/CollapsableTableRow.res
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ let make = (
let borderClass = `${borderTop} border-jp-gray-500 dark:border-jp-gray-960`
let hCell = highlightCell ? "hover:font-bold" : ""
let cursorI = cellIndex == 0 ? "cursor-pointer" : ""
let location = `${title}_tr${(rowIndex + 1)->Belt.Int.toString}_td${(cellIndex + 1)
->Belt.Int.toString}`
let location = `${title}_tr${(rowIndex + 1)->Int.toString}_td${(cellIndex + 1)
->Int.toString}`
<AddDataAttributes
key={cellIndex->string_of_int} attributes=[("data-table-location", location)]>
<td
Expand All @@ -69,8 +69,7 @@ let make = (
->React.array}
</tr>
<UIUtils.RenderIf condition=isCurrentRowExpanded>
<AddDataAttributes
attributes=[("data-table-row-expanded", (rowIndex + 1)->Belt.Int.toString)]>
<AddDataAttributes attributes=[("data-table-row-expanded", (rowIndex + 1)->Int.toString)]>
<tr className="dark:border-jp-gray-dark_disable_border_color">
<td colSpan=12 className=""> {getRowDetails(rowIndex)} </td>
</tr>
Expand Down
42 changes: 20 additions & 22 deletions src/components/CustomCharts/FunnelChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ let make = (
let funnelData = data->Array.get(0)->Option.getOr(Js.Json.null)->LogicUtils.getDictFromJsonObject
let (hoverIndex, setHoverIndex) = React.useState(_ => -1.)
let (selectedMetric, setSelectedMetric) = React.useState(_ => Volume)
let length = metrics->Array.length->Belt.Float.fromInt
let length = metrics->Array.length->Float.fromInt
let widths = metrics->Array.mapWithIndex((metric, i) => {
let previousMetric = metrics->Array.get(i - 1)
let previousMetric = switch previousMetric {
| Some(prevMetric) => prevMetric.metric_name_db
| None => ""
}
let currentVol = funnelData->LogicUtils.getInt(metric.metric_name_db, 0)->Belt.Float.fromInt
let currentVol = funnelData->LogicUtils.getInt(metric.metric_name_db, 0)->Float.fromInt
let previousVol =
funnelData
->LogicUtils.getInt(previousMetric, currentVol->Belt.Float.toInt)
->Belt.Float.fromInt
funnelData->LogicUtils.getInt(previousMetric, currentVol->Float.toInt)->Float.fromInt
Js.Math.log10(currentVol *. 100. /. previousVol) /. 2.0
})

Expand Down Expand Up @@ -75,31 +73,31 @@ let make = (
<div className={`flex flex-col items-center my-auto ${widthClass}`}>
{metrics
->Array.mapWithIndex((_metric, i) => {
let i = i->Belt.Float.fromInt
let i = i->Float.fromInt
let opacity = (i +. 1.) /. length
let borderTop = `${(size *. 14.)
->Belt.Float.toString}rem solid rgb(0,109,249,${opacity->Belt.Float.toString})`
->Float.toString}rem solid rgb(0,109,249,${opacity->Float.toString})`

let currentWidthRatio = switch widths->Array.get(i->Belt.Float.toInt) {
let currentWidthRatio = switch widths->Array.get(i->Float.toInt) {
| Some(width) => width
| None => size *. 70.
}

let nextWidthRatio = switch widths->Array.get(i->Belt.Float.toInt + 1) {
let nextWidthRatio = switch widths->Array.get(i->Float.toInt + 1) {
| Some(width) => width
| None => widths->Array.get(i->Belt.Float.toInt)->Option.getOr(size *. 70.)
| None => widths->Array.get(i->Float.toInt)->Option.getOr(size *. 70.)
}

fixedWidth := currentWidthRatio *. fixedWidth.contents
let borderXFloat = (1. -. nextWidthRatio) *. fixedWidth.contents /. 2.
let borderX = `${borderXFloat->Belt.Float.toString}rem solid transparent`
let borderX = `${borderXFloat->Float.toString}rem solid transparent`

let width = `${fixedWidth.contents->Belt.Float.toString}rem`
let width = `${fixedWidth.contents->Float.toString}rem`

let marginBottom = `${(size *. 1.4)->Belt.Float.toString}rem`
let marginBottom = `${(size *. 1.4)->Float.toString}rem`
let funnelElement =
<div
key={`${i->Belt.Float.toString}funnelStage`}
key={`${i->Float.toString}funnelStage`}
className="flex hover:cursor-pointer transition ease-in-out hover:scale-110 duration-300"
style={ReactDOMStyle.make(
~borderTop,
Expand All @@ -122,9 +120,9 @@ let make = (
open LogicUtils
metrics
->Array.mapWithIndex((metric, i) => {
let marginBottom = `${(size *. 1.4)->Belt.Float.toString}rem`
let paddingTop = `${(size *. 4.2)->Belt.Float.toString}rem`
let metricVal = funnelData->getInt(metric.metric_name_db, 0)->Belt.Float.fromInt
let marginBottom = `${(size *. 1.4)->Float.toString}rem`
let paddingTop = `${(size *. 4.2)->Float.toString}rem`
let metricVal = funnelData->getInt(metric.metric_name_db, 0)->Float.fromInt
let prevMetricVolume = switch prevMetricVol.contents {
| Some(vol) => vol
| None => metricVal
Expand All @@ -136,7 +134,7 @@ let make = (
}

<div
key={`${i->Belt.Int.toString}funnelStageVol`}
key={`${i->Int.toString}funnelStageVol`}
className={`flex flex-row gap-4 h-full items-center w-max`}
style={ReactDOMStyle.make(~marginBottom, ~paddingTop, ())}>
<div
Expand All @@ -157,15 +155,15 @@ let make = (
<div className="flex flex-col items-start">
{metrics
->Array.mapWithIndex((metric, i) => {
let marginBottom = `${(size *. 2.1)->Belt.Float.toString}rem`
let paddingTop = `${(size *. 3.4 *. 1.4)->Belt.Float.toString}rem`
let marginBottom = `${(size *. 2.1)->Float.toString}rem`
let paddingTop = `${(size *. 3.4 *. 1.4)->Float.toString}rem`
<div
key={`${i->Belt.Int.toString}funnelStageDesc`}
key={`${i->Int.toString}funnelStageDesc`}
className={`flex flex-row gap-4 h-full items-center w-max items-start`}
style={ReactDOMStyle.make(~marginBottom, ~paddingTop, ())}>
<div
className={`transition ease-in-out duration-300 font-medium text-base ${hoverIndex ===
i->Belt.Float.fromInt
i->Float.fromInt
? "text-blue-900 scale-110"
: "text-jp-gray-800 dark:text-dark_theme"}`}>
{metric.metric_label->React.string}
Expand Down
8 changes: 4 additions & 4 deletions src/components/CustomCharts/HighchartHorizontalBarChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ let xLabelFormatter: Js_OO.Callback.arity1<xAxisRecord => string> = {
| None => 0
}
`<div style="display: inline-block; margin-left: 10px;" class="text-black dark:text-white"><div class="font-semibold"> ${value} </div><div class="font-medium" style="display: inline-block;">` ++
(y->Belt.Float.fromInt *. 100. /. seriesSum->Belt.Float.fromInt)
(y->Float.fromInt *. 100. /. seriesSum->Float.fromInt)
->Js.Float.toFixedWithPrecision(~digits=2) ++ `%</div></div>`
}
}
Expand All @@ -78,11 +78,11 @@ let make = (

let barOption: Js.Json.t = React.useMemo2(() => {
let colors = {
let length = barChartData->Array.length->Belt.Int.toFloat
let length = barChartData->Array.length->Int.toFloat
barChartData->Array.mapWithIndex((_data, i) => {
let i = i->Belt.Int.toFloat
let i = i->Int.toFloat
let opacity = (length -. i +. 1.) /. (length +. 1.)
`rgb(0,109,249,${opacity->Belt.Float.toString})`
`rgb(0,109,249,${opacity->Float.toString})`
})
}
let defaultOptions: HighchartsHorizontalBarChart.options = {
Expand Down
6 changes: 3 additions & 3 deletions src/components/CustomCharts/HighchartPieChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ let make = (

let barOption: Js.Json.t = React.useMemo2(() => {
let colors = {
let length = pieSeriesData->Array.length->Belt.Int.toFloat
let length = pieSeriesData->Array.length->Int.toFloat
pieSeriesData->Array.mapWithIndex((_data, i) => {
let i = i->Belt.Int.toFloat
let i = i->Int.toFloat
let opacity = (length -. i +. 1.) /. (length +. 1.)
`rgb(0,109,249,${opacity->Belt.Float.toString})`
`rgb(0,109,249,${opacity->Float.toString})`
})
}
let defaultOptions: HighchartsPieChart.options = {
Expand Down
12 changes: 6 additions & 6 deletions src/components/CustomCharts/HighchartTimeSeriesChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,19 @@ module LineChart1D = {
->Js.Date.fromFloat
->DateTimeUtils.toUtc
->Js.Date.getHours
->Belt.Float.toString}:00`
->Float.toString}:00`
->String.sliceToEnd(~start=-5)
->Js.Json.string
} else if "run_month" === groupKey {
xAxis
->Js.Date.fromFloat
->DateTimeUtils.toUtc
->Js.Date.getDate
->Belt.Float.toString
->Float.toString
->Js.Json.string
} else if "run_week" === groupKey {
switch DateTimeUtils.daysArr[
xAxis->Js.Date.fromFloat->DateTimeUtils.toUtc->Js.Date.getDay->Belt.Float.toInt
xAxis->Js.Date.fromFloat->DateTimeUtils.toUtc->Js.Date.getDay->Float.toInt
] {
| Some(ele) => DateTimeUtils.dayMapper(ele)
| None => ""
Expand Down Expand Up @@ -622,7 +622,7 @@ module LineChart1D = {
let positions = NumericUtils.pretty([lower_bound, upper_bound], 5)

let positionArr =
Belt.Array.concat(positions, [threshold])->Js.Array2.sortInPlaceWith(
Array.concat(positions, [threshold])->Js.Array2.sortInPlaceWith(
numericArraySortComperator,
)
positionArr
Expand Down Expand Up @@ -801,7 +801,7 @@ module LegendItem = {

module RenderMultiDimensionalChart = {
type config = {
chartDictData: Dict.t<Belt.Array.t<Js.Json.t>>,
chartDictData: Dict.t<Js.Array.t<Js.Json.t>>,
class: string,
selectedMetrics: LineChartUtils.metricsConfig,
groupBy: string,
Expand Down Expand Up @@ -853,7 +853,7 @@ module RenderMultiDimensionalChart = {
let (key, value) = item

<LineChart1D
key={index->Belt.Int.toString}
key={index->Int.toString}
class=config.class
rawChartData=value
commonColorsArr={LineChartUtils.removeDuplicates(chartNames)}
Expand Down
Loading

0 comments on commit 089c051

Please sign in to comment.