@kineticdata/react
Version:
A React library for the Kinetic Platform
96 lines (95 loc) • 4.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getUsedFields = exports.getRemainingParts = exports.availableParts = void 0;
var _immutable = require("immutable");
var _helpers = require("../../../helpers");
var getUsedFields = exports.getUsedFields = function getUsedFields(values, partIndex) {
var partType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'eq';
var equalities = (0, _immutable.List)();
if (partType === 'eq' && partIndex === 0) {
equalities = (0, _immutable.List)();
} else if (partType === 'eq' && partIndex === 1) {
equalities = (0, _immutable.List)([values.get('op0-part')]);
} else if (partType === 'eq') {
equalities = (0, _immutable.Range)(0, partIndex).map(function (i) {
return values.get("op".concat(i, "-part"));
}).toList().filter(function (f) {
return f !== '';
});
} else if (partType === 'range') {
var orders = (0, _immutable.Range)(0, _helpers.MAX_PART_LENGTH).map(function (i) {
return values.get("orderby".concat(i, "-part"));
}).toList().filter(function (f) {
return f !== '' && f !== values.get('range-part');
});
equalities = (0, _immutable.Range)(0, _helpers.MAX_PART_LENGTH).map(function (i) {
return values.get("op".concat(i, "-part"));
}).toList().concat(orders).filter(function (f) {
return f !== '';
});
} else if (partType === 'orderBy') {
var _orders;
if (partIndex === 0) {
_orders = (0, _immutable.List)();
} else if (partIndex === 1) {
_orders = (0, _immutable.List)([values.get('orderby0-part')]);
} else {
_orders = (0, _immutable.Range)(0, partIndex).map(function (i) {
return values.get("orderby".concat(i, "-part"));
}).toList().filter(function (f) {
return f !== '';
});
}
equalities = (0, _immutable.Range)(0, _helpers.MAX_PART_LENGTH).map(function (i) {
return values.get("op".concat(i, "-part"));
}).toList().concat(_orders).filter(function (f) {
return f !== '';
});
}
return equalities;
};
var availableParts = exports.availableParts = function availableParts(values, indexes, equalityFields) {
var partType = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'eq';
var remainingParts = indexes.map(function (index) {
return getRemainingParts(index.get('parts', (0, _immutable.List)()), equalityFields);
});
var containsTimeline = equalityFields.some(function (index) {
return _helpers.TIMELINES.includes(index);
});
var anyAtLast = remainingParts.some(function (index) {
return index && index.size === 0;
});
var rangePart = values.get('range-part');
var timelinesAvailable = anyAtLast && !containsTimeline ? _helpers.TIMELINES : containsTimeline ? getRemainingParts((0, _immutable.List)([equalityFields.last()]), (0, _immutable.fromJS)(_helpers.TIMELINES)) : (0, _immutable.List)();
if (partType === 'range') {
var rangeRemaining = remainingParts.filter(function (index) {
return index && index.size === 1;
});
return rangeRemaining.concat(rangePart && rangeRemaining.size === 0 && values.get('orderby0-part') && values.get('orderby0-part') !== rangePart ? (0, _immutable.List)([]) : timelinesAvailable || (0, _immutable.List)([]));
} else if (partType === 'orderBy') {
return (rangePart ? (0, _immutable.List)([rangePart]) : remainingParts.filter(function (index) {
return index && index.size > 0;
}).map(function (index) {
return index.first();
})).concat(_helpers.TIMELINES.includes(rangePart) ? (0, _immutable.List)([rangePart]) : anyAtLast ? (0, _immutable.fromJS)(_helpers.TIMELINES) : equalityFields.size === 0 ? (0, _immutable.fromJS)(_helpers.TIMELINES) : (0, _immutable.List)()).toSet().toList();
} else {
return remainingParts.filterNot(function (index) {
return !index || index.size === 0;
}).map(function (index) {
return index.first();
}).toSet().toList().filterNot(function (p) {
return _helpers.TIMELINES.includes(p);
});
}
};
var getRemainingParts = exports.getRemainingParts = function getRemainingParts(src, dst) {
if (src.size === 0 && dst.size === 0) return (0, _immutable.List)();
// If we're matching so far, and the are no more to compare it's a match.
if (src.size > 0 && dst.size === 0) return src;
// If we're out of elements but there's more to match, it's not a match.
if (src.size === 0 && dst.size > 0) return (0, _immutable.List)();
if (src.first() === dst.first()) return getRemainingParts(src.shift(), dst.shift());
return null;
};