Skip to content

Commit

Permalink
Fix opening the Transform or Sort modal in code mode with invalid JSO…
Browse files Browse the repository at this point in the history
…N contents not triggering the `onError` callback (see #1364)
  • Loading branch information
josdejong committed Aug 25, 2021
1 parent cbb95ae commit b3b31f2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
8 changes: 5 additions & 3 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ https://github.com/josdejong/jsoneditor

## not yet published, version 9.5.4

- Change the default behavior of error handling to open a basic alert instead
of logging the error in the console (see #1364).
- Use `noreferrer` for window.open. Thanks @rajitbanerjee.
- Fix #1363: parsing error contains html caharacters.
- Fix #1363: parsing error contains html characters.
- Fix opening the Transform or Sort modal in code mode with invalid JSON
contents not triggering the `onError` callback (see #1364).
- Change the default behavior of error handling to open a basic alert instead
of logging the error in the console (see #1364).


## 2021-07-28, version 9.5.3
Expand Down
67 changes: 38 additions & 29 deletions src/js/textmode.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,48 +456,57 @@ textmode._updateHistoryButtons = function () {
* @private
*/
textmode._showSortModal = function () {
const me = this
const container = this.options.modalAnchor || DEFAULT_MODAL_ANCHOR
const json = this.get()
try {
const me = this
const container = this.options.modalAnchor || DEFAULT_MODAL_ANCHOR
const json = this.get()

function onSort (sortedBy) {
if (Array.isArray(json)) {
const sortedJson = sort(json, sortedBy.path, sortedBy.direction)
function onSort (sortedBy) {
if (Array.isArray(json)) {
const sortedJson = sort(json, sortedBy.path, sortedBy.direction)

me.sortedBy = sortedBy
me.update(sortedJson)
}
me.sortedBy = sortedBy
me.update(sortedJson)
}

if (isObject(json)) {
const sortedJson = sortObjectKeys(json, sortedBy.direction)
if (isObject(json)) {
const sortedJson = sortObjectKeys(json, sortedBy.direction)

me.sortedBy = sortedBy
me.update(sortedJson)
me.sortedBy = sortedBy
me.update(sortedJson)
}
}
}

showSortModal(container, json, onSort, me.sortedBy)
showSortModal(container, json, onSort, me.sortedBy)
} catch (err) {
this._onError(err)
}
}

/**
* Open a transform modal
* @private
*/
textmode._showTransformModal = function () {
const { modalAnchor, createQuery, executeQuery, queryDescription } = this.options
const json = this.get()

showTransformModal({
container: modalAnchor || DEFAULT_MODAL_ANCHOR,
json,
queryDescription, // can be undefined
createQuery,
executeQuery,
onTransform: query => {
const updatedJson = executeQuery(json, query)
this.update(updatedJson)
}
})
try {
const { modalAnchor, createQuery, executeQuery, queryDescription } = this.options

const json = this.get()

showTransformModal({
container: modalAnchor || DEFAULT_MODAL_ANCHOR,
json,
queryDescription, // can be undefined
createQuery,
executeQuery,
onTransform: query => {
const updatedJson = executeQuery(json, query)
this.update(updatedJson)
}
})
} catch (err) {
this._onError(err)
}
}

/**
Expand Down

0 comments on commit b3b31f2

Please sign in to comment.