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

chore(NonIdealState): refactored non ideal state component to a functional component #6821

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

ahmadJT
Copy link
Contributor

@ahmadJT ahmadJT commented May 23, 2024

Fixes #6289

Checklist

  • Includes tests
  • Update documentation

Changes proposed in this pull request:

  • refactor non ideal state component to a functional component

Reviewers should focus on:

  • NonIdealState component

Screenshot

@changelog-app
Copy link

changelog-app bot commented May 23, 2024

Generate changelog in packages/core/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

chore(NonIdealState): refactored non ideal state component to a functional component

Check the box to generate changelog(s)

  • Generate changelog entry

Copy link
Contributor

@ggdouglas ggdouglas left a comment

Choose a reason for hiding this comment

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

This is almost ready; requesting a few minor stylistic and one functional change.

iconSize = NonIdealStateIconSize.STANDARD,
layout = "vertical",
title,
}) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we destructure these inside of the function body rather than in the arguments? I think this is more in line with the structure we use for other functional components that have multiline props in Blueprint.

export const NonIdealState: React.FC<NonIdealStateProps> = props => {
    const {
        action,
        children,
        className,
        description,
        icon,
        iconMuted = true,
        iconSize = NonIdealStateIconSize.STANDARD,
        layout = "vertical",
        title,
    } = props;
    // ...
}

);
};

const maybeRenderText = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of keeping these as inline functions, can we encapsulate the conditional in a couple variables, say:

const shouldRenderVisual = icon != null;
const shouldRenderText = title != null || description != null;

and then inline them below:

<div className={classNames(Classes.NON_IDEAL_STATE, `${Classes.NON_IDEAL_STATE}-${layout}`, className)}>
    {shouldRenderVisual && (
        <div
            className={Classes.NON_IDEAL_STATE_VISUAL}
            style={{ fontSize: `${iconSize}px`, lineHeight: `${iconSize}px` }}
        >
            <Icon
                className={classNames({ [Classes.ICON_MUTED]: iconMuted })}
                icon={icon}
                size={iconSize}
                aria-hidden={true}
                tabIndex={-1}
            />
        </div>
    )}
    {shouldRenderText && (
        <div className={Classes.NON_IDEAL_STATE_TEXT}>
            {title && <H4>{title}</H4>}
            {description && ensureElement(description, "div")}
        </div>
    )}
    {action}
    {children}
</div>

I think this would improve the code clarity a bit, and it precludes having to make additional unnecessary function calls.

const maybeRenderText = () => {
return (
!!title &&
!!description && (
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the logic here should be:

!!title || !!description

Otherwise, the text will only render only if both title and description are set. Having just a title and no description (or vice versa) is a valid configuration for this component.

Better yet, can we be a bit more explicit with our operators here? (since this is TypeScript)

title != null || description != null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor simple class components into functions
3 participants