Implement sort a nested path if provided
This commit is contained in:
parent
456f1912fd
commit
89eaf2f264
|
@ -22,7 +22,6 @@
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
|
|
|
@ -8,6 +8,9 @@
|
||||||
--clearSelectBottom: 2px;
|
--clearSelectBottom: 2px;
|
||||||
--itemIsActiveBG: #3883fa; // theme-color
|
--itemIsActiveBG: #3883fa; // theme-color
|
||||||
|
|
||||||
|
font-family: $font-family;
|
||||||
|
font-size: $font-size;
|
||||||
|
|
||||||
.contents {
|
.contents {
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,19 @@
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
font-weight: normal;
|
font-weight: normal;
|
||||||
padding-bottom: $padding;
|
padding-bottom: $padding;
|
||||||
|
|
||||||
|
input.path {
|
||||||
|
width: 100%;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding: 6px 16px; // TODO: define variables for those props
|
||||||
|
border: 1px solid $border-gray;
|
||||||
|
border-radius: $border-radius;
|
||||||
|
font-family: $font-family;
|
||||||
|
font-size: $font-size;
|
||||||
|
color: $black;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
import { getNestedPaths } from '../../utils/arrayUtils.js'
|
import { getNestedPaths } from '../../utils/arrayUtils.js'
|
||||||
import { getIn, setIn } from '../../utils/immutabilityHelpers.js'
|
import { getIn, setIn } from '../../utils/immutabilityHelpers.js'
|
||||||
import { isObject } from '../../utils/typeUtils.js'
|
import { isObject } from '../../utils/typeUtils.js'
|
||||||
|
import { stringifyPath } from '../../utils/pathUtils.js'
|
||||||
|
|
||||||
export let json
|
export let json
|
||||||
export let path
|
export let path
|
||||||
|
@ -33,10 +34,17 @@
|
||||||
let selectedProperty = undefined
|
let selectedProperty = undefined
|
||||||
let selectedDirection = asc
|
let selectedDirection = asc
|
||||||
|
|
||||||
|
$: {
|
||||||
|
// if there is only one option, select it and do not render the select box
|
||||||
|
if (selectedProperty === undefined && properties && properties.length === 1) {
|
||||||
|
selectedProperty = properties[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function pathToOption (path) {
|
function pathToOption (path) {
|
||||||
return {
|
return {
|
||||||
value: path,
|
value: path,
|
||||||
label: path.join('.')
|
label: stringifyPath(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,10 +133,17 @@
|
||||||
{#if path.length > 0}
|
{#if path.length > 0}
|
||||||
<tr>
|
<tr>
|
||||||
<th>Path</th>
|
<th>Path</th>
|
||||||
<td>{path.join('.')}</td>
|
<td>
|
||||||
|
<input
|
||||||
|
class="path"
|
||||||
|
type="text"
|
||||||
|
readonly
|
||||||
|
value={stringifyPath(path)}
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{/if}
|
{/if}
|
||||||
{#if isArray}
|
{#if isArray && (properties.length > 1 || selectedProperty === undefined) }
|
||||||
<tr>
|
<tr>
|
||||||
<th>Property</th>
|
<th>Property</th>
|
||||||
<td>
|
<td>
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
|
|
||||||
.json-node {
|
.json-node {
|
||||||
position: relative;
|
position: relative;
|
||||||
font-family: $font-family;
|
font-family: $font-family-mono;
|
||||||
font-size: $font-size;
|
font-size: $font-size-mono;
|
||||||
color: $black;
|
color: $black;
|
||||||
|
|
||||||
&.root {
|
&.root {
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: $gray-icon;
|
color: $gray-icon;
|
||||||
font-size: $font-size;
|
font-size: $font-size-mono;
|
||||||
line-height: $line-height;
|
line-height: $line-height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
border: none;
|
border: none;
|
||||||
font-size: $font-size-small;
|
font-size: $font-size-small;
|
||||||
font-family: $font-family-menu;
|
font-family: $font-family;
|
||||||
color: white;
|
color: white;
|
||||||
background: $light-gray;
|
background: $light-gray;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
@import '../../styles.scss';
|
@import '../../styles.scss';
|
||||||
|
|
||||||
.menu {
|
.menu {
|
||||||
font-family: $font-family-menu;
|
font-family: $font-family;
|
||||||
font-size: $font-size;
|
font-size: $font-size;
|
||||||
background: $theme-color;
|
background: $theme-color;
|
||||||
color: $white;
|
color: $white;
|
||||||
|
|
|
@ -31,12 +31,13 @@
|
||||||
import { keyComboFromEvent } from '../../utils/keyBindings.js'
|
import { keyComboFromEvent } from '../../utils/keyBindings.js'
|
||||||
import { search, searchNext, searchPrevious } from '../../logic/search.js'
|
import { search, searchNext, searchPrevious } from '../../logic/search.js'
|
||||||
import { immutableJSONPatch } from '../../utils/immutableJSONPatch'
|
import { immutableJSONPatch } from '../../utils/immutableJSONPatch'
|
||||||
import { last, cloneDeep } from 'lodash-es'
|
import { first, last, initial, cloneDeep } from 'lodash-es'
|
||||||
import jump from '../../assets/jump.js/src/jump.js'
|
import jump from '../../assets/jump.js/src/jump.js'
|
||||||
import { expandPath, syncState, patchProps } from '../../logic/documentState.js'
|
import { expandPath, syncState, patchProps } from '../../logic/documentState.js'
|
||||||
import Menu from './Menu.svelte'
|
import Menu from './Menu.svelte'
|
||||||
import { isObjectOrArray } from '../../utils/typeUtils.js'
|
import { isObjectOrArray } from '../../utils/typeUtils.js'
|
||||||
import { mapValidationErrors } from '../../logic/validation.js'
|
import { mapValidationErrors } from '../../logic/validation.js'
|
||||||
|
import { stringifyPath } from '../../utils/pathUtils.js'
|
||||||
import SortModal from '../modals/SortModal.svelte'
|
import SortModal from '../modals/SortModal.svelte'
|
||||||
import TransformModal from '../modals/TransformModal.svelte'
|
import TransformModal from '../modals/TransformModal.svelte'
|
||||||
|
|
||||||
|
@ -262,9 +263,15 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSort () {
|
function handleSort () {
|
||||||
|
const path = selection && selection.paths
|
||||||
|
? selection.paths.length > 1
|
||||||
|
? initial(first(selection.paths)) // the parent path of the paths
|
||||||
|
: first(selection.paths) // the first and only path
|
||||||
|
: []
|
||||||
|
|
||||||
open(SortModal, {
|
open(SortModal, {
|
||||||
json: doc,
|
json: doc,
|
||||||
path: [], // FIXME: based on selection
|
path,
|
||||||
onSort: sortedDoc => {
|
onSort: sortedDoc => {
|
||||||
console.log('onSort', sortedDoc)
|
console.log('onSort', sortedDoc)
|
||||||
doc = sortedDoc
|
doc = sortedDoc
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
|
|
||||||
$font-family: consolas, monaco, "lucida console", "courier new", "dejavu sans mono", "droid sans mono", courier, monospace, sans-serif;
|
$font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
||||||
$font-size: 14px;
|
$font-family-mono: consolas, monaco, "lucida console", "courier new", "dejavu sans mono", "droid sans mono", courier, monospace, sans-serif;
|
||||||
|
$font-size-mono: 14px;
|
||||||
|
$font-size: 16px;
|
||||||
$font-size-small: 11px;
|
$font-size-small: 11px;
|
||||||
$font-family-menu: arial, "sans-serif";
|
|
||||||
|
|
||||||
$white: #fff;
|
$white: #fff;
|
||||||
$black: #1A1A1A;
|
$black: #1A1A1A;
|
||||||
|
@ -27,6 +28,7 @@ $light-gray: #c0c0c0;
|
||||||
$selection-background: #e0e0e0;
|
$selection-background: #e0e0e0;
|
||||||
$hovered-background: #f0f0f0;
|
$hovered-background: #f0f0f0;
|
||||||
$background-gray: #f5f5f5;
|
$background-gray: #f5f5f5;
|
||||||
|
$border-gray: #d8dbdf;
|
||||||
|
|
||||||
$line-height: 18px;
|
$line-height: 18px;
|
||||||
$indentation-width: 18px; // IMPORTANT: keep in sync with js constant INDENTATION_WIDTH
|
$indentation-width: 18px; // IMPORTANT: keep in sync with js constant INDENTATION_WIDTH
|
||||||
|
@ -46,7 +48,7 @@ button {
|
||||||
background: transparent;
|
background: transparent;
|
||||||
color: inherit;
|
color: inherit;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-family: $font-family-menu;
|
font-family: $font-family;
|
||||||
font-size: $font-size;
|
font-size: $font-size;
|
||||||
padding: $menu-padding;
|
padding: $menu-padding;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stringify a path like
|
||||||
|
*
|
||||||
|
* ["data", 2, "nested", "property"]
|
||||||
|
*
|
||||||
|
* into a string:
|
||||||
|
*
|
||||||
|
* ".data[2].nested.property"
|
||||||
|
*
|
||||||
|
* @param {Path}
|
||||||
|
* @return {string}
|
||||||
|
*/
|
||||||
|
export function stringifyPath (path) {
|
||||||
|
return path.map(prop => {
|
||||||
|
return typeof prop === 'number'
|
||||||
|
? `[${prop}]`
|
||||||
|
: `.${prop}`
|
||||||
|
}).join('')
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
import assert from 'assert'
|
||||||
|
import { stringifyPath } from './pathUtils.js'
|
||||||
|
|
||||||
|
describe('pathUtils', () => {
|
||||||
|
it('stringifyPath', () => {
|
||||||
|
assert.strictEqual(stringifyPath(["data", 2, "nested", "property"]), '.data[2].nested.property')
|
||||||
|
assert.strictEqual(stringifyPath(['']), '.')
|
||||||
|
assert.strictEqual(stringifyPath([]), '')
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue