Skip to content

Commit

Permalink
feat(function): Add relationship field type to fieldData
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Sep 28, 2024
1 parent 06e4402 commit 98954d4
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/functions/FieldData.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { Link, NavLink } from "react-router-dom";
import RenderMarkdown from "./RenderMarkdown";



/**
* Value used to split URL.
*
* i.e. `http://127.0.0.1:8002/api/v2/itam/device/24` using ulr[1] would return `/itam/device/24`
*/
const API_SPLIT = String('api/v2')

/**
* Fetch the field data from Django API Data
*
Expand Down Expand Up @@ -72,6 +82,7 @@ export default function FieldData({

break;

case 'Relationship':
case 'Serializer':

if( data[field_name] === null ) {
Expand All @@ -80,7 +91,17 @@ export default function FieldData({

} else {

field_data = data[field_name].name
if( 'url' in data[field_name] ) {

field_data = (
<Link to={String(data[field_name].url).split(API_SPLIT)[1]}>{data[field_name].display_name}</Link>
)

} else {

field_data = data[field_name].display_name

}

}

Expand Down

0 comments on commit 98954d4

Please sign in to comment.