UNPKG

@backstage/plugin-techdocs

Version:

The Backstage plugin that renders technical documentation for your components

82 lines (79 loc) 2.57 kB
import { jsx, Fragment } from 'react/jsx-runtime'; import { SubvalueCell, Link } from '@backstage/core-components'; import { EntityRefLinks } from '@backstage/plugin-catalog-react'; import { useTranslationRef } from '@backstage/core-plugin-api/alpha'; import { techdocsTranslationRef } from '../../../translation.esm.js'; function customTitle(entity) { return entity.metadata.title || entity.metadata.name; } const TableColumnTitle = ({ translationKey }) => { const { t } = useTranslationRef(techdocsTranslationRef); return /* @__PURE__ */ jsx(Fragment, { children: t(`table.columns.${translationKey}`) }); }; const columnFactories = { createTitleColumn(options) { const nameCol = columnFactories.createNameColumn(); return { ...nameCol, field: "entity.metadata.title", hidden: options?.hidden }; }, createNameColumn() { return { title: /* @__PURE__ */ jsx(TableColumnTitle, { translationKey: "document" }), field: "entity.metadata.name", highlight: true, searchable: true, defaultSort: "asc", customSort: (row1, row2) => { const title1 = customTitle(row1.entity).toLocaleLowerCase(); const title2 = customTitle(row2.entity).toLocaleLowerCase(); return title1.localeCompare(title2); }, render: (row) => /* @__PURE__ */ jsx( SubvalueCell, { value: /* @__PURE__ */ jsx(Link, { to: row.resolved.docsUrl, children: customTitle(row.entity) }), subvalue: row.entity.metadata.description } ) }; }, createOwnerColumn() { return { title: /* @__PURE__ */ jsx(TableColumnTitle, { translationKey: "owner" }), field: "resolved.ownedByRelationsTitle", render: ({ resolved }) => /* @__PURE__ */ jsx( EntityRefLinks, { entityRefs: resolved.ownedByRelations, defaultKind: "group" } ) }; }, createKindColumn() { return { title: /* @__PURE__ */ jsx(TableColumnTitle, { translationKey: "kind" }), field: "entity.kind" }; }, createTypeColumn() { return { title: /* @__PURE__ */ jsx(TableColumnTitle, { translationKey: "type" }), field: "entity.spec.type" }; } }; const defaultColumns = [ columnFactories.createTitleColumn({ hidden: true }), columnFactories.createNameColumn(), columnFactories.createOwnerColumn(), columnFactories.createKindColumn(), columnFactories.createTypeColumn() ]; export { columnFactories, defaultColumns }; //# sourceMappingURL=columns.esm.js.map