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

[Enhance] Implement Validation for Icon Input Source & Set Default Icon to Beaker #1137

Merged
merged 7 commits into from
Dec 8, 2023

Conversation

willie-hung
Copy link
Contributor

@willie-hung willie-hung commented Nov 2, 2023

Description

  • Implemented validation for four icon input types:
    • Cached OuiIcons
    • Icons from URLs (absolute, relative)
    • Non-cached OuiIcons and newly added icons
    • Custom components
  • Implemented tests to ensure the functionality of these validations.
  • Set Beaker as the new default icon.

Issues Resolved

Resolves #951

Screenshot

For demonstration purposes, when an input iconType is not present in the original OuiIconType, the Beaker icon will be used as a fallback. This behavior can be tested by removing specific keys from the typeToPathMap dictionary manually or checkout the test I wrote.

Screenshot 2023-11-01 at 10 02 58 PM

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 <[email protected]>
Signed-off-by: Willie Hung <[email protected]>
Signed-off-by: Willie Hung <[email protected]>
@willie-hung willie-hung changed the title [ENHANCE] Implement Validation for Icon Input Source & Set Default Icon to Beaker [Enhance] Implement Validation for Icon Input Source & Set Default Icon to Beaker Nov 21, 2023
Comment on lines +628 to 642
// Category 1: cached oui icons
if (isCachedIcon(type)) {
initialIcon = iconComponentCache[type as string];
// Category 2: URL (relative, absolute)
} else if (isUrl(type)) {
initialIcon = type;
// Category 3: non-cached oui icon or new icon
} else if (typeof type === 'string') {
isLoading = true;
this.loadIconComponent(type);
this.loadIconComponent(type as OuiIconType);
} else {
// Category 4: custom icon component
initialIcon = type;
this.onIconLoad();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be rewritten to not use a mutable variable. I'll make a followup issue, no need to worry about pushing it in this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +184 to +187
it('renders custom svg from relative url', () => {
const component = mount(<OuiIcon type="./assets/beaker.svg" />);
expect(prettyHtml(component.html())).toMatchSnapshot();
});
Copy link
Member

Choose a reason for hiding this comment

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

nit - maybe it's better to test custom svg rendering with an asset that isn't used as a fallback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshuarrrr should I raise an issue so that we can revise this unit test or just leave it as it is?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, if you think it's a worthwhile change.

@joshuarrrr joshuarrrr merged commit 0d3b6cc into opensearch-project:main Dec 8, 2023
17 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Dec 8, 2023
…on to `Beaker` (#1137)

* Revise the logic to handle default icon

Signed-off-by: Willie Hung <[email protected]>

* Categorize different input icon types

Signed-off-by: Willie Hung <[email protected]>

* Remove unused code

Signed-off-by: Willie Hung <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Willie Hung <[email protected]>

* Use readable parameter name

Signed-off-by: Willie Hung <[email protected]>

* Handle different input cases and add tests

Signed-off-by: Willie Hung <[email protected]>

---------

Signed-off-by: Willie Hung <[email protected]>
Co-authored-by: Josh Romero <[email protected]>
(cherry picked from commit 0d3b6cc)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

# Conflicts:
#	CHANGELOG.md
@willie-hung willie-hung deleted the feature/beaker branch December 11, 2023 22:38
ashwin-pc pushed a commit that referenced this pull request Dec 12, 2023
…on to `Beaker` (#1137) (#1171)

* Revise the logic to handle default icon

Signed-off-by: Willie Hung <[email protected]>

* Categorize different input icon types

Signed-off-by: Willie Hung <[email protected]>

* Remove unused code

Signed-off-by: Willie Hung <[email protected]>

* Update CHANGELOG.md

Signed-off-by: Willie Hung <[email protected]>

* Use readable parameter name

Signed-off-by: Willie Hung <[email protected]>

* Handle different input cases and add tests

Signed-off-by: Willie Hung <[email protected]>

---------

Signed-off-by: Willie Hung <[email protected]>
Co-authored-by: Josh Romero <[email protected]>
(cherry picked from commit 0d3b6cc)
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.

Unknown OuiIcon names should render 'beaker'
3 participants