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

fix: initial value #39

Merged
merged 3 commits into from
May 17, 2023
Merged

fix: initial value #39

merged 3 commits into from
May 17, 2023

Conversation

NasgulNexus
Copy link
Contributor

  1. In the controller, instead of the initial value, there will be a value.
  2. From the final form we pull out the initial value and value.

@NasgulNexus NasgulNexus requested a review from bocembocem as a code owner May 11, 2023 10:17
@gravity-ui-bot
Copy link
Contributor

Preview is ready.

@@ -85,7 +85,7 @@ export const DynamicField: React.FC<DynamicFieldProps> = ({
name={name}
parentOnChange={null}
parentOnUnmount={null}
initialValue={_.get(tools.initialValue, name)}
value={_.get(tools.values, name)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U need to take values from store, not from tools

@@ -71,18 +73,19 @@ export const useField = <Value extends FieldValue, SpecType extends Spec>({
}

const error = validate?.(value);
const isDiffentValues = !_.isEqual(value, initialValue);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*diffeREnt
Prefix is better to use for functions
You're checking dirty here, let's give a name for variable dirty too

pristine: false,
touched: false,
modified: isDiffentValues,
pristine: isDiffentValues,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

U can't use isEqual to check for pristine, only ===

@@ -28,36 +32,42 @@ export const useStore = (name: string) => {
const tools = React.useMemo(
() => ({
initialValue: store.initialValue,
values: store.values,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to include values in tools

onChange: (name: string, value: FieldValue, errors?: Record<string, ValidateError>) =>
setStore((store) => ({
...store,
values: _.set({...store.values}, name, _.clone(value)),
errors: errors || {},
})),
onUnmount: (name: string) =>
onUnmount: (name: string) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pointless changes, let's remove back


export interface DynamicFormsContext {
config: DynamicFormConfig;
Monaco?: React.ComponentType<MonacoEditorProps>;
tools: {
initialValue: FieldObjectValue;
initialValue: FieldValue;
values: FieldValue;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove values

@NasgulNexus NasgulNexus merged commit ce52d65 into main May 17, 2023
@NasgulNexus NasgulNexus deleted the fix-initial-value branch May 17, 2023 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants