change name from allowedRecordNodeIds to allowedModelNodeIds

This commit is contained in:
kevmodrome 2020-04-14 11:19:14 +02:00
parent 449b6c9c78
commit d7a4458488
18 changed files with 60 additions and 60 deletions

View File

@ -196,7 +196,7 @@ export const saveCurrentNode = store => () => {
? `all_${cloned.name}s`
: `${cloned.parent().name}_${cloned.name}s`
defaultIndex.allowedRecordNodeIds = [cloned.nodeId]
defaultIndex.allowedModelNodeIds = [cloned.nodeId]
}
state.currentNodeIsNew = false

View File

@ -26,8 +26,8 @@
map(node => ({
node,
isallowed:
index.allowedRecordNodeIds &&
index.allowedRecordNodeIds.some(id => node.nodeId === id),
index.allowedModelNodeIds &&
index.allowedModelNodeIds.some(id => node.nodeId === id),
})),
filter(hierarchyFunctions.isRecord),
filter(hierarchyFunctions.isDecendant($store.currentNode.parent())),
@ -41,11 +41,11 @@
const toggleAllowedModel = model => {
if (model.isallowed) {
index.allowedRecordNodeIds = index.allowedRecordNodeIds.filter(
index.allowedModelNodeIds = index.allowedModelNodeIds.filter(
id => id !== model.node.nodeId
)
} else {
index.allowedRecordNodeIds.push(model.node.nodeId)
index.allowedModelNodeIds.push(model.node.nodeId)
}
}
</script>

View File

@ -138,6 +138,6 @@ const buildHeirarchalIndex = async (app, indexNode) => {
}
const recordNodeApplies = indexNode => recordNode =>
includes(recordNode.nodeId)(indexNode.allowedRecordNodeIds)
includes(recordNode.nodeId)(indexNode.allowedModelNodeIds)
export default buildIndex

View File

@ -65,8 +65,8 @@ export const getRelevantAncestorIndexes = (hierarchy, record) => {
filter(
i =>
i.indexType === indexTypes.ancestor &&
(i.allowedRecordNodeIds.length === 0 ||
includes(nodeId)(i.allowedRecordNodeIds))
(i.allowedModelNodeIds.length === 0 ||
includes(nodeId)(i.allowedModelNodeIds))
),
])

View File

@ -22,7 +22,7 @@ export const canDeleteRecord = recordNode => {
i =>
isAncestorIndex(i) &&
belongsToAncestor(i) &&
includes(node.nodeId)(i.allowedRecordNodeIds)
includes(node.nodeId)(i.allowedModelNodeIds)
),
map(
i =>

View File

@ -109,7 +109,7 @@ const addToParent = obj => {
i => i.name === `${parent.name}_index`
)
if (defaultIndex) {
defaultIndex.allowedRecordNodeIds.push(obj.nodeId)
defaultIndex.allowedModelNodeIds.push(obj.nodeId)
}
}
}
@ -183,7 +183,7 @@ const _getNewModelTemplate = (parent, name, createDefaultIndex, isSingle) => {
if (createDefaultIndex) {
const defaultIndex = getNewIndexTemplate(parent)
defaultIndex.name = `${name}_index`
defaultIndex.allowedRecordNodeIds.push(node.nodeId)
defaultIndex.allowedModelNodeIds.push(node.nodeId)
}
return node
@ -208,7 +208,7 @@ export const getNewIndexTemplate = (parent, type = "ancestor") =>
getShardName: "",
getSortKey: "record.id",
aggregateGroups: [],
allowedRecordNodeIds: [],
allowedModelNodeIds: [],
nodeId: getNodeId(parent),
})

View File

@ -1,8 +1,8 @@
import {} from "../templateApi/heirarchy"
import { } from "../templateApi/heirarchy"
export const canDelete = () => {
/*
it must not exist on any index.allowedRecordNodeIds
it must not exist on any index.allowedModelNodeIds
it must not exist on and reference type fields
these rules should apply to any child nodes , which will also be deleted
*/

View File

@ -187,7 +187,7 @@ const indexHasChanged = (_new, old) =>
_new.map !== old.map ||
_new.filter !== old.filter ||
_new.getShardName !== old.getShardName ||
difference(_new.allowedRecordNodeIds)(old.allowedRecordNodeIds).length > 0
difference(_new.allowedModelNodeIds)(old.allowedModelNodeIds).length > 0
const isFieldSame = f1 => f2 => f1.name === f2.name && f1.type === f2.type

View File

@ -164,8 +164,8 @@ export const getRecordNodeById = (hierarchy, recordId) =>
])
export const recordNodeIdIsAllowed = indexNode => nodeId =>
indexNode.allowedRecordNodeIds.length === 0 ||
includes(nodeId)(indexNode.allowedRecordNodeIds)
indexNode.allowedModelNodeIds.length === 0 ||
includes(nodeId)(indexNode.allowedModelNodeIds)
export const recordNodeIsAllowed = indexNode => recordNode =>
recordNodeIdIsAllowed(indexNode)(recordNode.nodeId)

