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

feat(next): add store as global #1243

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/app-frontend/src/features/inspector/DataField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@
>
{{ $t('DataField.contextMenu.copyValue') }}
</VueDropdownButton>

<VueDropdownButton
icon-left="bug_report"
@click="storeAsGlobal"
>{{ $t('DataField.contextMenu.storeGlobal') }}</VueDropdownButton>
</div>
</VueDropdown>
</span>
Expand Down Expand Up @@ -212,7 +217,8 @@ import {
isPlainObject,
sortByKey,
openInEditor,
copyToClipboard
copyToClipboard,
storeAsGlobal
} from '@utils/util'
import { formattedValue, valueType } from '@front/util/format'

Expand Down Expand Up @@ -430,6 +436,10 @@ export default {
copyToClipboard(this.field.value)
},

storeAsGlobal () {
storeAsGlobal(this.field.value)
},

onClick (event) {
// Cancel if target is interactive
if (event.target.tagName === 'INPUT' || event.target.className.includes('button')) {
Expand Down
3 changes: 2 additions & 1 deletion packages/app-frontend/src/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ export default {
}
},
contextMenu: {
copyValue: 'Copy Value'
copyValue: 'Copy Value',
storeGlobal: 'Store as global'
},
quickEdit: {
number: {
Expand Down
17 changes: 17 additions & 0 deletions packages/shared-utils/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,3 +650,20 @@ export function copyToClipboard (state) {
document.execCommand('copy')
document.body.removeChild(dummyTextArea)
}

let globalCount = 0
export function storeAsGlobal (state) {
const target = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : {}

const name = 'vueTemp'

let i = 0 // prevent infinite loop
let varName = name + globalCount
do {
++globalCount
varName = name + globalCount
} while (!!target[varName] || (++i) > 500)

target[varName] = state
console.log(varName, state)
}