Skip to content

Conversation

@timroes
Copy link
Contributor

@timroes timroes commented Jul 9, 2018

This PR does a couple of improvements and fixes at the update status calculation:

  • It converts the update status to TypeScript.
  • It fixes the issue, that the TIME status would not be calculated correctly anymore, since the parameter on vis moved to a different location from earlier.
  • It will now use the hash calculation for all parameters and not longer only for data, so we can get rid of the slow JSON.stringify in this place.

@timroes timroes added Feature:Visualizations Generic visualization features (in case no more specific feature label is available) v7.0.0 v6.4.0 labels Jul 9, 2018
@timroes timroes requested review from markov00 and ppisljar July 9, 2018 08:31
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This (maybe a bit weird looking syntax) will actually tell TypeScript, that the return value contains exactly those keys, that has been specified in the array passed to the first parameter (since that's where the T generic type is used).

That way TypeScript will actually fail on: getUpdateStatus([Status.TIME], {}, {}).data, since it knows the return type is of type { time: boolean; }.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@ppisljar
Copy link
Contributor

ppisljar commented Jul 9, 2018

UI Functional Tests.test/functional/apps/visualize/_input_control_vis·js.visualize app input control visualization "before all" hook (from (UI Functional Tests.xml))

jenkins, test this

Copy link
Member

@markov00 markov00 left a comment

Choose a reason for hiding this comment

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

Waiting for CI test before testing deeper. I've left few comments on the code since we are improving the update_status code I think they can be addressed here.

Copy link
Member

Choose a reason for hiding this comment

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

What about moving this function out and create it as pure function?
Also the naming is a bit confusing, because seems that it just return true or false, but it also change a paramenter of the passed obj state. I rather prefer to have two separate function, one for checking and one for assign (if necessary).
Maybe the code will be a bit longer but you can get rid of any possible side effects of changing objects in the closure.

The function can be written like:

function hasChangedUsingGenericHashComparison(oldStatus: any, name: string, valueHash: any) {
  const oldHash = oldStatus[name];
  return oldHash !== valueHash;
}

Than you just call it like

const valueHash = calculateObjectHash(param.visData);
status.data = hasChangedUsingGenericHashComparison(obj._oldStatus, 'data', valueHash);
obj._oldStatus.data = newHash;

I found this more readable without knowing the internal of the calculate or hasChanged functions you know how object changes

Copy link
Member

Choose a reason for hiding this comment

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

Same for the previous comment. Prefer pure functions and move them outside the current function scope.
If not possible, at least change the function name to reflect that it not only check the status but also update the oldStatus.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

height: number;
}

function hasSizeChanged(size: Size, oldSize?: Size): boolean {
Copy link
Member

Choose a reason for hiding this comment

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

Could you invert the params here so we are a bit more aligned with the previous: hasHashChanged function?
first the oldStatus and the new one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I can't because oldSize is optional so it must be in the end. If you want I can change the parameter order to the hasHashChanged function if you want to hash, oldStatus, key if you think that increases readability.

Copy link
Member

Choose a reason for hiding this comment

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

oo you are right, sorry. Yes please so we have in the switch part a cleaner readibility,
thanks ❤️

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Tim Roes added 2 commits July 12, 2018 10:36
@timroes
Copy link
Contributor Author

timroes commented Jul 12, 2018

Reverted the tslint changes out of it, since it seems that PR is still not merged. @ppisljar care for a review?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

status.resize = hasSizeChanged(size, obj._oldStatus.resize);
obj._oldStatus.resize = size;
break;
case Status.TIME:
Copy link
Contributor

Choose a reason for hiding this comment

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

this will get removed with #20377

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. I think we should remove the TIME parameter itself in a separate PR< since we need to change developer docs with that one.

Copy link
Contributor

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

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

code LGTM

@timroes timroes merged commit b407be6 into elastic:master Jul 12, 2018
@timroes timroes deleted the update-status branch July 12, 2018 10:25
timroes added a commit to timroes/kibana that referenced this pull request Jul 12, 2018
* [tslint] use exitCode 1 when linter errors

* fix typo

* Improve getUpdateStatus

* Fix accessing timeRange

* Extract comparison functions

* Switch parameter order

* Revert "[tslint] use exitCode 1 when linter errors"

This reverts commit 0ca23a4.

* Revert "fix typo"

This reverts commit e4e8091.
timroes added a commit that referenced this pull request Jul 12, 2018
* [tslint] use exitCode 1 when linter errors

* fix typo

* Improve getUpdateStatus

* Fix accessing timeRange

* Extract comparison functions

* Switch parameter order

* Revert "[tslint] use exitCode 1 when linter errors"

This reverts commit 0ca23a4.

* Revert "fix typo"

This reverts commit e4e8091.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Visualizations Generic visualization features (in case no more specific feature label is available) v6.4.0 v7.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants