import get from 'lodash/get' ; import { linkToRecord } from '../../util' ; import { Record } from '../../types' ; export type LinkToFunctionType = ( record : Record , reference : string ) => string ; export type LinkToType = string | boolean | LinkToFunctionType ; interface Option { source : string ; reference : string ; resource : string ; basePath ? : string ; record ? : Record ; link ? : LinkToType ; deprecated linkType ? : LinkToType ; } example param option param { string } option . basePath param { string | false | LinkToFunctionType } option . link param { string | false | LinkToFunctionType } option . linkType param { string } option . reference param { Object } option . record param { string } option . resource param { string } option . source returns { string | false } const getResourceLinkPath = ( { resource , source , reference , link = 'edit' , record = { id : '' } , basePath = '' , linkType , } ) : string | false => { if ( linkType !== undefined ) { console . warn ( "The 'linkType' prop is deprecated and should be named to 'link' in <ReferenceField />" ) ; } const sourceId = get ( record , source ) ; const rootPath = basePath ? basePath . replace ( resource , reference ) : `/${ reference }` ; const linkTo = linkType !== undefined ? linkType : link ; return ! linkTo ? false : typeof linkTo === 'function' ? linkTo ( record , reference ) : linkToRecord ( rootPath , sourceId , linkTo as string ) ; } ; export default getResourceLinkPath ;