Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to save time with dashboard #3164

Merged
merged 12 commits into from
Apr 23, 2015

Conversation

rashidkpc
Copy link
Contributor

Closes #2473

This pull implements the ability to link a time filter to a saved dashboard, and have it restored when the dashboard is loaded.

It will only restore the time if on of the following is true:

The time filter will be changed upon the loading of the dashboard, it will not be somehow changed back if the user leaves the dashboard. Not sure if this is the behavior we want, but since time is global, its the behavior that exists currently.

Also, as I was typing this up I wondered if this should be an option for all saved objects. However, things get a lot more complicated if we do that. If we enabled saving time with say, a visualization, it would be expected that the time would stick with that visualization even if was added to a dashboard, which would break the whole global time filter thing.

Side effects of implementation

  • Implements boolean support for the saved object editor.
  • Fixes a bug in saved object editor in which undefined properties were not defineable
  • Breaks out saved object serialization into a .serialize() method

@rashidkpc rashidkpc added this to the 4.1.0 milestone Feb 25, 2015
@w33ble
Copy link
Contributor

w33ble commented Feb 25, 2015

In the settings screen, the timeRestore checkbox does not show up for existing dashboards


// I don't like this, but not sure how else to tell if this is a fresh load of the
// saved dashboard object, so looking for _a in the URL. Ideas?
if (dash.timeRestore && dash.timeTo && dash.timeFrom && !$routeParams._a) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you pointed out, checking for _a is a little dangerous - it's makes assumptions about how AppState works. It's unlikely to cause problems as it's unlikely to change, but it's still not a good idea.

To me, it seems like you want to offload this to the AppState service somehow though. My immediate thought is keeping a reference to what the AppState in the URL was before defaults were injected, and making that "original" state available from the service, but I'm not convinced that's the answer.

@w33ble w33ble assigned rashidkpc and unassigned w33ble Feb 25, 2015
@w33ble w33ble removed the review label Feb 25, 2015
@rashidkpc rashidkpc modified the milestone: 4.1.0 Mar 2, 2015
@rashidkpc
Copy link
Contributor Author

Fixed the _a thing by adding a method called mightExist to the getAppState service.

As for timeRestore not showing up for existing dashboards in the saved object editor. Its probably not a huge deal. Makes me wonder if we should offer either a pure JSON editor for saved objects, or a way to add new fields to the root of a saved object.

@rashidkpc rashidkpc assigned w33ble and unassigned rashidkpc Apr 9, 2015
var currentAppState;

function get() {
return currentAppState;
}

// Checks to see if the appState might already exist, even if it hasn't been newed up
get.mightExist = function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this to exists, or isLoaded or something? The might seems ambiguous, and I kind of expect it to take some action instead of just returning a bool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldExist? I'm trying to convey that a non-default app state could or will exist if you chose to instantiate one.

@w33ble
Copy link
Contributor

w33ble commented Apr 14, 2015

There's still a strange disconnect in the saved object editor, and I think a bug in that interface as well when dealing with dashboards that don't have a saved time. Hopefully I can explain this well enough...

Old Dashboard

Here's a dashboard I created before checking this PR (this is every dashboard that exists in the wild already). I have no way of enabling saved time - maybe this is intention? If not, it's a bug.

screenshot 2015-04-14 11 17 41

New Dashboard, Time Not Saved

I created a new dashboard with the PR, but did not save the time. I then went ahead and checked the save time box, but it doesn't work, since I can't enter the desired time settings. This seems like a bug.

screenshot 2015-04-14 11 17 52

New Dashboard, Time Saved

This one I saved with the time, and now I get the fields I expected, and that I need to make changes.

screenshot 2015-04-14 11 18 02

And when I uncheck the box, I still have the fields I need to re-enable it.

screenshot 2015-04-14 11 20 48

Even when I uncheck the box and clear the fields, I still have the means to restore this. This is all expected and I think how the "Time Not Saved" example should have worked.

screenshot 2015-04-14 11 29 46

@w33ble w33ble assigned rashidkpc and unassigned w33ble Apr 14, 2015
@rashidkpc rashidkpc assigned w33ble and unassigned rashidkpc Apr 14, 2015

// I don't like this, but not sure how else to tell if this is a fresh load of the
// saved dashboard object, so looking for _a in the URL. Ideas?
if (dash.timeRestore && dash.timeTo && dash.timeFrom && !getAppState.mightExist()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be getAppState.wouldExist - or whatever it ends up getting named

version: 1
version: 1,
timeRestore: false,
timeTo: moment().toISOString(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we want the defaults to be real timestamps...

@w33ble
Copy link
Contributor

w33ble commented Apr 15, 2015

As for the timestamp default stuff, this is what the fields look like on a dashboard that was saved without the time.

screenshot 2015-04-14 17 14 39

This will probably never be what the user wants to see. More likely, it'll be now and now-X, and we could fall back to the current now-15m. Really, even just empty inputs would be probably be more useful.

As-is, this is how the dashboard loads when you just check that box:

screenshot 2015-04-14 17 19 36

@w33ble
Copy link
Contributor

w33ble commented Apr 15, 2015

What do you think about renaming getAppState.wouldExist to getAppState.previouslyStored?

@w33ble w33ble assigned rashidkpc and unassigned w33ble Apr 15, 2015
@w33ble w33ble removed the review label Apr 15, 2015
@rashidkpc
Copy link
Contributor Author

Ok, so I undefined timeTo and timeFrom, for exactly the reason you point out. I originally put them there to give people the hint that they should be ISO8601. Then I remembered they can also be datemath. Long term it would be nice to have a date input here, but we should remember we consider this to be an "advanced" screen and thats way outside the scope of this ticket :-D

@rashidkpc rashidkpc assigned w33ble and unassigned rashidkpc Apr 15, 2015
@@ -57,6 +57,14 @@ define(function (require) {
});

var dash = $scope.dash = $route.current.locals.dash;

// I don't like this, but not sure how else to tell if this is a fresh load of the
// saved dashboard object, so looking for _a in the URL. Ideas?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that this is officially a method, the comment should probably be removed

@w33ble w33ble assigned rashidkpc and unassigned w33ble Apr 22, 2015
@w33ble
Copy link
Contributor

w33ble commented Apr 22, 2015

One last, small thing. Once you remove that comment, go ahead and merge, this LGTM! 🚜

rashidkpc added a commit that referenced this pull request Apr 23, 2015
@rashidkpc rashidkpc merged commit 4b5d401 into elastic:master Apr 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Link time selection to saved dashboard
2 participants