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

[Fix] "Guidelines" Documentation Render Blank Page #1111

Merged
merged 4 commits into from
Oct 30, 2023

Conversation

willie-hung
Copy link
Contributor

@willie-hung willie-hung commented Oct 22, 2023

Description

Resolve the issue where the Source Documentation would render blank pages when users clicked on either the "Colors" or "Sass" sections.

Issues Resolved

Closes #1109

Screenshot

Before

before-1.mov

After

after.mov

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • All tests pass
    • yarn lint
    • yarn test-unit
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Signed-off-by: Willie Hung <willie880201044@gmail.com>
@willie-hung
Copy link
Contributor Author

While investigating this issue, I found it challenging to identify the bug due to the implicit typing of variables.

For example, the main issue lies in the fact that palette[color] is already a string in the format "#017D73". Therefore, the original code rgbToHex(palette[color].rgba).toUpperCase() is unnecessary and prone to errors.

Do we have any plans to migrate some of these files to TypeScript for better type safety?

Copy link

@vvavdiya vvavdiya left a comment

Choose a reason for hiding this comment

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

@Willie-The-Lord
PR details need to update in CHANGELOG.md

@willie-hung
Copy link
Contributor Author

@Willie-The-Lord PR details need to update in CHANGELOG.md

Thank you for the heads up!

Signed-off-by: Willie Hung <willie880201044@gmail.com>
Copy link
Contributor

@BigSamu BigSamu left a comment

Choose a reason for hiding this comment

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

Apart from the minor comment I made, the changes LGTM! I have already reviewed the code and tested it locally. Indeed, the problem was tricky, as @Willie-The-Lord mentioned.

@BigSamu
Copy link
Contributor

BigSamu commented Oct 25, 2023

@BSFishy,

Additionally I want to comment the following when doing console.log(palette) for the aux function getSassVars(theme) in the file src-docs/src/views/guidelines/_get_sass_vars.js

Why do we repeat the colour themes using variables that have the suffix Text. For example, take a look at the screenshot below. We are repeating the values for hex colour"#F66" in the keyseuiDangerColor and euiDangerColorText. In both cases, the value is a string. Shouldn't we avoid DRY?

image

@BSFishy
Copy link
Contributor

BSFishy commented Oct 26, 2023

While investigating this issue, I found it challenging to identify the bug due to the implicit typing of variables.

For example, the main issue lies in the fact that palette[color] is already a string in the format "#017D73". Therefore, the original code rgbToHex(palette[color].rgba).toUpperCase() is unnecessary and prone to errors.

Do we have any plans to migrate some of these files to TypeScript for better type safety?

Unfortunately, not really. These variables are extracted from Sass, using custom scripts: https://github.com/opensearch-project/oui/blob/main/scripts/babel/variables-from-scss/index.js and https://github.com/opensearch-project/oui/blob/main/scripts/lib/compile-scss-with-variables.js.

I think the format changed from

color: {
  r: string;
  g: string;
  b: string;
  a: string;
  rgba: string;
}

into

color: string

Which is where the errors come from. We might be able to add some sort of type safety by updating the Webpack plugin.

Why do we repeat the colour themes using variables that have the suffix Text. For example, take a look at the screenshot below. We are repeating the values for hex colour"#F66" in the keyseuiDangerColor and euiDangerColorText. In both cases, the value is a string. Shouldn't we avoid DRY?

To this point, the generates vars are just all of the Sass vars in the projects put into a JSON object. So for whatever reason we have these variables which are used in different ways, all just extracted and put into a single object.

@BigSamu
Copy link
Contributor

BigSamu commented Oct 26, 2023

To this point, the generates vars are just all of the Sass vars in the projects put into a JSON object. So for whatever reason we have these variables which are used in different ways, all just extracted and put into a single object.

Just asking here if we should simplify the JSON object to avoid DRY. It does not make sense to have the same value for 2 distinct keys. Of course, this will mean refactoring the code in other parts.

Regards,

Samuel

@joshuarrrr
Copy link
Member

While investigating this issue, I found it challenging to identify the bug due to the implicit typing of variables.

For example, the main issue lies in the fact that palette[color] is already a string in the format "#017D73". Therefore, the original code rgbToHex(palette[color].rgba).toUpperCase() is unnecessary and prone to errors.

Do we have any plans to migrate some of these files to TypeScript for better type safety?

I don't think we have any overall issue for migrating OUI from JS to TS, but I think you could open one with this as an example of why it may be worth the effort to do. The good thing about typescript conversions is that they can be parallelized and worked on as good first issues.

@joshuarrrr
Copy link
Member

joshuarrrr commented Oct 30, 2023

To this point, the generates vars are just all of the Sass vars in the projects put into a JSON object. So for whatever reason we have these variables which are used in different ways, all just extracted and put into a single object.

Just asking here if we should simplify the JSON object to avoid DRY. It does not make sense to have the same value for 2 distinct keys. Of course, this will mean refactoring the code in other parts.

Regards,

Samuel

@BigSamu This has to do with the way we use SASS vars in the project. In many cases, it's useful to have multiple aliases that map to different usages even if (in some themes) they actually use the same underlying value. When you look at the JSON file (or the output of _get_sass_vars.js), what you're seeing is the calculated/resolved values for each SASS var in the currently selected theme. But different themes (or even light/dark mode within a particular theme) may assign these values differently.

