Skip to content

Commit

Permalink
chore: Citations loading optimization (#38837)
Browse files Browse the repository at this point in the history
/ok-to-test tags="@tag.Anvil"

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
	- Enhanced spinner component with dynamic size configuration
	- Improved type safety across multiple design system components

- **Bug Fixes**
	- Refined size prop handling for various UI components
	- Updated type definitions to prevent invalid size selections

- **Refactor**
	- Replaced `Omit` with `Exclude` for more precise type management
	- Updated component prop type definitions
	- Standardized size prop handling across design system widgets

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12947772391>
> Commit: 4043446
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12947772391&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Anvil`
> Spec:
> <hr>Fri, 24 Jan 2025 10:51:14 UTC
<!-- end of auto-generated comment: Cypress test results  -->
  • Loading branch information
jsartisan authored Jan 24, 2025
1 parent 8f5aad9 commit cc6fafd
Show file tree
Hide file tree
Showing 22 changed files with 88 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const _Button = (props: ButtonProps, ref: ForwardedRef<HTMLButtonElement>) => {

{isLoading && (
<span aria-hidden={!isLoading ? true : undefined} data-loader="">
<Spinner />
<Spinner size={size} />
<span {...visuallyHiddenProps}>{loadingText}</span>
</span>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface ButtonProps extends HeadlessButtonProps {
/** Size of the button
* @default medium
*/
size?: Omit<keyof typeof SIZES, "large">;
size?: Exclude<keyof typeof SIZES, "large">;
/** Indicates if the button should be disabled when the form is invalid */
disableOnInvalidForm?: boolean;
/** Indicates if the button should reset the form when clicked */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import React from "react";
import type { Meta, StoryObj } from "@storybook/react";
import { Button, Flex, BUTTON_VARIANTS, COLORS, SIZES } from "@appsmith/wds";
import {
Button,
Flex,
BUTTON_VARIANTS,
COLORS,
SIZES,
type ButtonProps,
} from "@appsmith/wds";
import { objectKeys } from "@appsmith/utils";

/**
Expand Down Expand Up @@ -59,33 +66,45 @@ export const Sizes: Story = {
render: () => (
<Flex direction="column" gap="spacing-6">
<Flex alignItems="start" gap="spacing-4">
{Object.keys(SIZES)
.filter((size) => !["large"].includes(size))
{objectKeys(SIZES)
.filter(
(size): size is NonNullable<ButtonProps["size"]> =>
!["large"].includes(size),
)
.map((size) => (
<Button icon="star" key={size} size={size} />
))}
</Flex>
<Flex alignItems="start" gap="spacing-4">
{Object.keys(SIZES)
.filter((size) => !["large"].includes(size))
{objectKeys(SIZES)
.filter(
(size): size is NonNullable<ButtonProps["size"]> =>
!["large"].includes(size),
)
.map((size) => (
<Button icon="star" key={size} size={size}>
{size}
</Button>
))}
</Flex>
<Flex alignItems="start" gap="spacing-4">
{Object.keys(SIZES)
.filter((size) => !["large"].includes(size))
{objectKeys(SIZES)
.filter(
(size): size is NonNullable<ButtonProps["size"]> =>
!["large"].includes(size),
)
.map((size) => (
<Button icon="star" iconPosition="end" key={size} size={size}>
{size}
</Button>
))}
</Flex>
<Flex alignItems="start" gap="spacing-4">
{Object.keys(SIZES)
.filter((size) => !["large"].includes(size))
{objectKeys(SIZES)
.filter(
(size): size is NonNullable<ButtonProps["size"]> =>
!["large"].includes(size),
)
.map((size) => (
<Button key={size} size={size}>
{size}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ComboBoxProps
*
* @default medium
*/
size?: Omit<keyof typeof SIZES, "xSmall" | "large">;
size?: Exclude<keyof typeof SIZES, "xSmall" | "large">;

/** The content to display as the placeholder. */
placeholder?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dateInputStyles from "./styles.module.css";

interface DatepickerTriggerProps {
isLoading?: boolean;
size?: Omit<keyof typeof SIZES, "xSmall" | "large">;
size?: Exclude<keyof typeof SIZES, "xSmall" | "large">;
isDisabled?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface DatePickerProps<T extends DateValue>
*
* @default medium
*/
size?: Omit<keyof typeof SIZES, "xSmall" | "large">;
size?: Exclude<keyof typeof SIZES, "xSmall" | "large">;
/**
* className for the popover
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, Flex, SIZES } from "@appsmith/wds";
import { parseDate } from "@internationalized/date";
import type { Meta, StoryObj } from "@storybook/react";

import { DatePicker } from "../src";
import { DatePicker, type DatePickerProps, type DateValue } from "../src";
/**
* A date picker allows a user to select a date.
*/
Expand Down Expand Up @@ -44,7 +44,10 @@ export const Sizes: Story = {
render: () => (
<Flex direction="column" gap="spacing-4" width="sizing-60">
{objectKeys(SIZES)
.filter((size) => !["xSmall", "large"].includes(size))
.filter(
(size): size is NonNullable<DatePickerProps<DateValue>["size"]> =>
!["xSmall", "large"].includes(size),
)
.map((size) => (
<DatePicker key={size} popoverClassName="sb-unstyled" size={size} />
))}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from "clsx";
import type { Component, Ref } from "react";
import React, { Suspense, forwardRef, lazy, useMemo } from "react";

Expand All @@ -7,7 +8,7 @@ import type { IconProps } from "./types";
import { FallbackIcon } from "./FallbackIcon";

const _Icon = (props: IconProps, ref: Ref<Component>) => {
const { color, name, size = "medium", ...rest } = props;
const { className, color, name, size = "medium", ...rest } = props;

const Icon = useMemo(() => {
const pascalName = ICONS[name];
Expand All @@ -16,7 +17,9 @@ const _Icon = (props: IconProps, ref: Ref<Component>) => {
import("@tabler/icons-react").then((module) => {
if (pascalName in module) {
return {
default: module[pascalName] as React.ComponentType,
default: module[pascalName] as React.ComponentType<{
className?: string;
}>,
};
}

Expand All @@ -29,14 +32,14 @@ const _Icon = (props: IconProps, ref: Ref<Component>) => {
<Suspense
fallback={
<FallbackIcon
className={styles.icon}
className={clsx(styles.icon, className)}
data-size={Boolean(size) ? size : undefined}
{...rest}
/>
}
>
<Icon
className={styles.icon}
className={clsx(styles.icon, className)}
data-color={color ? color : undefined}
data-icon=""
data-size={Boolean(size) ? size : undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
SIZES,
BUTTON_VARIANTS,
COLORS,
type IconButtonProps,
} from "@appsmith/wds";
import { objectKeys } from "@appsmith/utils";

Expand Down Expand Up @@ -66,7 +67,10 @@ export const Sizes: Story = {
render: () => (
<Flex alignItems="start" gap="spacing-2">
{objectKeys(SIZES)
.filter((size) => !["xSmall", "large"].includes(size))
.filter(
(size): size is NonNullable<IconButtonProps["size"]> =>
!["xSmall", "large"].includes(size),
)
.map((size) => (
<IconButton icon="star" key={size} size={size} />
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface InlineButtonsProps<T>
/** Size of buttons
* @default medium
*/
size?: Omit<keyof typeof SIZES, "large">;
size?: Exclude<keyof typeof SIZES, "large">;
}

export interface InlineButtonsItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,11 @@ export const IndividualSemantic: Story = {
export const Sizes: Story = {
render: () => (
<Flex direction="column" gap="spacing-4" width="100%">
{Object.keys(SIZES)
.filter((size) => !["xSmall", "large"].includes(size))
{objectKeys(SIZES)
.filter(
(size): size is Exclude<keyof typeof SIZES, "xSmall" | "large"> =>
!["xSmall", "large"].includes(size),
)
.map((size) => (
<InlineButtons items={itemList} key={size} size={size} />
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface CommonInputProps {
suffix?: React.ReactNode;
isLoading?: boolean;
isReadOnly?: boolean;
size?: Omit<keyof typeof SIZES, "xSmall">;
size?: Exclude<keyof typeof SIZES, "xSmall">;
}

export interface InputProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface ModalProps
/** size of the modal
* @default medium
*/
size?: Omit<keyof typeof SIZES, "xSmall">;
size?: Exclude<keyof typeof SIZES, "xSmall">;
/** The children of the component. */
children: ReactNode;
/** Additional props to be passed to the overlay */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export interface SelectProps
*
* @default medium
*/
size?: Omit<keyof typeof SIZES, "xSmall" | "large">;
size?: Exclude<keyof typeof SIZES, "xSmall" | "large">;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import React from "react";
import type { Meta, StoryObj } from "@storybook/react";
import { Select, Button, Flex, SIZES, ListBoxItem } from "@appsmith/wds";
import {
Select,
Button,
Flex,
SIZES,
ListBoxItem,
type SelectProps,
} from "@appsmith/wds";

import { selectItems, selectItemsWithIcons } from "./selectData";

Expand Down Expand Up @@ -40,7 +47,10 @@ export const Sizes: Story = {
render: () => (
<Flex direction="column" gap="spacing-4" width="sizing-60">
{Object.keys(SIZES)
.filter((size) => !["xSmall", "large"].includes(size))
.filter(
(size): size is NonNullable<SelectProps["size"]> =>
!["xSmall", "large"].includes(size),
)
.map((size) => (
<Select key={size} label={size} placeholder={size} size={size}>
{selectItems.map((item) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React from "react";

import { Icon } from "../../Icon";
import { Icon, type IconProps } from "../../Icon";
import styles from "./styles.module.css";

const Spinner = () => {
return <Icon className={styles.spinner} name="loader" size="xSmall" />;
interface SpinnerProps {
size?: Exclude<IconProps["size"], "large">;
}

const Spinner = ({ size = "medium" }: SpinnerProps) => {
return <Icon className={styles.spinner} name="loader" size={size} />;
};

Spinner.displayName = "Spinner";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.spinner {
animation: spin 1s linear infinite;
height: 1.5em;
width: 1.5em;
}

@keyframes spin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export interface TextAreaProps extends AriaTextFieldProps, FieldProps {
rows?: number;
fieldClassName?: string;
inputClassName?: string;
size?: Omit<keyof typeof SIZES, "xSmall">;
size?: Exclude<keyof typeof SIZES, "xSmall">;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export interface TextFieldProps extends AriaTextFieldProps, FieldProps {
placeholder?: string;
suffix?: ReactNode;
prefix?: ReactNode;
size?: Omit<keyof typeof SIZES, "xSmall">;
size?: Exclude<keyof typeof SIZES, "xSmall">;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export interface TimeFieldProps<T extends TimeValue>
FieldProps {
suffix?: ReactNode;
prefix?: ReactNode;
size?: Omit<keyof typeof SIZES, "xSmall">;
size?: Exclude<keyof typeof SIZES, "xSmall">;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ToolbarButtonsProps<T>
/** Size of buttons
* @default medium
*/
size?: Omit<keyof typeof SIZES, "large">;
size?: Exclude<keyof typeof SIZES, "large">;
/** Alignment of buttons inside the container
* @default start
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ export const Semantic: Story = {
export const Sizes: Story = {
render: () => (
<Flex direction="column" gap="spacing-4" width="100%">
{Object.keys(SIZES)
{objectKeys(SIZES)
.filter((size) => !["xSmall", "large"].includes(size))
.map((size) => (
<ToolbarButtons items={itemList} key={size} size={size} />
<ToolbarButtons
items={itemList}
key={size}
size={size as Exclude<keyof typeof SIZES, "large">}
/>
))}
</Flex>
),
Expand Down

0 comments on commit cc6fafd

Please sign in to comment.