@@ -4,11 +4,12 @@ import { get as getPandasCsv } from "@wq/pandas";
4
4
import Mustache from "mustache" ;
5
5
import { labelWithIcon } from "./components/Icon.jsx" ;
6
6
7
- export function useAnalyst ( ) {
8
- const config = useAnalystConfig ( ) ,
7
+ export function useAnalyst ( props ) {
8
+ const config = useAnalystConfig ( props ) ,
9
9
[ data , dataError ] = useAnalystData (
10
10
config . url || null ,
11
11
config . data || null ,
12
+ config . fields || null ,
12
13
) ,
13
14
modes = useAnalystModes ( data , config ) ,
14
15
[ form , options , setOptions ] = useAnalystForm ( modes ) ;
@@ -24,16 +25,24 @@ export function useAnalyst() {
24
25
} ;
25
26
}
26
27
27
- export function useAnalystConfig ( ) {
28
+ export function useAnalystConfig ( props ) {
28
29
const {
29
- page_config : { name, analyst = { } } ,
30
+ page_config : { name, analyst : routeProps } ,
30
31
} = useRouteInfo ( ) ,
31
32
context = useRenderContext ( ) ;
32
33
34
+ const analyst = { ...routeProps , ...props } ;
35
+
33
36
if ( ! analyst . url ) {
34
- return {
35
- error : `The config for "${ name } " should include an analyst.url property.` ,
36
- } ;
37
+ if ( routeProps ) {
38
+ return {
39
+ error : `The config for "${ name } " should include an analyst.url property.` ,
40
+ } ;
41
+ } else {
42
+ return {
43
+ error : `Specify analyst.url in the config for "${ name } " or as a prop.` ,
44
+ } ;
45
+ }
37
46
}
38
47
39
48
return {
@@ -44,6 +53,7 @@ export function useAnalystConfig() {
44
53
: analyst . initial_order ,
45
54
url : render ( analyst . url , context ) ,
46
55
title : render ( analyst . title , context ) ,
56
+ id_url_prefix : render ( analyst . id_url_prefix , context ) ,
47
57
} ;
48
58
}
49
59
@@ -55,7 +65,7 @@ function render(value, context) {
55
65
}
56
66
}
57
67
58
- export function useAnalystData ( url , initialData ) {
68
+ export function useAnalystData ( url , initialData , fields ) {
59
69
const [ data , setData ] = useState ( initialData ) ,
60
70
[ error , setError ] = useState ( null ) ;
61
71
@@ -65,7 +75,7 @@ export function useAnalystData(url, initialData) {
65
75
}
66
76
async function loadData ( ) {
67
77
try {
68
- const data = await getPandasCsv ( url , { flatten : true } ) ;
78
+ const data = await getPandasCsv ( url , { flatten : true , fields } ) ;
69
79
if ( data && data . length > 0 ) {
70
80
setData ( data ) ;
71
81
} else {
0 commit comments