-
Notifications
You must be signed in to change notification settings - Fork 26
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ed434dc
add dynamic ref props with default value
Njuelle db7afd9
add e2e tests
Njuelle 73f1f62
fix tests
Njuelle 7cb0d18
Merge branch '4-dev' into 893-fix-jsonFormInput
Njuelle 3dca4dc
fix tests
Njuelle 50c6d67
lint
Njuelle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,12 @@ describe('Form view', function() { | |
items: { | ||
type: 'object' | ||
}, | ||
skill: { | ||
properties: { | ||
name: { type: 'keyword' }, | ||
level: { type: 'integer' } | ||
} | ||
}, | ||
job: { | ||
type: 'text' | ||
}, | ||
|
@@ -38,6 +44,10 @@ describe('Form view', function() { | |
phone: 'Blackberry', | ||
car: 'Laguna' | ||
}, | ||
skill: { | ||
name: 'managment', | ||
level: '1' | ||
}, | ||
job: 'Always asking Esteban to do his job', | ||
employeeOfTheMonthSince: '1996-07-10' | ||
} | ||
Comment on lines
44
to
53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❤️ |
||
|
@@ -49,15 +59,14 @@ describe('Form view', function() { | |
it('should be able to create a new document with the form view enabled', function() { | ||
cy.visit(`/#/data/${indexName}/${collectionName}`) | ||
|
||
|
||
cy.get('[data-cy="CreateDocument-btn"').click() | ||
|
||
|
||
cy.get('[data-cy="formView-switch"').click({ force: true }) | ||
cy.get('[data-cy="DocumentCreate-input--id"').type('new-doc') | ||
|
||
cy.get('input#age').type('31') | ||
cy.get('textarea.ace_text-input') | ||
|
||
cy.get('[name="items"] > textarea.ace_text-input') | ||
.type('{backspace}{backspace}', { force: true }) | ||
.type( | ||
`{ | ||
|
@@ -66,6 +75,17 @@ describe('Form view', function() { | |
force: true | ||
} | ||
) | ||
|
||
cy.get('[name="skill"] > textarea.ace_text-input') | ||
.type('{backspace}{backspace}', { force: true }) | ||
.type( | ||
`{ | ||
"name": "CSS", "level": 60`, | ||
{ | ||
force: true | ||
} | ||
) | ||
|
||
cy.get('textarea#job').type('webmestre enginer') | ||
cy.get('input#name').type('Bombi') | ||
|
||
|
@@ -74,7 +94,6 @@ describe('Form view', function() { | |
|
||
cy.get('[data-cy="DocumentCreate-btn"').click({ force: true }) | ||
|
||
|
||
cy.contains('new-doc') | ||
cy.request( | ||
'GET', | ||
|
@@ -86,16 +105,16 @@ describe('Form view', function() { | |
date.getTime().toString() | ||
) | ||
expect(res.body.result._source.items.desktop).to.be.equals('standing') | ||
expect(res.body.result._source.skill.name).to.be.equals('CSS') | ||
expect(res.body.result._source.skill.level).to.be.equals(60) | ||
}) | ||
}) | ||
|
||
it('should be able to update a document with the form view enabled', function() { | ||
cy.visit(`/#/data/${indexName}/${collectionName}`) | ||
|
||
|
||
cy.get('[data-cy="DocumentListItem-update--testdoc"').click() | ||
|
||
|
||
cy.get('[data-cy="formView-switch"').click({ force: true }) | ||
|
||
cy.get('input#age').type('{selectall}{backspace}43') | ||
|
@@ -107,6 +126,16 @@ describe('Form view', function() { | |
.clear() | ||
.type('23:30:00') | ||
|
||
cy.get('[name="skill"] > textarea.ace_text-input').type( | ||
`{selectall}{backspace} | ||
{ | ||
"name": "management", "level": 0`, | ||
{ | ||
delay: 400, | ||
force: true | ||
} | ||
) | ||
|
||
cy.get('[data-cy="DocumentUpdate-btn"').click({ force: true }) | ||
|
||
cy.request( | ||
|
@@ -119,16 +148,15 @@ describe('Form view', function() { | |
expect(res.body.result._source.employeeOfTheMonthSince).to.be.equals( | ||
date.getTime().toString() | ||
) | ||
expect(res.body.result._source.skill.level).to.be.equals(0) | ||
}) | ||
}) | ||
|
||
it('should be able to keep synchronized the form view and the JSON view', function() { | ||
cy.visit(`/#/data/${indexName}/${collectionName}`) | ||
|
||
|
||
cy.get('[data-cy="DocumentListItem-update--testdoc"').click() | ||
|
||
|
||
cy.get('textarea.ace_text-input') | ||
.type(`{selectall}{backspace}`, { | ||
delay: 400, | ||
|
@@ -159,10 +187,8 @@ describe('Form view', function() { | |
) | ||
cy.visit(`/#/data/${indexName}/${collectionName}`) | ||
|
||
|
||
cy.get('[data-cy="DocumentListItem-update--witharraydoc"').click() | ||
|
||
|
||
cy.get('[data-cy="formView-switch"').click({ force: true }) | ||
|
||
cy.get('[data-cy="form-view-warning"').should('be.visible') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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 instancesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 theVue
constructor each time this component is instantiated. But this config has a reference to theeditor
variable, which is actually overwritten, as you rightly say, each time the component is instantiated. By putting the variable inside thedata
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?
There was a problem hiding this comment.
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