WIP fixing the explorer

pull/98/head
Will Piers 2016-09-20 16:46:03 -07:00 committed by Andrew Watkins
parent 9fcf4f36fd
commit 64b658b633
7 changed files with 34 additions and 18 deletions

View File

@ -100,11 +100,17 @@ func (m *Handler) Explorations(ctx context.Context, params op.GetSourcesIDUsersU
} }
res := &models.Explorations{} res := &models.Explorations{}
for _, e := range exs { for _, e := range exs {
rel := "self"
href := "/chronograf/v1/source/1/users/1/explorations/1"
res.Explorations = append(res.Explorations, &models.Exploration{ res.Explorations = append(res.Explorations, &models.Exploration{
Data: e.Data, Data: e.Data,
Name: e.Name, Name: e.Name,
UpdatedAt: strfmt.DateTime(e.UpdatedAt), UpdatedAt: strfmt.DateTime(e.UpdatedAt),
CreatedAt: strfmt.DateTime(e.CreatedAt), CreatedAt: strfmt.DateTime(e.CreatedAt),
Link: &models.Link{
Rel: &rel,
Href: &href,
},
}, },
) )
} }

View File

@ -19,10 +19,8 @@ func NewExplorationStore(nowFunc func() time.Time) mrfusion.ExplorationStore {
db: map[int]mrfusion.Exploration{}, db: map[int]mrfusion.Exploration{},
} }
e.db[1] = mrfusion.Exploration{ e.db[1] = mrfusion.Exploration{
ID: 1,
Name: "Ferdinand Magellan", Name: "Ferdinand Magellan",
UserID: 1, Data: "{\"panels\":{\"123\":{\"id\":\"123\",\"queryIds\":[\"456\"]}},\"queryConfigs\":{\"456\":{\"id\":\"456\",\"database\":null,\"measurement\":null,\"retentionPolicy\":null,\"fields\":[],\"tags\":{},\"groupBy\":{\"time\":null,\"tags\":[]},\"areTagsAccepted\":true,\"rawText\":null}}}",
Data: `"{\"panels\":{\"123\":{\"id\":\"123\",\"queryIds\":[\"456\"]}},\"queryConfigs\":{\"456\":{\"id\":\"456\",\"database\":null,\"measurement\":null,\"retentionPolicy\":null,\"fields\":[],\"tags\":{},\"groupBy\":{\"time\":null,\"tags\":[]},\"areTagsAccepted\":true,\"rawText\":null}}}"`,
CreatedAt: nowFunc(), CreatedAt: nowFunc(),
UpdatedAt: nowFunc(), UpdatedAt: nowFunc(),
} }

View File

@ -15,7 +15,6 @@ import (
swagger:model Exploration swagger:model Exploration
*/ */
type Exploration struct { type Exploration struct {
/* created at /* created at
*/ */
CreatedAt strfmt.DateTime `json:"created_at,omitempty"` CreatedAt strfmt.DateTime `json:"created_at,omitempty"`

View File

@ -47,13 +47,13 @@ const CheckDataNodes = React.createClass({
} }
const {source} = this.state; const {source} = this.state;
if (!source || !source.links.proxy) { if (!source) {
// this should probably be changed.... // this should probably be changed....
return <NoClusterError />; return <NoClusterError />;
} }
return this.props.children && React.cloneElement(this.props.children, Object.assign({}, this.props, { return this.props.children && React.cloneElement(this.props.children, Object.assign({}, this.props, {
proxyLink: source.links.proxy, source,
})); }));
}, },
}); });

View File

