All Downloads are FREE. Search and download functionalities are using the official Maven repository.

components.breadcrumbs.utils.breadcrumb.ts Maven / Gradle / Ivy

There is a newer version: 0.80.3
Show newest version
import { createDetailUrl } from 'components/view/utils/view';
import { toRefMenuInfo } from 'contexts/utils/menu';
import { T } from 'helpers/translator';
import { Notifier } from 'hooks/notification';

export function listSectionToCrumb(translator: T, notifier: Notifier, section: any) {
  const info  = toRefMenuInfo(translator, notifier, section.fqk)
  const link  = info?.href

  return {key: section.key, label: section.label, link, type: "list"}
}

export function detailRowToCrumb(row: any, detail: string, id: string) {
  function primaryAttempt(row: any) {
    const priority = ["name", "description", "client", "identification", "value", "user", "username"]

    const reducer = (computed: boolean, name: string) =>  computed || row.hasOwnProperty(name) && row[name]
    const label   = priority.reduce(reducer, false)

    return label ? { label } : undefined
  }
  
  const crumb = primaryAttempt(row)
  const link  = createDetailUrl(detail, id) 

  return {...crumb, link, type: "detail", key: detail}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy