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

refactor: Common file for all identity functions #86

Merged
merged 3 commits into from
Dec 11, 2023
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 @@ -25,7 +25,7 @@ let make = (
endDateArr->Belt.Array.get(i)->Belt.Option.getWithDefault(x),
))

input.onChange(newArr->NestedDropdown.formToArray)
input.onChange(newArr->Identity.anyTypeToReactEvent)
}

let showCalendars = React.useMemo1(() => {
Expand Down
9 changes: 4 additions & 5 deletions src/components/Base64ImageInputWithDnD.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
external toReactEvent: 'a => ReactEvent.Form.t = "%identity"
external strToDomImg: string => Webapi.Dom.Image.t = "%identity"
@send external drawImage: (Webapi.Canvas.Canvas2d.t, 'a, int, int) => unit = "drawImage"
@send external toDataURL: 'a => string = "toDataURL"
Expand Down Expand Up @@ -57,7 +56,7 @@ let make = (
)
let clearImage = _evt => {
setFilename(_ => "")
input.onChange(""->toReactEvent)
input.onChange(""->Identity.stringToFormReactEvent)
}
let onChange = evt => {
let target = ReactEvent.Form.target(evt)
Expand All @@ -76,7 +75,7 @@ let make = (
let target = ReactEvent.Form.target(e)
let data = target["result"]
setIsNewUpload(_ => true)
input.onChange(toReactEvent(data))
input.onChange(data->Identity.anyTypeToReactEvent)
}
}
}
Expand Down Expand Up @@ -106,7 +105,7 @@ let make = (
context->drawImage(img, 0, 0)
toDataURL(canvas)
}
input.onChange(a->toReactEvent)
input.onChange(a->Identity.stringToFormReactEvent)
}
<div
onDragOver={ev => {
Expand All @@ -129,7 +128,7 @@ let make = (
let target = ReactEvent.Form.target(e)
let data = target["result"]
setIsNewUpload(_ => true)
input.onChange(toReactEvent(data))
input.onChange(data->Identity.anyTypeToReactEvent)
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/components/BreadCrumb.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
external jsonToarr: Js.Json.t => array<'a> = "%identity"

type status = Active | Disabled | Completed

type breadCrumb_options = {
Expand Down
3 changes: 1 addition & 2 deletions src/components/CsvFileUpload.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
external toReactEvent: 'a => ReactEvent.Form.t = "%identity"
type t

type formData
Expand Down Expand Up @@ -28,7 +27,7 @@ let make = (
setFilenameVal(_ => "")
onFileUpload(None)

input.onChange(""->toReactEvent)
input.onChange(""->Identity.stringToFormReactEvent)
}

let onChange = evt => {
Expand Down
15 changes: 6 additions & 9 deletions src/components/CsvInputField.res
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
external toReactEvent: 'a => ReactEvent.Form.t = "%identity"
external jsonToarr: Js.Json.t => array<'a> = "%identity"
external arrToReactEvent: array<string> => ReactEvent.Form.t = "%identity"
external strToReactEvent: string => ReactEvent.Form.t = "%identity"

module FilenameSaver = {
@react.component
let make = (~input: ReactFinalForm.fieldRenderPropsInput, ~fileName) => {
React.useEffect1(() => {
let reactEvFilename = fileName->toReactEvent
let reactEvFilename = fileName->Identity.anyTypeToReactEvent
input.onChange(reactEvFilename)
None
}, [fileName])
Expand Down Expand Up @@ -110,12 +107,12 @@ let make = (
let clearCsv = _evt => {
setFilename(_ => "")
setKey(pre => pre + 1)
input.onChange(arrToReactEvent([]))
input.onChange(Identity.arrofStringToReactEvent([]))
}
let clearData = _ev => {
setFilename(_ => "")
setKey(pre => pre + 1)
input.onChange(strToReactEvent(""))
input.onChange(Identity.stringToFormReactEvent(""))
}

let toast = (message, toastType) => {
Expand Down Expand Up @@ -164,7 +161,7 @@ let make = (
})

if errorLines->Js.Array2.length === 0 {
input.onChange(toReactEvent(res))
input.onChange(res->Identity.anyTypeToReactEvent)
toast("File Uploaded Successfully", ToastSuccess)
}

Expand All @@ -175,7 +172,7 @@ let make = (
}

| None => {
input.onChange(toReactEvent(res))
input.onChange(res->Identity.anyTypeToReactEvent)
toast("File Uploaded Successfully", ToastSuccess)
}
}
Expand All @@ -188,7 +185,7 @@ let make = (
}
| _ =>
setIsNewUpload(_ => true)
input.onChange(toReactEvent(csv))
input.onChange(csv->Identity.anyTypeToReactEvent)
toast("File Uploaded Successfully", ToastSuccess)
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/components/DateOnlySelector.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
external strToForm: string => ReactEvent.Form.t = "%identity"
module DateCalendar = {
open Calendar
@react.component
Expand Down Expand Up @@ -55,7 +54,7 @@ let make = (~input: ReactFinalForm.fieldRenderPropsInput) => {
let currentDateSplit = Js.String2.split(str, "-")
let currentDateDay = currentDateSplit[2]->Belt.Option.getWithDefault("")
setSelectedDate(_ => currentDateDay)
input.onChange(currentDateDay->strToForm)
input.onChange(currentDateDay->Identity.stringToFormReactEvent)
}
OutsideClick.useOutsideClick(
~refs=ArrayOfRef([dropdownRef]),
Expand Down
9 changes: 4 additions & 5 deletions src/components/DatePicker.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
external strToForm: string => ReactEvent.Form.t = "%identity"
external jsonToForm: Js.Json.t => ReactEvent.Form.t = "%identity"
external formEvAsString: ReactEvent.Form.t => string = "%identity"

@react.component
let make = (
~input: ReactFinalForm.fieldRenderPropsInput,
Expand Down Expand Up @@ -92,7 +91,7 @@ let make = (
currentDateSecondsFormat,
)
setDate(_ => currentDateTimeCheck)
input.onChange(currentDateTimeCheck->strToForm)
input.onChange(currentDateTimeCheck->Identity.stringToFormReactEvent)
}
React.useEffect1(() => {
if input.value == ""->Js.Json.string {
Expand Down Expand Up @@ -167,7 +166,7 @@ let make = (
name: "string",
onBlur: _ev => (),
onChange: timeValEv => {
let timeVal = timeValEv->formEvAsString
let timeVal = timeValEv->Identity.formReactEventToString
if selectedDate !== "" {
let todayDayJsObj = Js.Date.make()->Js.Date.toString->DayJs.getDayJsForString
let todayTime = todayDayJsObj.format(. "HH:mm:ss")
Expand Down Expand Up @@ -198,7 +197,7 @@ let make = (
)
let timestamp = TimeZoneHook.formattedISOString(dateTimeCheck, format)
setDate(_ => timestamp)
input.onChange(timestamp->Table.dateFormat(format)->strToForm)
input.onChange(timestamp->Table.dateFormat(format)->Identity.stringToFormReactEvent)
}
},
onFocus: _ev => (),
Expand Down
15 changes: 5 additions & 10 deletions src/components/DateRangePicker.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
external strToForm: string => ReactEvent.Form.t = "%identity"
external formEvAsString: ReactEvent.Form.t => string = "%identity"

let defaultCellHighlighter = (_): Calendar.highlighter => {
{
highlightSelf: false,
Expand Down Expand Up @@ -277,7 +274,7 @@ module Base = {
setStartDateVal(_ => localStartDate)
setEndDateVal(_ => localEndDate)
switch optInput {
| Some(ip) => ip.onChange(localOpt->strToForm)
| Some(ip) => ip.onChange(localOpt->Identity.stringToFormReactEvent)
| None => ()
}
}
Expand Down Expand Up @@ -418,7 +415,7 @@ module Base = {
setIsDropdownExpanded(_ => false)
saveDates()
switch optInput {
| Some(ip) => ip.onChange("custom_range"->strToForm)
| Some(ip) => ip.onChange("custom_range"->Identity.stringToFormReactEvent)
| None => ()
}
}
Expand Down Expand Up @@ -458,7 +455,7 @@ module Base = {
name: "string",
onBlur: _ev => (),
onChange: timeValEv => {
let startTimeVal = timeValEv->formEvAsString
let startTimeVal = timeValEv->Identity.formReactEventToString
let endTime = localEndDate->getTimeStringForValue(isoStringToCustomTimeZone)

if localStartDate !== "" {
Expand All @@ -481,7 +478,7 @@ module Base = {
name: "string",
onBlur: _ev => (),
onChange: timeValEv => {
let endTimeVal = timeValEv->formEvAsString
let endTimeVal = timeValEv->Identity.formReactEventToString
let startTime = localStartDate->getTimeStringForValue(isoStringToCustomTimeZone)
if localEndDate !== "" {
if disableFutureDates && selectedEndDate == todayDate && endTimeVal > todayTime {
Expand Down Expand Up @@ -885,14 +882,12 @@ module Base = {
}
}

external asFormEvent: string => ReactEvent.Form.t = "%identity"

let useStateForInput = (input: ReactFinalForm.fieldRenderPropsInput) => {
React.useMemo1(() => {
let val = input.value->Js.Json.decodeString->Belt.Option.getWithDefault("")
let onChange = fn => {
let newVal = fn(val)
input.onChange(newVal->asFormEvent)
input.onChange(newVal->Identity.stringToFormReactEvent)
}

(val, onChange)
Expand Down
3 changes: 1 addition & 2 deletions src/components/DistributionDonut/DistributionDonut.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
external objToJson: {..} => Js.Json.t = "%identity"
external formEventToStr: ReactEvent.Form.t => string = "%identity"

type dataPoint = {y: int, name: string}

Expand Down Expand Up @@ -160,7 +159,7 @@ let make = (
let filterInput: ReactFinalForm.fieldRenderPropsInput = {
name: "Get By",
onBlur: _ev => (),
onChange: ev => {setGroupBy(_ => ev->formEventToStr)},
onChange: ev => {setGroupBy(_ => ev->Identity.formReactEventToString)},
onFocus: _ev => (),
value: groupBy->Js.Json.string,
checked: true,
Expand Down
4 changes: 1 addition & 3 deletions src/components/DraggableFilter.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ type rec options = {
options: option<array<options>>,
}

external formToArray: 'a => ReactEvent.Form.t = "%identity"

module TypeText = {
@react.component
let make = () => {
Expand Down Expand Up @@ -429,7 +427,7 @@ let make = (
}

React.useEffect1(() => {
input.onChange(dataSelectedBase->formToArray)
input.onChange(dataSelectedBase->Identity.anyTypeToReactEvent)
None
}, [dataSelectedBase])
let keyExtractor = (index, data, isDragging) => {
Expand Down
15 changes: 9 additions & 6 deletions src/components/DynamicChart.res
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,6 @@ let useChartFetch = (~setStatusDict) => {
fetchChartData
}

external formEventToStr: ReactEvent.Form.t => string = "%identity"
external tofloat: string => float = "%identity"

let granularityMapper = (granularity: granularity) => {
switch granularity {
| G_ONEDAY => "G_ONEDAY"
Expand Down Expand Up @@ -862,7 +859,9 @@ let make = (
let _inputChart: ReactFinalForm.fieldRenderPropsInput = {
name: "inputChart",
onChange: ev => {
updateChartCompFilters(Js.Dict.fromArray([("chartType", ev->formEventToStr)]))
updateChartCompFilters(
Js.Dict.fromArray([("chartType", ev->Identity.formReactEventToString)]),
)
},
value: chartTypeFromUrl->Js.Json.string,
onBlur: _ev => (),
Expand All @@ -872,7 +871,9 @@ let make = (
let inputMetricTop: ReactFinalForm.fieldRenderPropsInput = {
name: "inputMetricTop",
onChange: ev => {
updateChartCompFilters(Js.Dict.fromArray([("chartTopMetric", ev->formEventToStr)]))
updateChartCompFilters(
Js.Dict.fromArray([("chartTopMetric", ev->Identity.formReactEventToString)]),
)
},
value: chartTopMetricFromUrl->Js.Json.string,
onBlur: _ev => (),
Expand All @@ -882,7 +883,9 @@ let make = (
let inputMetricBottom: ReactFinalForm.fieldRenderPropsInput = {
name: "inputMetricBottom",
onChange: ev => {
updateChartCompFilters(Js.Dict.fromArray([("chartBottomMetric", ev->formEventToStr)]))
updateChartCompFilters(
Js.Dict.fromArray([("chartBottomMetric", ev->Identity.formReactEventToString)]),
)
},
value: chartBottomMetricFromUrl->Js.Json.string,
onBlur: _ev => (),
Expand Down
1 change: 0 additions & 1 deletion src/components/DynamicTabs.res
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ module TabInfo = {
}
}

external syntheticEventAsStr: ReactEvent.Form.t => string = "%identity"
module IndicationArrow = {
@react.component
let make = (~iconName, ~side, ~refElement: React.ref<Js.nullable<Dom.element>>, ~isVisible) => {
Expand Down
1 change: 0 additions & 1 deletion src/components/InfraDateRangeCustomSelection.res
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
external strToForm: string => ReactEvent.Form.t = "%identity"
@send external focus: Dom.element => unit = "focus"
type focusElement = From | To

Expand Down
12 changes: 7 additions & 5 deletions src/components/InfraDateRangePicker.res
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
external strToForm: string => ReactEvent.Form.t = "%identity"

let useErroryValueResetter = (
input: ReactFinalForm.fieldRenderPropsInput,
isoStringToCustomTimeZone,
Expand All @@ -14,7 +12,7 @@ let useErroryValueResetter = (
}
}
if input.value->isErroryTimeValue {
input.onChange(""->strToForm)
input.onChange(""->Identity.stringToFormReactEvent)
}

None
Expand Down Expand Up @@ -327,7 +325,9 @@ let make = (
sec,
)
setStartTime(_ => `${hour}:${min}:${sec}`)
startInput.onChange(TimeZoneHook.formattedISOString(startDateTimeCheck, format)->strToForm)
startInput.onChange(
TimeZoneHook.formattedISOString(startDateTimeCheck, format)->Identity.stringToFormReactEvent,
)
}

let changeEndDate = (~hour="23", ~min="59", ~sec="59", ~ele, ()) => {
Expand All @@ -345,7 +345,9 @@ let make = (
sec,
)
setEndTime(_ => `${hour}:${min}:${sec}`)
endInput.onChange(TimeZoneHook.formattedISOString(endDateTimeCheck, format)->strToForm)
endInput.onChange(
TimeZoneHook.formattedISOString(endDateTimeCheck, format)->Identity.stringToFormReactEvent,
)
}

let processDate = x => {
Expand Down
7 changes: 3 additions & 4 deletions src/components/InputFields.res
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ type comboCustomInputRecord = {
}

module DOBPicker = {
external strToForm: string => ReactEvent.Form.t = "%identity"
external jsonToForm: Js.Json.t => ReactEvent.Form.t = "%identity"
@react.component
let make = (
Expand Down Expand Up @@ -47,7 +46,7 @@ module DOBPicker = {
val := Js.String.concat("-", val.contents)
}
setSelectedDate(_ => val.contents)
input.onChange(val.contents->strToForm)
input.onChange(val.contents->Identity.stringToFormReactEvent)
}
let dropdownRef = React.useRef(Js.Nullable.null)
let (isExpanded, setIsExpanded) = React.useState(_ => false)
Expand All @@ -64,10 +63,10 @@ module DOBPicker = {
setIsExpanded(p => !p)
if format == "DD-MM-YYYY" {
setSelectedDate(_ => changeDOBFormat(str))
input.onChange(changeDOBFormat(str)->strToForm)
input.onChange(changeDOBFormat(str)->Identity.stringToFormReactEvent)
} else {
setSelectedDate(_ => str)
input.onChange(str->strToForm)
input.onChange(str->Identity.stringToFormReactEvent)
}
}
React.useEffect1(() => {
Expand Down
1 change: 0 additions & 1 deletion src/components/InputFields.resi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ type customInputFn = (
type comboCustomInputFn = array<ReactFinalForm.fieldRenderProps> => React.element
type comboCustomInputRecord = {fn: comboCustomInputFn, names: array<string>}
module DOBPicker: {
external strToForm: string => ReactEvent.Form.t = "%identity"
external jsonToForm: Js.Json.t => ReactEvent.Form.t = "%identity"
@react.component
let make: (
Expand Down
Loading