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 Json-editor multiple instance #894

Merged
merged 6 commits into from
Feb 4, 2021
Merged

Fix Json-editor multiple instance #894

merged 6 commits into from
Feb 4, 2021

Conversation

Njuelle
Copy link
Contributor

@Njuelle Njuelle commented Jan 27, 2021

What does this PR do ?

Fix #893 Json-editor multiple instance

How should this be manually tested?

  • Step 1 : Create a collection with at least 2 nested properties
{
  "bar": {
    "properties": {
      "barfoo": {
        "type": "keyword"
      },
      "bazfoo": {
        "type": "keyword"
      }
    }
  },
  "foo": {
    "properties": {
      "foobar": {
        "type": "keyword"
      },
      "foobaz": {
        "type": "keyword"
      }
    }
  }
}
  • Step 2 : try create and edit a document with the form-view enabled

@Njuelle Njuelle self-assigned this Jan 27, 2021
@Njuelle Njuelle linked an issue Jan 27, 2021 that may be closed by this pull request
@Njuelle Njuelle marked this pull request as draft January 27, 2021 10:58
@Njuelle Njuelle marked this pull request as ready for review January 27, 2021 14:16
@Njuelle Njuelle marked this pull request as draft January 27, 2021 15:05
@Njuelle Njuelle marked this pull request as ready for review January 27, 2021 16:26
height: { type: Number, default: 250 }
},
data() {
return {
editor: null
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of putting the editor variable in the component state?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is necessary to have the editor variable scoped to the component to be able to use several instances

Copy link
Contributor

Choose a reason for hiding this comment

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

why?

Copy link
Contributor

@berthieresteban berthieresteban Feb 3, 2021

Choose a reason for hiding this comment

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

If we let the editor in global:

Hypothesis: if we add multiple json-editors there will still be only one editor variable wich will be overrided each time we instanciate a new json-editor.

Actual consequence: Call the setContent method of a json-editor component will always set the content on the last instanciated editor no matter wich json-editor's method we call

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. The editor variable is scoped to the JSONEditor.vue module, which is a singleton, in the CommonJS modules model. The module exports a VueJS Component config, which is passed to the Vue constructor each time this component is instantiated. But this config has a reference to the editor variable, which is actually overwritten, as you rightly say, each time the component is instantiated. By putting the variable inside the data structure, you make it local to the component instead, which is obviously not a singleton. This is a nice thing to keep in mind for future developments.

I still don't like the idea of putting a complex object (i.e. one that has attributes and functions) inside the data structure, because it is meant to keep track of the state of the component, yet this object is just logic to make the editor work. We should find a way to replicate this reference each time the component is created, and avoid the reference to be overwritten.

I am not really hurried to ship this fix, but if you are, we can keep this enhancement for later. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

After merge this PR I'll create an issue concerning the refacto of the json-editor and we'll probably need a workshop

Copy link
Contributor

@xbill82 xbill82 left a comment

Choose a reason for hiding this comment

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

It would be nice if we had the same code-formatting rules.

Comment on lines 44 to 53
phone: 'Blackberry',
car: 'Laguna'
},
skill: {
name: 'managment',
level: '1'
},
job: 'Always asking Esteban to do his job',
employeeOfTheMonthSince: '1996-07-10'
}
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

@xbill82 xbill82 merged commit 794fcd5 into 4-dev Feb 4, 2021
@xbill82 xbill82 deleted the 893-fix-jsonFormInput branch February 4, 2021 15:21
This was referenced Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] Cannot use form-view with multiple instances of JsonFormInput
4 participants