@skbkontur/db-viewer-ui
Version:
Database Viewer with custom configuration
52 lines • 3.73 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObjectTypes = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const edi_ui_1 = require("@skbkontur/edi-ui");
const react_ui_1 = require("@skbkontur/react-ui");
const lodash_1 = tslib_1.__importDefault(require("lodash"));
const react_1 = tslib_1.__importDefault(require("react"));
const ObjectLink_1 = require("./ObjectLink");
const ObjectTypes_styles_1 = require("./ObjectTypes.styles");
function ObjectTypes({ objects, filter, identifierKeywords }) {
const theme = react_1.default.useContext(react_ui_1.ThemeContext);
const getIdentifierWithoutKeywords = (identifier) => {
let result = identifier;
for (const keyword of identifierKeywords) {
result = result.replace(keyword, "");
}
return result;
};
const getGrouped = (objects) => {
return (0, lodash_1.default)(objects)
.orderBy(item => getIdentifierWithoutKeywords(item.identifier).toUpperCase())
.groupBy(item => getIdentifierWithoutKeywords(item.identifier)[0].toUpperCase())
.toPairs()
.value();
};
const getFiltered = (objects, filter) => {
return objects.filter(item => edi_ui_1.StringUtils.checkWordByCase(item.identifier, filter));
};
const renderTypes = (objects, displayGroups) => {
if (!displayGroups) {
return ((0, jsx_runtime_1.jsx)("div", { className: ObjectTypes_styles_1.jsStyles.root(), "data-tid": "ObjectsList", children: objects.map(item => ((0, jsx_runtime_1.jsx)(ObjectLink_1.ObjectLink, { identifier: item.identifier, keywords: identifierKeywords }, item.identifier))) }));
}
const groupedObjects = getGrouped(objects);
return ((0, jsx_runtime_1.jsx)("div", { "data-tid": "ObjectsList", className: ObjectTypes_styles_1.jsStyles.root(), children: groupedObjects.map(([firstLetter, identifiers], key) => ((0, jsx_runtime_1.jsxs)("div", { className: ObjectTypes_styles_1.jsStyles.typeGroup(), children: [(0, jsx_runtime_1.jsx)("div", { className: ObjectTypes_styles_1.jsStyles.firstLetter(theme), "data-tid": "FirstLetter", children: firstLetter }), identifiers.map(item => ((0, jsx_runtime_1.jsx)(ObjectLink_1.ObjectLink, { identifier: item.identifier, keywords: identifierKeywords }, item.identifier)))] }, key))) }));
};
const renderSchema = (schemaName, objects) => {
var _a;
const schema = (_a = objects[0]) === null || _a === void 0 ? void 0 : _a.schemaDescription;
let filteredObjects = objects;
const emptyFilter = edi_ui_1.StringUtils.isNullOrWhitespace(filter);
if (!emptyFilter) {
filteredObjects = getFiltered(objects, filter);
}
return (filteredObjects.length !== 0 && ((0, jsx_runtime_1.jsxs)("div", { "data-tid": "ObjectGroup", children: [(0, jsx_runtime_1.jsxs)("div", { className: ObjectTypes_styles_1.jsStyles.schema(theme), children: [(0, jsx_runtime_1.jsx)("span", { "data-tid": "Name", children: schemaName }), " ", schema.allowReadAll && ((0, jsx_runtime_1.jsx)("span", { className: ObjectTypes_styles_1.jsStyles.indexed(), "data-tid": "IndexedLabel", children: "indexed" }))] }), (0, jsx_runtime_1.jsx)("div", { children: renderTypes(filteredObjects, emptyFilter) })] }, schemaName)));
};
const categorized = lodash_1.default.groupBy(objects, x => x.schemaDescription.schemaName);
return ((0, jsx_runtime_1.jsx)("div", { "data-tid": "ObjectGroups", children: Object.keys(categorized).map(schemaName => renderSchema(schemaName, categorized[schemaName])) }));
}
exports.ObjectTypes = ObjectTypes;
//# sourceMappingURL=ObjectTypes.js.map
;