EntityDetail.jsx 728 Bytes
Newer Older
Jaden's avatar
Jaden committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// @flow
import React from 'react';
import {
	Container,
	Row,
	Col,
} from 'reactstrap';


import {
	Route,
	Link
} from 'react-router-dom';

type Props = {
	instance: any
};

const EntityDetail = ({ instance }: Props) => (
	<pre>{ JSON.stringify(instance) }</pre>
);

export default EntityDetail;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

const name = (params: any) => Object.values(params).join('/');

export const mapParamsToData = (params: string[], data: any) => {
	let obj = {};
	if(Object.keys(data).length > 0){
		const arr: any[] = (
			params.slice(0, -1)
			.reduce((o: any, p) => o[p], JSON.parse(JSON.stringify(data))): any
		);

		obj = arr.find(o => o.name === name(params));
	}

	return obj;
};

export type DetailProps = {
	match: any,
	data: any,
};