bugfix: records&indexs badly named in UI
(due to previous collectionName change)
This commit is contained in:
parent
5209c6443c
commit
f771db5915
|
@ -5,7 +5,7 @@
|
|||
import ButtonGroup from "../common/ButtonGroup.svelte"
|
||||
import Button from "../common/Button.svelte"
|
||||
import ActionButton from "../common/ActionButton.svelte"
|
||||
import { validateAccessLevels } from "../common/core"
|
||||
import { validateAccessLevels, nodeNameFromNodeKey } from "../common/core"
|
||||
import ErrorsBox from "../common/ErrorsBox.svelte"
|
||||
|
||||
export let level
|
||||
|
@ -38,7 +38,9 @@
|
|||
)
|
||||
|
||||
const getPermissionName = perm =>
|
||||
perm.nodeKey ? `${perm.type} - ${perm.nodeKey}` : perm.type
|
||||
perm.nodeKey
|
||||
? `${perm.type} - ${nodeNameFromNodeKey(hierarchy, perm.nodeKey)}`
|
||||
: perm.type
|
||||
|
||||
const save = () => {
|
||||
const newLevels = isNew
|
||||
|
|
|
@ -79,6 +79,7 @@ export const getPotentialReferenceIndexes = (hierarchy, record) =>
|
|||
|
||||
export const isIndex = hierarchyFunctions.isIndex
|
||||
export const isRecord = hierarchyFunctions.isRecord
|
||||
export const nodeNameFromNodeKey = hierarchyFunctions.nodeNameFromNodeKey
|
||||
|
||||
export const getDefaultTypeOptions = type =>
|
||||
!type ? {} : allTypes[type].getDefaultOptions()
|
||||
|
|
|
@ -48,6 +48,11 @@ const nodeKeyMaker = node => () =>
|
|||
[defaultCase, n => joinKey(node.parent().nodeKey(), n.name)]
|
||||
)(node)
|
||||
|
||||
const nodeNameMaker = node => () =>
|
||||
isRoot(node)
|
||||
? "/"
|
||||
: joinKey(node.parent().nodeName(), node.name)
|
||||
|
||||
const validate = parent => node => {
|
||||
if (
|
||||
isIndex(node) &&
|
||||
|
@ -71,6 +76,7 @@ const validate = parent => node => {
|
|||
|
||||
const construct = parent => node => {
|
||||
node.nodeKey = nodeKeyMaker(node)
|
||||
node.nodeName = nodeNameMaker(node)
|
||||
node.pathRegx = pathRegxMaker(node)
|
||||
node.parent = constant(parent)
|
||||
node.isRoot = () =>
|
||||
|
|
|
@ -244,6 +244,11 @@ export const fieldReversesReferenceToIndex = indexNode => field =>
|
|||
intersection(field.typeOptions.reverseIndexNodeKeys)([indexNode.nodeKey()])
|
||||
.length > 0
|
||||
|
||||
export const nodeNameFromNodeKey = (hierarchy, nodeKey) => {
|
||||
const node = getNode(hierarchy, nodeKey)
|
||||
return node ? node.nodeName() : ""
|
||||
}
|
||||
|
||||
export default {
|
||||
getLastPartInKey,
|
||||
getNodesInPath,
|
||||
|
@ -281,4 +286,5 @@ export default {
|
|||
getFlattenedHierarchy,
|
||||
isTopLevelIndex,
|
||||
isTopLevelRecord,
|
||||
nodeNameFromNodeKey,
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ describe("hierarchy node creation", () => {
|
|||
expect(root.parent).toBeDefined()
|
||||
expect(root.isRoot()).toBeTruthy()
|
||||
expect(root.indexes).toEqual([])
|
||||
expect(root.nodeName()).toBe("/")
|
||||
})
|
||||
|
||||
it("> getNewRecordTemplate > should be initialise with correct members", async () => {
|
||||
|
@ -33,6 +34,7 @@ describe("hierarchy node creation", () => {
|
|||
expect(record.collectionNodeKey()).toBe("/records")
|
||||
expect(record.collectionPathRegx()).toBe("/records")
|
||||
expect(record.nodeKey()).toBe(`/records/${record.nodeId}-{id}`)
|
||||
expect(record.nodeName()).toBe(`/${record.name}`)
|
||||
expect(record.pathRegx()).toBe(`/records/${record.nodeId}-[a-zA-Z0-9_\-]+`)
|
||||
})
|
||||
|
||||
|
@ -60,6 +62,16 @@ describe("hierarchy node creation", () => {
|
|||
expect(parentRecord.children[0]).toBe(record)
|
||||
})
|
||||
|
||||
it("> getNewrecordTemplate > child should get correct nodeName ", async () => {
|
||||
const { templateApi } = await getMemoryTemplateApi()
|
||||
const root = templateApi.getNewRootLevel()
|
||||
const parentRecord = templateApi.getNewRecordTemplate(root)
|
||||
parentRecord.name = "parent"
|
||||
const record = templateApi.getNewRecordTemplate(parentRecord)
|
||||
record.name = "child"
|
||||
expect(record.nodeName()).toBe(`/${parentRecord.name}/${record.name}`)
|
||||
})
|
||||
|
||||
it("> getNewrecordTemplate > should add itself to parents's default index allowedNodeIds", async () => {
|
||||
const { templateApi } = await getMemoryTemplateApi()
|
||||
const root = templateApi.getNewRootLevel()
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export default ({ records }) =>
|
||||
records.map(r => ({
|
||||
name: `Form for Record: ${r.nodeKey()}`,
|
||||
name: `Form for Record: ${r.nodeName()}`,
|
||||
props: outerContainer(r),
|
||||
}))
|
||||
|
||||
|
|
Loading…
Reference in New Issue