In your example, in that theme the euiColorDanger is suitable for use as a text color given the themed background colors, so it's not transformed by the makeHighContrastColor() function: https://github.com/search?q=repo%3Aopensearch-project%2Foui+ouiColorDangerText%3A&type=code

But each theme is free to define the relationship between the euiColorDanger and euiColorDangerText variables (even hard-coding both), and OUI components are structured to use the appropriate variable whether the same or different.

@willie-hung
Copy link
Contributor Author

To this point, the generates vars are just all of the Sass vars in the projects put into a JSON object. So for whatever reason we have these variables which are used in different ways, all just extracted and put into a single object.

Just asking here if we should simplify the JSON object to avoid DRY. It does not make sense to have the same value for 2 distinct keys. Of course, this will mean refactoring the code in other parts.
Regards,
Samuel

@BigSamu This has to do with the way we use SASS vars in the project. In many cases, it's useful to have multiple aliases that map to different usages even if (in some themes) they actually use the same underlying value. When you look at the JSON file (or the output of _get_sass_vars.js), what you're seeing is the calculated/resolved values for each SASS var in the currently selected theme. But different themes (or even light/dark mode within a particular theme) may assign these values differently.

In your example, in that theme the euiColorDanger is suitable for use as a text color given the themed background colors, so it's not transformed by the makeHighContrastColor() function: https://github.com/search?q=repo%3Aopensearch-project%2Foui+ouiColorDangerText%3A&type=code

But each theme is free to define the relationship between the euiColorDanger and euiColorDangerText variables (even hard-coding both), and OUI components are structured to use the appropriate variable whether the same or different.

Thanks @joshuarrrr for the detailed explanation! It makes sense that the flexibility is beneficial, especially when we consider the implementation across various themes.

Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

Awesome fix @Willie-The-Lord - just a couple minor questions and suggestions.

CHANGELOG.md Outdated Show resolved Hide resolved
src-docs/src/views/guidelines/sass.js Show resolved Hide resolved
src-docs/src/views/guidelines/colors/vis_palette.js Outdated Show resolved Hide resolved
willie-hung and others added 2 commits October 30, 2023 15:34
Co-authored-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Willie Hung <willie880201044@gmail.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Willie Hung <willie880201044@gmail.com>
@joshuarrrr joshuarrrr merged commit 9ba6199 into opensearch-project:main Oct 30, 2023
11 of 16 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Oct 30, 2023
* Update error color type

Signed-off-by: Willie Hung <willie880201044@gmail.com>

* Add CHANGELOG.md

Signed-off-by: Willie Hung <willie880201044@gmail.com>

* Update src-docs/src/views/guidelines/colors/vis_palette.js

Co-authored-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Willie Hung <willie880201044@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Willie Hung <willie880201044@gmail.com>

---------

Signed-off-by: Willie Hung <willie880201044@gmail.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
(cherry picked from commit 9ba6199)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
@willie-hung willie-hung deleted the test-colorRenderError branch October 30, 2023 23:47
@BigSamu
Copy link
Contributor

BigSamu commented Oct 31, 2023

To this point, the generates vars are just all of the Sass vars in the projects put into a JSON object. So for whatever reason we have these variables which are used in different ways, all just extracted and put into a single object.

Just asking here if we should simplify the JSON object to avoid DRY. It does not make sense to have the same value for 2 distinct keys. Of course, this will mean refactoring the code in other parts.
Regards,
Samuel

@BigSamu This has to do with the way we use SASS vars in the project. In many cases, it's useful to have multiple aliases that map to different usages even if (in some themes) they actually use the same underlying value. When you look at the JSON file (or the output of _get_sass_vars.js), what you're seeing is the calculated/resolved values for each SASS var in the currently selected theme. But different themes (or even light/dark mode within a particular theme) may assign these values differently.

In your example, in that theme the euiColorDanger is suitable for use as a text color given the themed background colors, so it's not transformed by the makeHighContrastColor() function: https://github.com/search?q=repo%3Aopensearch-project%2Foui+ouiColorDangerText%3A&type=code

But each theme is free to define the relationship between the euiColorDanger and euiColorDangerText variables (even hard-coding both), and OUI components are structured to use the appropriate variable whether the same or different.

Many thanks @joshuarrrr! Pretty clear the explanation!

joshuarrrr pushed a commit that referenced this pull request Nov 14, 2023
* Update error color type

Signed-off-by: Willie Hung <willie880201044@gmail.com>

* Add CHANGELOG.md

Signed-off-by: Willie Hung <willie880201044@gmail.com>

* Update src-docs/src/views/guidelines/colors/vis_palette.js

Co-authored-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Willie Hung <willie880201044@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Josh Romero <rmerqg@amazon.com>
Signed-off-by: Willie Hung <willie880201044@gmail.com>

---------

Signed-off-by: Willie Hung <willie880201044@gmail.com>
Co-authored-by: Josh Romero <rmerqg@amazon.com>
(cherry picked from commit 9ba6199)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
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.

[BUG] "Guidelines" Documentation Render Blank Page
5 participants