Skip to content

Commit

Permalink
chore: Option Core changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Jan 18, 2024
1 parent 1b75528 commit fe03e31
Show file tree
Hide file tree
Showing 186 changed files with 951 additions and 1,116 deletions.
4 changes: 2 additions & 2 deletions src/components/AdvancedSearchComponent.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ let make = (
fetchApi(url, ~bodyStr=Js.Json.stringify(values), ~method_=Fetch.Post, ())
->then(Fetch.Response.json)
->then(json => {
let jsonData = json->Js.Json.decodeObject->Belt.Option.flatMap(dict => dict->Dict.get("rows"))
let jsonData = json->Js.Json.decodeObject->Option.flatMap(dict => dict->Dict.get("rows"))
let newData = switch jsonData {
| Some(actualJson) => actualJson->getObjects->Array.map(obj => obj->Js.Nullable.return)
| None => []
}

let summaryData =
json->Js.Json.decodeObject->Belt.Option.flatMap(dict => dict->Dict.get("summary"))
json->Js.Json.decodeObject->Option.flatMap(dict => dict->Dict.get("summary"))

let summary = switch summaryData {
| Some(x) => x->getSummary
Expand Down
7 changes: 3 additions & 4 deletions src/components/AdvancedSearchModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ module AdvanceSearch = {
let statusStr = getString(jsonDict, "status", "FAILURE")

if statusStr === "SUCCESS" {
let payloadDict =
jsonDict->Dict.get(detailsKey)->Belt.Option.flatMap(Js.Json.decodeObject)
let payloadDict = jsonDict->Dict.get(detailsKey)->Option.flatMap(Js.Json.decodeObject)

switch payloadDict {
| Some(dict) => {
Expand Down Expand Up @@ -90,12 +89,12 @@ module AdvanceSearch = {
}
let errors = Dict.make()
requiredSearchFieldsList->Array.forEach(key => {
if Dict.get(valuesDict, key)->Js.Option.isNone {
if Dict.get(valuesDict, key)->Option.isNone {
Dict.set(errors, key, "Required"->Js.Json.string)
}
})
let isSubmitEnabled = optionalSearchFieldsList->Array.some(key => {
Dict.get(valuesDict, key)->Js.Option.isSome
Dict.get(valuesDict, key)->Option.isSome
})

if !isSubmitEnabled {
Expand Down
4 changes: 2 additions & 2 deletions src/components/AuthWrapperUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ let useLocalStorageToken = tokenType => {
let lcToken = LocalStorage.useStorageValue("login")->getValidToken
let switchToken = LocalStorage.useStorageValue("switchToken")->getValidToken

if switchToken->Js.Option.isSome && switchToken !== Some("__failed") && tokenType !== Original {
if switchToken->Option.isSome && switchToken !== Some("__failed") && tokenType !== Original {
switchToken
} else if lcToken->Js.Option.isSome && lcToken !== Some("__failed") && tokenType !== SwitchOnly {
} else if lcToken->Option.isSome && lcToken !== Some("__failed") && tokenType !== SwitchOnly {
lcToken
} else {
None
Expand Down
20 changes: 10 additions & 10 deletions src/components/Button.res
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ let make = (
}

let buttonSize: buttonSize =
buttonSize->Belt.Option.getWithDefault(
buttonSize->Option.getWithDefault(
MatchMedia.useMatchMedia("(max-width: 800px)") ? Small : Medium,
)

Expand Down Expand Up @@ -419,7 +419,7 @@ let make = (
}
}

let heightClass = customHeightClass->Belt.Option.getWithDefault({
let heightClass = customHeightClass->Option.getWithDefault({
switch buttonSize {
| XSmall => "h-fit"
| Small => "h-fit"
Expand All @@ -433,7 +433,7 @@ let make = (
| _ => "cursor-pointer"
}

let paddingClass = customPaddingClass->Belt.Option.getWithDefault(
let paddingClass = customPaddingClass->Option.getWithDefault(
switch buttonSize {
| XSmall => "py-3 px-4"
| Small =>
Expand All @@ -447,7 +447,7 @@ let make = (
},
)

let textPaddingClass = customTextPaddingClass->Belt.Option.getWithDefault(
let textPaddingClass = customTextPaddingClass->Option.getWithDefault(
switch buttonSize {
| XSmall => "px-1"
| Small => "px-1"
Expand All @@ -456,7 +456,7 @@ let make = (
},
)

let textSize = customTextSize->Belt.Option.getWithDefault(
let textSize = customTextSize->Option.getWithDefault(
switch buttonSize {
| XSmall => "text-fs-11"
| Small => "text-fs-13"
Expand All @@ -468,7 +468,7 @@ let make = (
let ellipsisClass = ellipsisOnly ? "truncate" : ""
let ellipsisParentClass = ellipsisOnly ? "max-w-[250px] md:max-w-xs" : ""

let iconSize = customIconSize->Belt.Option.getWithDefault(
let iconSize = customIconSize->Option.getWithDefault(
switch buttonSize {
| XSmall => 12
| Small => 14
Expand All @@ -493,7 +493,7 @@ let make = (
| Large => ""
}

let iconMargin = customIconMargin->Belt.Option.getWithDefault(
let iconMargin = customIconMargin->Option.getWithDefault(
switch buttonSize {
| XSmall
| Small => "ml-1"
Expand Down Expand Up @@ -670,7 +670,7 @@ let make = (
| _ => "text-sm font-medium leading-5"
}

let textId = text->Belt.Option.getWithDefault("")
let textId = text->Option.getWithDefault("")
let iconId = switch leftIcon {
| FontAwesome(iconName)
| Euler(iconName) => iconName
Expand All @@ -692,9 +692,9 @@ let make = (
let relativeClass = isRelative ? "relative" : ""
let conditionalButtonStyles = `${allowButtonTextMinWidth
? "min-w-min"
: ""} ${customBackColor->Belt.Option.getWithDefault(
: ""} ${customBackColor->Option.getWithDefault(
backColor,
)} ${customRoundedClass->Belt.Option.getWithDefault(roundedClass)}`
)} ${customRoundedClass->Option.getWithDefault(roundedClass)}`

let newThemeGap = ""

Expand Down
8 changes: 4 additions & 4 deletions src/components/Calendar.res
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module TableRow = {
switch obj {
| Some(a) => {
let day = String.split(a, "-")
React.string(day[2]->Belt.Option.getWithDefault(""))
React.string(day[2]->Option.getWithDefault(""))
}

| None => React.string("")
Expand Down Expand Up @@ -149,11 +149,11 @@ module TableRow = {
}
let getDate = date => {
let datevalue = Js.Date.makeWithYMD(
~year=Js.Float.fromString(date[0]->Belt.Option.getWithDefault("")),
~year=Js.Float.fromString(date[0]->Option.getWithDefault("")),
~month=Js.Float.fromString(
String.make(Js.Float.fromString(date[1]->Belt.Option.getWithDefault("")) -. 1.0),
String.make(Js.Float.fromString(date[1]->Option.getWithDefault("")) -. 1.0),
),
~date=Js.Float.fromString(date[2]->Belt.Option.getWithDefault("")),
~date=Js.Float.fromString(date[2]->Option.getWithDefault("")),
(),
)
datevalue
Expand Down
2 changes: 1 addition & 1 deletion src/components/CalendarList.res
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let make = (
// check whether month and date has value
let getMonthFromFloat = value => {
let valueInt = value->Belt.Float.toInt
months[valueInt]->Belt.Option.getWithDefault(Jan)
months[valueInt]->Option.getWithDefault(Jan)
}
let getMonthInFloat = mon => {
Array.indexOf(months, mon)->Belt.Float.fromInt
Expand Down
2 changes: 1 addition & 1 deletion src/components/CollapsableTableRow.res
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ let make = (
<div className="px-3 py-4 bg-white dark:bg-jp-gray-lightgray_background">
{item
->Array.mapWithIndex((obj, index) => {
let heading = headingArray->Belt.Array.get(index)->Belt.Option.getWithDefault("")
let heading = headingArray->Belt.Array.get(index)->Option.getWithDefault("")
<UIUtils.RenderIf condition={index !== 0} key={index->string_of_int}>
<div className="flex mb-5 justify-between">
<div className="text-jp-gray-900 opacity-50 font-medium">
Expand Down
7 changes: 2 additions & 5 deletions src/components/CustomCharts/FunnelChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ let make = (
isMobileView ? (0.16, "w-full", "flex-col") : (size, "w-1/2", "flex-row")
}, [isMobileView])
let funnelData =
data
->Belt.Array.get(0)
->Belt.Option.getWithDefault(Js.Json.null)
->LogicUtils.getDictFromJsonObject
data->Belt.Array.get(0)->Option.getWithDefault(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
Expand Down Expand Up @@ -92,7 +89,7 @@ let make = (
let nextWidthRatio = switch widths->Belt.Array.get(i->Belt.Float.toInt + 1) {
| Some(width) => width
| None =>
widths->Belt.Array.get(i->Belt.Float.toInt)->Belt.Option.getWithDefault(size *. 70.)
widths->Belt.Array.get(i->Belt.Float.toInt)->Option.getWithDefault(size *. 70.)
}

fixedWidth := currentWidthRatio *. fixedWidth.contents
Expand Down
4 changes: 2 additions & 2 deletions src/components/CustomCharts/HighchartHorizontalBarChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ let xLabelFormatter: Js_OO.Callback.arity1<xAxisRecord => string> = {
| Some(series) => {
let options = series.options
switch options {
| Some(options) => options.data->Belt.Array.get(index)->Belt.Option.getWithDefault(0)
| Some(options) => options.data->Belt.Array.get(index)->Option.getWithDefault(0)
| None => 0
}
}
Expand Down Expand Up @@ -74,7 +74,7 @@ let make = (
selectedMetrics.metric_name_db,
)
}, (rawData, groupKey, selectedMetrics.metric_name_db))
let titleKey = titleKey->Belt.Option.getWithDefault(groupKey)
let titleKey = titleKey->Option.getWithDefault(groupKey)

let barOption: Js.Json.t = React.useMemo2(() => {
let colors = {
Expand Down
2 changes: 1 addition & 1 deletion src/components/CustomCharts/HighchartPieChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let make = (
let color = theme === Dark ? "white" : "black"
let borderColor = theme === Dark ? "black" : "white"
let opacity = theme === Dark ? "0.5" : "1"
let titleKey = titleKey->Belt.Option.getWithDefault(groupKey)
let titleKey = titleKey->Option.getWithDefault(groupKey)

let barOption: Js.Json.t = React.useMemo2(() => {
let colors = {
Expand Down
29 changes: 14 additions & 15 deletions src/components/CustomCharts/HighchartTimeSeriesChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ module LineChart1D = {
let (x, y, secondryMetrics) = axes
xAxisMapInfo->LineChartUtils.appendToDictValue(
["run_date", "run_month", "run_week"]->Array.includes(groupKey)
? x->Js.Json.decodeString->Belt.Option.getWithDefault("")
? x->Js.Json.decodeString->Option.getWithDefault("")
: x->Js.Json.stringify,
(
item.name,
{
item.color->Belt.Option.getWithDefault("#000000")
item.color->Option.getWithDefault("#000000")
},
y,
secondryMetrics,
Expand Down Expand Up @@ -299,7 +299,7 @@ module LineChart1D = {
}
})
->Belt.Array.get(0)
->Belt.Option.getWithDefault("")
->Option.getWithDefault("")
let color =
chartData
->Belt.Array.keepMap(item => {
Expand All @@ -309,7 +309,7 @@ module LineChart1D = {
}
})
->Belt.Array.get(0)
->Belt.Option.getWithDefault(`${colorOrig}`)
->Option.getWithDefault(`${colorOrig}`)

let transformValue = num => {
num->HSAnalyticsUtils.setPrecision()
Expand Down Expand Up @@ -611,12 +611,12 @@ module LineChart1D = {

let upper_bound =
upper_bound <= threshold
? threshold +. stepUpFromThreshold->Belt.Option.getWithDefault(0.)
? threshold +. stepUpFromThreshold->Option.getWithDefault(0.)
: upper_bound

let lower_bound =
lower_bound >= threshold
? threshold -. stepUpFromThreshold->Belt.Option.getWithDefault(0.)
? threshold -. stepUpFromThreshold->Option.getWithDefault(0.)
: lower_bound

let positions = NumericUtils.pretty([lower_bound, upper_bound], 5)
Expand Down Expand Up @@ -661,8 +661,7 @@ module LineChart1D = {
let labelsValue = {
"formatter": Some(
@this
param =>
formatLabels(selectedMetrics, param.value->Belt.Option.getWithDefault(0.0)),
param => formatLabels(selectedMetrics, param.value->Option.getWithDefault(0.0)),
),
"enabled": true,
"style": {
Expand Down Expand Up @@ -778,7 +777,7 @@ module LegendItem = {
<AddDataAttributes attributes=[("data-chart-legend", legendItem.name)]>
<div
className={`flex flex-row gap-2 justify-center items-center cursor-pointer ${opacity} select-none`}
onDoubleClick={_ => selectedRow->Belt.Option.isSome ? setSelectedRow(_ => None) : ()}
onDoubleClick={_ => selectedRow->Option.isSome ? setSelectedRow(_ => None) : ()}
onClick={_ =>
setSelectedRow(prev => {
switch prev {
Expand Down Expand Up @@ -837,7 +836,7 @@ module RenderMultiDimensionalChart = {
),
legendIndex: i.legendIndex,
name: i.name,
color: i.color->Belt.Option.getWithDefault("#000000"),
color: i.color->Option.getWithDefault("#000000"),
})
)
->ignore
Expand Down Expand Up @@ -895,8 +894,8 @@ module LineChart2D = {
) => {
let (groupBy1, groupBy2) = switch groupBy {
| Some(value) => (
value->Belt.Array.get(0)->Belt.Option.getWithDefault(""),
value->Belt.Array.get(1)->Belt.Option.getWithDefault(""),
value->Belt.Array.get(0)->Option.getWithDefault(""),
value->Belt.Array.get(1)->Option.getWithDefault(""),
)
| None => ("", "")
}
Expand Down Expand Up @@ -940,9 +939,9 @@ module LineChart3D = {
) => {
let (groupBy1, groupBy2, groupby3) = switch groupBy {
| Some(value) => (
value->Belt.Array.get(0)->Belt.Option.getWithDefault(""),
value->Belt.Array.get(1)->Belt.Option.getWithDefault(""),
value->Belt.Array.get(2)->Belt.Option.getWithDefault(""),
value->Belt.Array.get(0)->Option.getWithDefault(""),
value->Belt.Array.get(1)->Option.getWithDefault(""),
value->Belt.Array.get(2)->Option.getWithDefault(""),
)
| None => ("", "", "")
}
Expand Down
Loading

0 comments on commit fe03e31

Please sign in to comment.