@ -231,16 +231,15 @@ export function fetchExplorers({sourceLink, userID, explorerID, push}) {
return (dispatch) => { return (dispatch) => {
dispatch({type: 'FETCH_EXPLORERS'}); dispatch({type: 'FETCH_EXPLORERS'});
AJAX({ AJAX({
url: `/chronograf/v1/sources/1/users/1/explorations`, url: `${sourceLink}/users/${userID}/explorations`,
}).then(({data: {explorations}}) => { }).then(({data: {explorations}}) => {
debugger;
const explorers = explorations.map(parseRawExplorer); const explorers = explorations.map(parseRawExplorer);
dispatch(loadExplorers(explorers)); dispatch(loadExplorers(explorers));
// Create a new explorer session for a user if they don't have any // Create a new explorer session for a user if they don't have any
// saved (e.g. when they visit for the first time). // saved (e.g. when they visit for the first time).
if (!explorers.length) { if (!explorers.length) {
dispatch(createExplorer(clusterID, push)); dispatch(createExplorer(push));
return; return;
} }
@ -250,7 +249,7 @@ export function fetchExplorers({sourceLink, userID, explorerID, push}) {
if (!explorerID) { if (!explorerID) {
const explorer = _.maxBy(explorers, (ex) => ex.updated_at); const explorer = _.maxBy(explorers, (ex) => ex.updated_at);
dispatch(loadExplorer(explorer)); dispatch(loadExplorer(explorer));
push(`/chronograf/data_explorer/${explorer.id}`); push(`/chronograf/data_explorer/${encodeURIComponent(explorer.link.href)}`);
return; return;
} }

View File

@ -6,7 +6,12 @@ import DataExplorer from './DataExplorer';
const App = React.createClass({ const App = React.createClass({
propTypes: { propTypes: {
proxyLink: PropTypes.string.isRequired, source: PropTypes.shape({
links: PropTypes.shape({
proxy: PropTypes.string.isRequired,
self: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,
fetchExplorers: PropTypes.func.isRequired, fetchExplorers: PropTypes.func.isRequired,
router: PropTypes.shape({ router: PropTypes.shape({
push: PropTypes.func.isRequired, push: PropTypes.func.isRequired,
@ -19,8 +24,8 @@ const App = React.createClass({
componentDidMount() { componentDidMount() {
const {explorerID} = this.props.params; const {explorerID} = this.props.params;
this.props.fetchExplorers({ this.props.fetchExplorers({
sourceLink: 'linkgoesheres', // source.links.self sourceLink: this.props.source.links.self,
userID: 1, // userID userID: 1, // TODO: get the userID
explorerID: Number(explorerID), explorerID: Number(explorerID),
push: this.props.router.push, push: this.props.router.push,
}); });
@ -30,7 +35,7 @@ const App = React.createClass({
const {explorerID} = this.props.params; const {explorerID} = this.props.params;
return ( return (
<div className="data-explorer-container"> <div className="data-explorer-container">
<DataExplorer proxyLink={this.props.proxyLink} explorerID={Number(explorerID)} /> <DataExplorer source={this.props.source} explorerID={Number(explorerID)} />
</div> </div>
); );
}, },

View File

@ -16,14 +16,18 @@ import {
const DataExplorer = React.createClass({ const DataExplorer = React.createClass({
propTypes: { propTypes: {
proxyLink: PropTypes.string.isRequired, source: PropTypes.shape({
links: PropTypes.shape({
proxy: PropTypes.string.isRequired,
self: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,
timeRange: PropTypes.shape({ timeRange: PropTypes.shape({
upper: PropTypes.string, upper: PropTypes.string,
lower: PropTypes.string, lower: PropTypes.string,
}).isRequired, }).isRequired,
explorers: PropTypes.shape({}).isRequired, explorers: PropTypes.shape({}).isRequired,
explorerID: PropTypes.number.isRequired, explorerID: PropTypes.number.isRequired,
clusterID: PropTypes.string.isRequired,
setTimeRange: PropTypes.func.isRequired, setTimeRange: PropTypes.func.isRequired,
createExplorer: PropTypes.func.isRequired, createExplorer: PropTypes.func.isRequired,
chooseExplorer: PropTypes.func.isRequired, chooseExplorer: PropTypes.func.isRequired,
@ -32,11 +36,16 @@ const DataExplorer = React.createClass({
}, },
childContextTypes: { childContextTypes: {
proxyLink: PropTypes.string, source: PropTypes.shape({
links: PropTypes.shape({
proxy: PropTypes.string.isRequired,
self: PropTypes.string.isRequired,
}).isRequired,
}).isRequired,
}, },
getChildContext() { getChildContext() {
return {proxyLink: this.props.proxyLink}; return {source: this.props.source};
}, },
getInitialState() { getInitialState() {