Skip to content

Commit

Permalink
Search for stored value in local data
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Feb 10, 2024
1 parent 2d97403 commit a735ade
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/decorate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ exports.decorate = function (params, keyPath, componentName) {
return params
}

keyPath = _.toPath(keyPath)

const { data, errors } = this.ctx
if (!data) {
return ''
}

keyPath = _.toPath(keyPath)

// Strip data from key path as auto store data middleware adds it
if (keyPath[0] === 'data') {
keyPath.shift(1)
}

const storedValue = _.get(data, keyPath)
// Get stored value from session data, else local data
const storedValue = _.get(data, keyPath) || _.get(this.ctx, keyPath)
if (!storedValue) {
return ''
}

params.id = (params.id) ? params.id : keyPath.join('-')
params.name = (params.name) ? params.name : keyPath.map(s => `[${s}]`).join('')
Expand Down

0 comments on commit a735ade

Please sign in to comment.