Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 19 additions & 6 deletions modules/presets/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function addHistoricalFields(fields) {

for (let i = 1; i < 4; i++){
let id = 'source:' + i.toString();
let previousId = 'source' + ((i-1) > 0 ? ':' + (i-1).toString() : '');
fields[id] = {
...fields.source,
key: id,
Expand All @@ -72,11 +71,25 @@ function addHistoricalFields(fields) {
baseKey: 'source',
index: i,
prerequisiteTag: {
keys: [
previousId,
previousId + ':url',
previousId + ':name',
previousId + ':date']}};
prerequisiteFunction: (tag) => {
let sourceRegex = /^source/;
if (tag.match(sourceRegex) ){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let sourceRegex = /^source/;
if (tag.match(sourceRegex) ){
if (tag.startsWith('source')) {

// allow index 1 if there are any source tags present
if (i === 1){
return true;
} else {
// for index > 1, get the index in the tag with a regex
let indexRegex = /(?<=\:)\d+/;
let regexMatch = parseInt(tag.match(indexRegex), 10);
// allow index i if the index directly before it is present OR if any index above it is present
if (regexMatch === i-1 || regexMatch > i){
return true;
}
}
}
return false;
}}
};
}
}

Expand Down
4 changes: 4 additions & 0 deletions modules/ui/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ export function uiField(context, presetField, entityIDs, options) {

if (!entityIDs.every(function(entityID) {
var entity = context.graph().entity(entityID);
if (prerequisiteTag.prerequisiteFunction) {
// Return true if prerequisiteFunction returns true for any tag
return Object.keys(entity.tags).some(prerequisiteTag.prerequisiteFunction);
}
if (prerequisiteTag.keys) {
// Return true if any key in prerequisiteTag.keys is present, return false otherwise
// If prerequisiteTag.keys is present, prerequisiteTag.key will be ignored
Expand Down
Loading