Skip to content

Use data-id attribute to select loading message, instead of CSS class…#9248

Merged
cjcenizal merged 2 commits intoelastic:masterfrom
cjcenizal:improvement/loading-screen-js-selector
Nov 29, 2016
Merged

Use data-id attribute to select loading message, instead of CSS class…#9248
cjcenizal merged 2 commits intoelastic:masterfrom
cjcenizal:improvement/loading-screen-js-selector

Conversation

@cjcenizal
Copy link
Copy Markdown
Contributor

@cjcenizal cjcenizal commented Nov 29, 2016

… since that creates a brittle coupling between JS and CSS.

Also, formalize this rule in the CSS style guide.

This change will help avoid problems like the one solved in #9235.

… since that creates a brittle coupling between JS and CSS.

- Formalize this rule in the CSS style guide.
@kobelb
Copy link
Copy Markdown
Contributor

kobelb commented Nov 29, 2016

I completely agree with not using the css .class selector in this scenario; however, I'd like to suggest an alternative solution.

It's my understanding that the 'hideLoadingMessage' functionality is only used to hide the loading message in embedded mode. Instead of adding a 'data-id' attribute, I feel like it'd be more clear if we added an attribute such as 'data-hide-for-embedded' ( or a better name ) and use that attribute to determine what we hide in embedded mode.

That way we're marking the elements based on the intention of what we intend to happen to them.

Also, I don't think that we need to mark the parent of the element that we want removed, and instead we should be able to use element.parentNode.removeChild(element);

@stacey-gammon
Copy link
Copy Markdown

Curious, how does this help with the brittleness? If someone deleted .kibanaLoadingMessage but left the onload function as it was, wouldn't we get in the same crash situation? Or does data-id do something special?

@cjcenizal
Copy link
Copy Markdown
Contributor Author

cjcenizal commented Nov 29, 2016

@kobelb I think those are great ideas. I'll update the PR.
@stacey-gammon The brittleness mostly stems from the fact that we may want to change the name of the class, which is now possible to do without breaking the JS. In the case that we're removing the element altogether, I'm thinking that the attribute will ring an alarm bell in the dev's mind that the JS is doing something special with that element, and will know to dig deeper into the JS. When we're using a class, there's no indication that there's a relationship with the JS. I think Brandon's suggestion will do an even better job of ringing that alarm bell because the name of the attribute will convey a lot more information.

Copy link
Copy Markdown

@stacey-gammon stacey-gammon left a comment

Choose a reason for hiding this comment

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

Nice. I agree the more specific data tag makes it obvious that it's important and needs to be left in. Otherwise I could see someone updating the class name and the data-id tag simultaneously, just to keep them in sync.

Copy link
Copy Markdown
Contributor

@kobelb kobelb left a comment

Choose a reason for hiding this comment

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

LGTM

@cjcenizal cjcenizal merged commit 7cdd298 into elastic:master Nov 29, 2016
@cjcenizal cjcenizal deleted the improvement/loading-screen-js-selector branch November 29, 2016 21:21
@cjcenizal cjcenizal added release_note:enhancement v5.2.0 v6.0.0 Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. labels Nov 30, 2016
elastic-jasper added a commit that referenced this pull request Nov 30, 2016
Backports PR #9248

**Commit 1:**
Use data-id attribute to select loading message, instead of CSS class since that creates a brittle coupling between JS and CSS.
- Formalize this rule in the CSS style guide.

* Original sha: d574763
* Authored by CJ Cenizal <cj@cenizal.com> on 2016-11-29T17:28:48Z

**Commit 2:**
Use uniquely and semantically named data attribute instead of data-id.

* Original sha: 0b42628
* Authored by CJ Cenizal <cj@cenizal.com> on 2016-11-29T20:24:54Z
cjcenizal pushed a commit that referenced this pull request Nov 30, 2016
#9271)

Backports PR #9248

**Commit 1:**
Use data-id attribute to select loading message, instead of CSS class since that creates a brittle coupling between JS and CSS.
- Formalize this rule in the CSS style guide.

* Original sha: d574763
* Authored by CJ Cenizal <cj@cenizal.com> on 2016-11-29T17:28:48Z

**Commit 2:**
Use uniquely and semantically named data attribute instead of data-id.

* Original sha: 0b42628
* Authored by CJ Cenizal <cj@cenizal.com> on 2016-11-29T20:24:54Z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:enhancement Team:Platform-Design Team Label for Kibana Design Team. Support the Analyze group of plugins. v5.2.0 v6.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants