If we open an existing config in GUI editor, the "Save" button should appear only if there are changes to the Config instance in the store. Therefore, we should provide a mechanism to check whether the config instance has been edited.
dirty: boolean
Returns true if values are not deeply equal from initial values, false otherwise. dirty is a readonly computed property and should not be mutated directly.
However, there are problems when handling fields of type number. A "number" text field will hold a value of string (e.g., _settings.cpus: "1.5") in Formik, which has a different type of what the initial config will hold (e.g., _settings.cpus: 1.5). Due to difference in type, dirty will be false.
Manipulating onChange is also no easy task. The below code doesn't work when a user type 1., because parseFloat("1.") = 1. Hence, the user cannot type decimal points.
Description
If we open an existing config in GUI editor, the "Save" button should appear only if there are changes to the
Config
instance in the store. Therefore, we should provide a mechanism to check whether the config instance has been edited.Solutions
Few solutions are being explored:
dirty
propertyConfig
class for deep comparison:-1: Formik's
dirty
propertyIf we're using Formik, according to the docs:
However, there are problems when handling fields of type
number
. A "number" text field will hold a value of string (e.g.,_settings.cpus: "1.5"
) in Formik, which has a different type of what the initial config will hold (e.g.,_settings.cpus: 1.5
). Due to difference in type,dirty
will be false.Manipulating
onChange
is also no easy task. The below code doesn't work when a user type1.
, becauseparseFloat("1.") = 1
. Hence, the user cannot type decimal points.