Remember previous query when opening transform modal again
This commit is contained in:
parent
350969638c
commit
01579dc115
|
@ -1,7 +1,7 @@
|
|||
<svelte:options immutable={true} />
|
||||
|
||||
<script>
|
||||
import { getContext, setContext, onDestroy } from 'svelte'
|
||||
import { getContext } from 'svelte'
|
||||
import Select from 'svelte-select'
|
||||
import Header from './Header.svelte'
|
||||
import { getNestedPaths } from '../../utils/arrayUtils.js'
|
||||
|
@ -9,7 +9,7 @@
|
|||
import { stringifyPath } from '../../utils/pathUtils.js'
|
||||
import { sortArray, sortObjectKeys } from '../../logic/sort.js'
|
||||
import { sortModalState } from './sortModalState.js'
|
||||
import { compileJSONPointer } from '../../utils/jsonPointer';
|
||||
import { compileJSONPointer } from '../../utils/jsonPointer'
|
||||
|
||||
export let id
|
||||
export let json
|
||||
|
@ -17,8 +17,8 @@ import { compileJSONPointer } from '../../utils/jsonPointer';
|
|||
export let onSort
|
||||
|
||||
const {close} = getContext('simple-modal')
|
||||
const stateId = `${id}:${compileJSONPointer(rootPath)}`
|
||||
|
||||
let stateId = `${id}:${compileJSONPointer(rootPath)}`
|
||||
$: json
|
||||
$: jsonIsArray = Array.isArray(json)
|
||||
$: paths = jsonIsArray ? getNestedPaths(json) : undefined
|
||||
|
|
|
@ -2,17 +2,22 @@
|
|||
|
||||
<script>
|
||||
import { getContext } from 'svelte'
|
||||
import { compileJSONPointer } from '../../utils/jsonPointer';
|
||||
import { compileJSONPointer } from '../../utils/jsonPointer'
|
||||
import Header from './Header.svelte'
|
||||
import { transformModalState } from './transformModalState.js'
|
||||
|
||||
export let id
|
||||
export let json
|
||||
export let rootPath
|
||||
export let onTransform
|
||||
|
||||
const DEFAULT_QUERY = 'function query (data) {\n return data\n}'
|
||||
|
||||
const {close} = getContext('simple-modal')
|
||||
|
||||
let query = 'function query (data) {\n return data\n}'
|
||||
let stateId = `${id}:${compileJSONPointer(rootPath)}`
|
||||
|
||||
let query = transformModalState[stateId]?.query || DEFAULT_QUERY
|
||||
let previewHasError = false
|
||||
let preview = ''
|
||||
|
||||
|
@ -49,7 +54,13 @@ import { compileJSONPointer } from '../../utils/jsonPointer';
|
|||
value: jsonTransformed
|
||||
}
|
||||
])
|
||||
|
||||
|
||||
// remember the selected values for the next time we open the SortModal
|
||||
// just in memory, not persisted
|
||||
transformModalState[stateId] = {
|
||||
query
|
||||
}
|
||||
|
||||
close()
|
||||
} catch (err) {
|
||||
// this should never occur since we can only press the Transform
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export const transformModalState = {}
|
Loading…
Reference in New Issue