Commit 28d24d8b authored by Jaden DIEFENBAUGH's avatar Jaden DIEFENBAUGH
Browse files

[js] show objects paths, #104

parent 114e4504
Pipeline #20176 passed with stages
in 63 minutes and 13 seconds
......@@ -97,6 +97,16 @@ class Templates(Resource):
utils.generate_python_template(entity, name, self.config, **data)
class Settings(Resource):
"""Exposes the prefix"""
def __init__(self, config):
self.config = config
def get(self):
"""Uses beat.cmdline to get the prefix"""
return { 'prefix': self.config.path }
def path_to_dict(path):
"""Generates a dict of the given file/folder in the BEAT prefix"""
......
......@@ -106,7 +106,7 @@ def main(user_input=None):
from flask import Flask, request, redirect, url_for
from flask_restful import Api
from flask_cors import CORS
from ..resources import Layout, Templates, Environments
from ..resources import Layout, Templates, Environments, Settings
from ..resources import VALID_ENTITIES, gen_endpoint
static_folder = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../js')
......@@ -120,6 +120,7 @@ def main(user_input=None):
api.add_resource(Layout, '/layout', resource_class_kwargs={'config': config})
api.add_resource(Templates, '/templates', resource_class_kwargs={'config': config})
api.add_resource(Settings, '/settings', resource_class_kwargs={'config': config})
api.add_resource(Environments, '/environments')
for entity in VALID_ENTITIES:
api.add_resource(gen_endpoint(entity), '/' + entity,
......
......@@ -9,6 +9,9 @@ import {
Nav,
NavItem,
NavLink,
Input,
InputGroupAddon,
InputGroup,
} from 'reactstrap';
import { connect } from 'react-redux';
......@@ -24,7 +27,7 @@ import {
} from 'react-router-dom';
import type { BeatObject, BeatEntity } from '@helpers/beat';
import { getDefaultEntityObject } from '@helpers/beat';
import { getDefaultEntityObject, pluralize } from '@helpers/beat';
import { genModuleApiFuncs } from '@helpers/api';
import ValidSchemaBadge from './ValidSchemaBadge.jsx';
......@@ -50,6 +53,8 @@ type Props = {
updateFunc: (BeatObject) => any,
// the current BEAT entity being show
entity: BeatEntity,
// the absolute path to the user's prefix folder
prefix: string,
};
// 3 tabs so far: editor, docs, raw json
......@@ -84,21 +89,31 @@ export class EntityDetail extends React.Component<Props, State> {
}
render () {
const name = this.props.match.params.name;
return (
<Container>
<Row>
{/* title line (name & validation info) */}
<Row className='mb-1'>
<Col>
<h4 style={{'textAlign': 'center'}}>
{/* title line (name & validation info) */}
<h4 className='text-center'>
<span style={{'textTransform': 'capitalize'}}>
{ this.props.entity }
</span>
{' '}
<pre style={{display: 'inline'}}>
{ this.props.getEntityObject().name }
{ name }
</pre>
<ValidSchemaBadge entity={this.props.entity} obj={this.props.getEntityObject()} />
</h4>
{/* path line */}
<InputGroup>
<InputGroupAddon addonType='prepend'>Path:</InputGroupAddon>
<Input
readOnly
width='80'
value={`${ this.props.prefix }/${ pluralize(this.props.entity) }/${ name }`}
/>
</InputGroup>
</Col>
</Row>
<Row>
......@@ -116,14 +131,6 @@ export class EntityDetail extends React.Component<Props, State> {
<NavLink
className={cn({ active: this.state.activeTab === '1' })}
onClick={() => this.switchToTab('1')}
>
Documentation
</NavLink>
</NavItem>
<NavItem>
<NavLink
className={cn({ active: this.state.activeTab === '2' })}
onClick={() => this.switchToTab('2')}
>
Raw JSON
</NavLink>
......@@ -190,13 +197,6 @@ export class EntityDetail extends React.Component<Props, State> {
}
</TabPane>
<TabPane tabId='1'>
<Row>
<Col>
<h4 style={{textAlign: 'center'}}>Under construction 😄</h4>
</Col>
</Row>
</TabPane>
<TabPane tabId='2'>
<pre>{ JSON.stringify(this.props.getEntityObject(), null, 4) }</pre>
</TabPane>
</TabContent>
......@@ -217,6 +217,7 @@ const mapStateToProps = (state, ownProps) => {
// if the obj doesnt exist (huge edge case) just return a default obj to not break everything
getEntityObject: (): BeatObject => Selectors[`${ entity }Get`](state).find(o => o.name === name) || getDefaultEntityObject(),
entity,
prefix: Selectors.settingsGet(state).prefix,
};
return obj;
......
......@@ -40,6 +40,10 @@ export const fetchAllObjects: ActionThunkCreator = () => async (dispatch: Dispat
dispatch(plotterparameterSave(arrs[7]));
dispatch(clearUnsaved());
const settingsGet = genModuleApiFuncs('settings').get;
const settingsJson = await settingsGet();
dispatch(settingsSave(settingsJson));
const envGet = genModuleApiFuncs('environments').get;
const envJson = await envGet();
dispatch(environmentsSave(envJson));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment