@@ -4,11 +4,12 @@ import { get as getPandasCsv } from "@wq/pandas";
44import Mustache from "mustache" ;
55import { labelWithIcon } from "./components/Icon.jsx" ;
66
7- export function useAnalyst ( ) {
8- const config = useAnalystConfig ( ) ,
7+ export function useAnalyst ( props ) {
8+ const config = useAnalystConfig ( props ) ,
99 [ data , dataError ] = useAnalystData (
1010 config . url || null ,
1111 config . data || null ,
12+ config . fields || null ,
1213 ) ,
1314 modes = useAnalystModes ( data , config ) ,
1415 [ form , options , setOptions ] = useAnalystForm ( modes ) ;
@@ -24,16 +25,24 @@ export function useAnalyst() {
2425 } ;
2526}
2627
27- export function useAnalystConfig ( ) {
28+ export function useAnalystConfig ( props ) {
2829 const {
29- page_config : { name, analyst = { } } ,
30+ page_config : { name, analyst : routeProps } ,
3031 } = useRouteInfo ( ) ,
3132 context = useRenderContext ( ) ;
3233
34+ const analyst = { ...routeProps , ...props } ;
35+
3336 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+ }
3746 }
3847
3948 return {
@@ -44,6 +53,7 @@ export function useAnalystConfig() {
4453 : analyst . initial_order ,
4554 url : render ( analyst . url , context ) ,
4655 title : render ( analyst . title , context ) ,
56+ id_url_prefix : render ( analyst . id_url_prefix , context ) ,
4757 } ;
4858}
4959
@@ -55,7 +65,7 @@ function render(value, context) {
5565 }
5666}
5767
58- export function useAnalystData ( url , initialData ) {
68+ export function useAnalystData ( url , initialData , fields ) {
5969 const [ data , setData ] = useState ( initialData ) ,
6070 [ error , setError ] = useState ( null ) ;
6171
@@ -65,7 +75,7 @@ export function useAnalystData(url, initialData) {
6575 }
6676 async function loadData ( ) {
6777 try {
68- const data = await getPandasCsv ( url , { flatten : true } ) ;
78+ const data = await getPandasCsv ( url , { flatten : true , fields } ) ;
6979 if ( data && data . length > 0 ) {
7080 setData ( data ) ;
7181 } else {
0 commit comments