View File

@ -54,7 +54,7 @@ describe("getRelevantIndexes", () => {
expect(indexExists("/customersBySurname")).toBeTruthy()
})
it("should ignore index when allowedRecordNodeIds does not contain record's node id", async () => {
it("should ignore index when allowedModelNodeIds does not contain record's node id", async () => {
const { recordApi, appHierarchy } = await setupApphierarchy(
basicAppHierarchyCreator_WithFields_AndIndexes
)
@ -72,7 +72,7 @@ describe("getRelevantIndexes", () => {
expect(indexExists("/customersBySurname")).toBeFalsy()
})
it("should include index when allowedRecordNodeIds contains record's node id", async () => {
it("should include index when allowedModelNodeIds contains record's node id", async () => {
const { recordApi, appHierarchy } = await setupApphierarchy(
basicAppHierarchyCreator_WithFields_AndIndexes
)

View File

@ -88,7 +88,7 @@ const createApp = includeFish => templateApi => {
const petsIndex = templateApi.getNewIndexTemplate(root)
petsIndex.name = "allPets"
petsIndex.allowedRecordNodeIds = [dogRecord.nodeId]
petsIndex.allowedModelNodeIds = [dogRecord.nodeId]
const addDogField = addField(dogRecord)
addDogField("name", "string")
@ -105,7 +105,7 @@ const createApp = includeFish => templateApi => {
fishStuff.fishRecord = fishRecord
const fishOnlyIndex = templateApi.getNewIndexTemplate(root)
fishOnlyIndex.name = "fishOnly"
fishOnlyIndex.allowedRecordNodeIds = [fishRecord.nodeId]
fishOnlyIndex.allowedModelNodeIds = [fishRecord.nodeId]
fishStuff.fishOnlyIndex = fishOnlyIndex
const dogFriends = templateApi.getNewIndexTemplate(
@ -115,7 +115,7 @@ const createApp = includeFish => templateApi => {
dogFriends.name = "dogFriends"
fishStuff.dogFriends = dogFriends
petsIndex.allowedRecordNodeIds.push(fishRecord.nodeId)
petsIndex.allowedModelNodeIds.push(fishRecord.nodeId)
const favFishField = addDogField("favouriteFish", "reference", {
indexNodeKey: fishOnlyIndex.nodeKey(),

View File

@ -203,7 +203,7 @@ export const withFields = (hierarchy, templateApi) => {
partnersReferenceIndex.name = "partnersReference"
partnersReferenceIndex.map =
"return {name:record.businessName, phone:record.phone};"
partnersReferenceIndex.allowedRecordNodeIds = [partnerRecord.nodeId]
partnersReferenceIndex.allowedModelNodeIds = [partnerRecord.nodeId]
const partnerCustomersReverseIndex = templateApi.getNewIndexTemplate(
partnerRecord,
@ -212,7 +212,7 @@ export const withFields = (hierarchy, templateApi) => {
partnerCustomersReverseIndex.name = "partnerCustomers"
partnerCustomersReverseIndex.map = "return {...record};"
partnerCustomersReverseIndex.filter = "record.isalive === true"
partnerCustomersReverseIndex.allowedRecordNodeIds = [customerRecord.nodeId]
partnerCustomersReverseIndex.allowedModelNodeIds = [customerRecord.nodeId]
hierarchy.partnerCustomersReverseIndex = partnerCustomersReverseIndex
newCustomerField("surname", "string")
@ -236,7 +236,7 @@ export const withFields = (hierarchy, templateApi) => {
referredToCustomersReverseIndex.map = "return {...record};"
referredToCustomersReverseIndex.getShardName =
"return !record.surname ? 'null' : record.surname.substring(0,1);"
referredToCustomersReverseIndex.allowedRecordNodeIds = [customerRecord.nodeId]
referredToCustomersReverseIndex.allowedModelNodeIds = [customerRecord.nodeId]
hierarchy.referredToCustomersReverseIndex = referredToCustomersReverseIndex
const customerReferredByField = newCustomerField(
@ -295,7 +295,7 @@ export const withFields = (hierarchy, templateApi) => {
)
partnerChargesReverseIndex.name = "partnerCharges"
partnerChargesReverseIndex.map = "return {...record};"
partnerChargesReverseIndex.allowedRecordNodeIds = [chargeRecord]
partnerChargesReverseIndex.allowedModelNodeIds = [chargeRecord]
hierarchy.partnerChargesReverseIndex = partnerChargesReverseIndex
const customersReferenceIndex = templateApi.getNewIndexTemplate(
@ -304,7 +304,7 @@ export const withFields = (hierarchy, templateApi) => {
customersReferenceIndex.name = "customersReference"
customersReferenceIndex.map = "return {name:record.surname}"
customersReferenceIndex.filter = "record.isalive === true"
customersReferenceIndex.allowedRecordNodeIds = [customerRecord.nodeId]
customersReferenceIndex.allowedModelNodeIds = [customerRecord.nodeId]
newInvoiceField("customer", "reference", undefined, {
indexNodeKey: "/customersReference",
@ -328,21 +328,21 @@ export const withIndexes = (hierarchy, templateApi) => {
"return {surname: record.surname, age:record.age};"
deceasedCustomersIndex.filter = "record.isalive === false"
findCollectionDefaultIndex(customerRecord).map = "return record;"
deceasedCustomersIndex.allowedRecordNodeIds = [customerRecord.nodeId]
deceasedCustomersIndex.allowedModelNodeIds = [customerRecord.nodeId]
findCollectionDefaultIndex(invoiceRecord).allowedRecordNodeIds = [
findCollectionDefaultIndex(invoiceRecord).allowedModelNodeIds = [
invoiceRecord.nodeId,
]
findCollectionDefaultIndex(customerRecord).allowedRecordNodeIds = [
findCollectionDefaultIndex(customerRecord).allowedModelNodeIds = [
customerRecord.nodeId,
]
findCollectionDefaultIndex(partnerRecord).allowedRecordNodeIds = [
findCollectionDefaultIndex(partnerRecord).allowedModelNodeIds = [
partnerRecord.nodeId,
]
findIndex(partnerRecord, "partnerInvoices_index").allowedRecordNodeIds = [
findIndex(partnerRecord, "partnerInvoices_index").allowedModelNodeIds = [
partnerInvoiceRecord.nodeId,
]
findCollectionDefaultIndex(chargeRecord).allowedRecordNodeIds = [
findCollectionDefaultIndex(chargeRecord).allowedModelNodeIds = [
chargeRecord.nodeId,
]
@ -350,14 +350,14 @@ export const withIndexes = (hierarchy, templateApi) => {
customerInvoicesIndex.name = "customer_invoices"
customerInvoicesIndex.map = "return record;"
customerInvoicesIndex.filter = "record.type === 'invoice'"
customerInvoicesIndex.allowedRecordNodeIds = [invoiceRecord.nodeId]
customerInvoicesIndex.allowedModelNodeIds = [invoiceRecord.nodeId]
const outstandingInvoicesIndex = getNewIndexTemplate(root)
outstandingInvoicesIndex.name = "Outstanding Invoices"
outstandingInvoicesIndex.filter =
"record.type === 'invoice' && record.paidAmount < record.totalIncVat"
outstandingInvoicesIndex.map = "return {...record};"
outstandingInvoicesIndex.allowedRecordNodeIds = [
outstandingInvoicesIndex.allowedModelNodeIds = [
invoiceRecord.nodeId,
partnerInvoiceRecord.nodeId,
]
@ -403,7 +403,7 @@ export const withIndexes = (hierarchy, templateApi) => {
customersBySurnameIndex.name = "customersBySurname"
customersBySurnameIndex.map = "return {...record};"
customersBySurnameIndex.filter = ""
customersBySurnameIndex.allowedRecordNodeIds = [customerRecord.nodeId]
customersBySurnameIndex.allowedModelNodeIds = [customerRecord.nodeId]
customersBySurnameIndex.getShardName =
"return !record.surname ? 'null' : record.surname.substring(0,1);"
@ -426,7 +426,7 @@ export const withIndexes = (hierarchy, templateApi) => {
invoicesByOutstandingIndex.filter = ""
invoicesByOutstandingIndex.getShardName =
"return (record.totalIncVat > record.paidAmount ? 'outstanding' : 'paid');"
invoicesByOutstandingIndex.allowedRecordNodeIds = [
invoicesByOutstandingIndex.allowedModelNodeIds = [
partnerInvoiceRecord.nodeId,
invoiceRecord.nodeId,
]

View File

@ -55,7 +55,7 @@ describe("canDeleteRecord", () => {
basicAppHierarchyCreator_WithFields
)
appHierarchy.root.indexes = appHierarchy.root.indexes.filter(i => !i.allowedRecordNodeIds.includes(appHierarchy.customerRecord.nodeId))
appHierarchy.root.indexes = appHierarchy.root.indexes.filter(i => !i.allowedModelNodeIds.includes(appHierarchy.customerRecord.nodeId))
const result = canDeleteRecord(appHierarchy.customerRecord)
expect(result.canDelete).toBe(true)

View File

@ -77,8 +77,8 @@ describe("hierarchy node creation", () => {
const root = templateApi.getNewRootLevel()
const parentRecord = templateApi.getNewModelTemplate(root)
const record = templateApi.getNewModelTemplate(parentRecord)
expect(root.indexes[0].allowedRecordNodeIds).toEqual([parentRecord.nodeId])
expect(parentRecord.indexes[0].allowedRecordNodeIds).toEqual([
expect(root.indexes[0].allowedModelNodeIds).toEqual([parentRecord.nodeId])
expect(parentRecord.indexes[0].allowedModelNodeIds).toEqual([
record.nodeId,
])
})

View File

@ -246,11 +246,11 @@ describe("diffHierarchy", () => {
}))
it("should detect root index allowedRecordIds changed", testIndexChanged("root", newSetup => {
newSetup.root.indexes[0].allowedRecordNodeIds.push(3)
newSetup.root.indexes[0].allowedModelNodeIds.push(3)
}))
it("should detect child index allowedRecordIds changed", testIndexChanged("contact", newSetup => {
newSetup.contact.indexes[0].allowedRecordNodeIds.push(3)
newSetup.contact.indexes[0].allowedModelNodeIds.push(3)
}))
it("should detect child index map changed", testIndexChanged("contact", newSetup => {

View File

@ -67,7 +67,7 @@ describe("upgradeData", () => {
const { oldSetup, newSetup } = await configure()
const newIndex = newSetup.templateApi.getNewIndexTemplate(newSetup.root)
newIndex.name = "more_contacts"
newIndex.allowedRecordNodeIds = [newSetup.contact.nodeId]
newIndex.allowedModelNodeIds = [newSetup.contact.nodeId]
await upgradeData(oldSetup.app)(newSetup.root)
@ -112,7 +112,7 @@ describe("upgradeData", () => {
const { oldSetup, newSetup, records } = await configure()
const newIndex = newSetup.templateApi.getNewIndexTemplate(newSetup.contact)
newIndex.name = "more_deals"
newIndex.allowedRecordNodeIds = [newSetup.deal.nodeId]
newIndex.allowedModelNodeIds = [newSetup.deal.nodeId]
await upgradeData(oldSetup.app)(newSetup.root)
@ -159,7 +159,7 @@ describe("upgradeData", () => {
const { oldSetup, newSetup, records, recordApi } = await configure()
const newIndex = newSetup.templateApi.getNewIndexTemplate(newSetup.lead)
newIndex.name = "contact_leads"
newIndex.allowedRecordNodeIds = [newSetup.lead.nodeId]
newIndex.allowedModelNodeIds = [newSetup.lead.nodeId]
newIndex.indexType = "reference"
const leadField = newSetup.templateApi.getNewField("string")

View File

@ -187,7 +187,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [],
"allowedModelNodeIds": [],
"nodeId": 15
}
],
@ -237,7 +237,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [],
"allowedModelNodeIds": [],
"nodeId": 9
},
{
@ -249,7 +249,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [],
"allowedModelNodeIds": [],
"nodeId": 10
},
{
@ -261,7 +261,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [],
"allowedModelNodeIds": [],
"nodeId": 28
}
],
@ -367,7 +367,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [
"allowedModelNodeIds": [
2
],
"nodeId": 23
@ -381,7 +381,7 @@
"getShardName": "return record.username.substring(0,2)",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [
"allowedModelNodeIds": [
16
],
"nodeId": 24
@ -395,7 +395,7 @@
"getShardName": "return record.name.substring(0,2)",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [
"allowedModelNodeIds": [
8
],
"nodeId": 25
@ -409,7 +409,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [
"allowedModelNodeIds": [
3
],
"nodeId": 26
@ -468,7 +468,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [
"allowedModelNodeIds": [
1
],
"nodeId": 22
@ -482,7 +482,7 @@
"getShardName": "return record.username.substring(0,2)",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [
"allowedModelNodeIds": [
17
],
"nodeId": 27

View File

@ -166,7 +166,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [
"allowedModelNodeIds": [
1
],
"nodeId": 2
@ -180,7 +180,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [
"allowedModelNodeIds": [
3
],
"nodeId": 4
@ -194,7 +194,7 @@
"getShardName": "",
"getSortKey": "record.id",
"aggregateGroups": [],
"allowedRecordNodeIds": [
"allowedModelNodeIds": [
7
],
"nodeId": 8