@skbkontur/db-viewer-ui
Version:
Database Viewer with custom configuration
68 lines • 2.76 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropertyMetaInformationUtils = void 0;
const tslib_1 = require("tslib");
const edi_ui_1 = require("@skbkontur/edi-ui");
const flatten_1 = tslib_1.__importDefault(require("lodash/flatten"));
const defaultType = {
isNullable: false,
isArray: false,
genericTypeArguments: [],
properties: [],
typeName: "Object",
originalTypeName: "Object",
};
const defaultProperty = {
name: "",
type: defaultType,
isEditable: true,
isIdentity: false,
isSearchable: false,
isSortable: false,
isRequired: false,
availableFilters: [],
availableValues: [],
};
class PropertyMetaInformationUtils {
static hasFilledRequiredFields(conditions, properties) {
const required = properties.filter(x => x.isRequired).map(x => x.name);
for (const property of required) {
const condition = conditions.filter(x => x.path === property)[0];
if (edi_ui_1.StringUtils.isNullOrWhitespace(condition === null || condition === void 0 ? void 0 : condition.value)) {
return false;
}
}
return true;
}
static getProperties(properties, prevName = "") {
const props = [];
properties.map(item => {
if (item.type != null && item.type.properties.length !== 0) {
props.push(...this.getProperties(item.type.properties, prevName ? `${prevName}.${item.name}` : item.name));
}
else {
props.push(Object.assign(Object.assign({}, item), { name: prevName ? `${prevName}.${item.name}` : item.name }));
}
});
return (0, flatten_1.default)(props);
}
static getPropertyTypeByPath(type, path) {
const [first, ...rest] = path;
const property = type.properties.find(x => x.name === first);
if (property == null && type.isArray) {
if (rest.length === 0) {
return Object.assign(Object.assign({}, defaultProperty), { name: "[]", type: type.genericTypeArguments[type.genericTypeArguments.length - 1] });
}
return this.getPropertyTypeByPath(type.genericTypeArguments[0], rest);
}
if (property == null) {
return Object.assign(Object.assign({}, defaultProperty), { name: first, type: Object.assign(Object.assign({}, defaultType), { typeName: rest.length === 0 ? "String" : "Object" }) });
}
if (rest.length === 0) {
return property;
}
return this.getPropertyTypeByPath(property.type, rest);
}
}
exports.PropertyMetaInformationUtils = PropertyMetaInformationUtils;
//# sourceMappingURL=PropertyMetaInformationUtils.js.map
;