Skip to content

Commit

Permalink
chore: update Avatar component in UI kit [WEB-1055, WEB-1734] (determ…
Browse files Browse the repository at this point in the history
…ined-ai#8178)

* replace DynamicIcon

* Group

* inactive and statusText

* fmt

* examples

* tooltipText

* palette

* update det-ui

* fmt

* fix typo
  • Loading branch information
johnkim-det authored Oct 24, 2023
1 parent 4c59393 commit 47b37eb
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 99 deletions.
6 changes: 3 additions & 3 deletions webui/react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webui/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"core-js": "3.32",
"dayjs": "^1.11.7",
"debug": "^4.3.4",
"determined-ui": "git+https://[email protected]/determined-ai/determined-ui.git#v0.5.2",
"determined-ui": "git+https://[email protected]/determined-ai/determined-ui.git#v0.5.4",
"events": "^3.3.0",
"fp-ts": "^2.13.1",
"fuse.js": "^6.6.2",
Expand Down
11 changes: 0 additions & 11 deletions webui/react/src/components/DynamicIcon.module.scss

This file was deleted.

57 changes: 0 additions & 57 deletions webui/react/src/components/DynamicIcon.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions webui/react/src/components/ModelRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SorterResult,
TablePaginationConfig,
} from 'antd/lib/table/interface';
import Avatar from 'determined-ui/Avatar';
import Button from 'determined-ui/Button';
import Dropdown, { MenuItem } from 'determined-ui/Dropdown';
import Icon from 'determined-ui/Icon';
Expand All @@ -19,7 +20,6 @@ import _ from 'lodash';
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';

import DeleteModelModal from 'components/DeleteModelModal';
import DynamicIcon from 'components/DynamicIcon';
import FilterCounter from 'components/FilterCounter';
import Link from 'components/Link';
import { ModelActionMenuKey as MenuKey, ModelActionDropdown } from 'components/ModelActionDropdown';
Expand Down Expand Up @@ -338,7 +338,7 @@ const ModelRegistry: React.FC<Props> = ({ workspace }: Props) => {
if (!workspace) {
return (
<Link disabled>
<DynamicIcon name="-" size={24} />
<Avatar palette="muted" square text="-" />
</Link>
);
}
Expand All @@ -352,7 +352,7 @@ const ModelRegistry: React.FC<Props> = ({ workspace }: Props) => {
? paths.projectDetails(workspaceId)
: paths.workspaceDetails(workspaceId)
}>
<DynamicIcon name={workspace?.name} size={24} />
<Avatar palette="muted" square text={workspace?.name} />
</Link>
</div>
</Tooltip>
Expand Down
4 changes: 2 additions & 2 deletions webui/react/src/components/NavigationSideBar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Avatar from 'determined-ui/Avatar';
import Button from 'determined-ui/Button';
import Dropdown, { MenuItem } from 'determined-ui/Dropdown';
import Icon, { IconName, IconSize } from 'determined-ui/Icon';
Expand All @@ -13,7 +14,6 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useLocation } from 'react-router-dom';
import { CSSTransition } from 'react-transition-group';

import DynamicIcon from 'components/DynamicIcon';
import Link, { Props as LinkProps } from 'components/Link';
import UserSettings from 'components/UserSettings';
import shortCutSettingsConfig, {
Expand Down Expand Up @@ -311,7 +311,7 @@ const NavigationSideBar: React.FC = () => {
workspace={workspace}>
<li>
<NavigationItem
icon={<DynamicIcon name={workspace.name} size={24} />}
icon={<Avatar palette="muted" square text={workspace.name} />}
label={workspace.name}
path={paths.workspaceDetails(workspace.id)}
tooltip={settings.navbarCollapsed}
Expand Down
4 changes: 2 additions & 2 deletions webui/react/src/components/NavigationTabbar.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Avatar from 'determined-ui/Avatar';
import Icon, { IconName } from 'determined-ui/Icon';
import { useModal } from 'determined-ui/Modal';
import Spinner from 'determined-ui/Spinner';
Expand All @@ -7,7 +8,6 @@ import React, { useCallback, useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';

import ActionSheet, { ActionItem } from 'components/ActionSheet';
import DynamicIcon from 'components/DynamicIcon';
import Link, { Props as LinkProps } from 'components/Link';
import UserSettings from 'components/UserSettings';
import usePermissions from 'hooks/usePermissions';
Expand Down Expand Up @@ -100,7 +100,7 @@ const NavigationTabbar: React.FC = () => {
workspaces.map(
(workspace) =>
({
icon: <DynamicIcon name={workspace.name} size={24} style={{ color: 'black' }} />,
icon: <Avatar palette="muted" square text={workspace.name} />,
label: workspace.name,
onClick: (e: AnyMouseEvent) =>
handlePathUpdate(e, paths.workspaceDetails(workspace.id)),
Expand Down
4 changes: 2 additions & 2 deletions webui/react/src/components/ProjectCard.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Typography } from 'antd';
import Avatar, { Size } from 'determined-ui/Avatar';
import Card from 'determined-ui/Card';
import Icon from 'determined-ui/Icon';
import Tooltip from 'determined-ui/Tooltip';
Expand All @@ -10,7 +11,6 @@ import { Project } from 'types';
import { nearestCardinalNumber } from 'utils/number';
import { AnyMouseEvent } from 'utils/routes';

import DynamicIcon from './DynamicIcon';
import { useProjectActionMenu } from './ProjectActionDropdown';
import css from './ProjectCard.module.scss';

Expand Down Expand Up @@ -58,7 +58,7 @@ const ProjectCard: React.FC<Props> = ({
{showWorkspace && project.workspaceId !== 1 && (
<Tooltip content={project.workspaceName}>
<div className={css.workspaceIcon}>
<DynamicIcon name={project.workspaceName} size={20} />
<Avatar palette="muted" size={Size.Small} square text={project.workspaceName} />
</div>
</Tooltip>
)}
Expand Down
4 changes: 2 additions & 2 deletions webui/react/src/components/ResourcePoolBindings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Avatar, { Size } from 'determined-ui/Avatar';
import Button from 'determined-ui/Button';
import { useModal } from 'determined-ui/Modal';
import { Loadable } from 'determined-ui/utils/loadable';
import { useObservable } from 'micro-observables';
import { useCallback, useEffect, useMemo } from 'react';

import DynamicIcon from 'components/DynamicIcon';
import Link from 'components/Link';
import ResourcePoolBindingModalComponent from 'components/ResourcePoolBindingModal';
import { ColumnDef } from 'components/Table/InteractiveTable';
Expand Down Expand Up @@ -39,7 +39,7 @@ const ResourcePoolBindings = ({ pool }: Props): JSX.Element => {
key: 'workspace',
render: (_, record) => (
<div className={css.tableRow}>
<DynamicIcon name={record.name} size={40} style={{ borderRadius: '100%' }} />
<Avatar palette="muted" size={Size.Medium} square text={record.name} />
<div>
<div>
<Link path={paths.workspaceDetails(record.id)}>{record.name}</Link>
Expand Down
4 changes: 2 additions & 2 deletions webui/react/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Space, Typography } from 'antd';
import Avatar from 'determined-ui/Avatar';
import Icon from 'determined-ui/Icon';
import Spinner from 'determined-ui/Spinner';
import { StateOfUnion } from 'determined-ui/Theme';
Expand All @@ -7,7 +8,6 @@ import React from 'react';

import Badge, { BadgeType } from 'components/Badge';
import { ConditionalWrapper } from 'components/ConditionalWrapper';
import DynamicIcon from 'components/DynamicIcon';
import ExperimentIcons from 'components/ExperimentIcons';
import HumanReadableNumber from 'components/HumanReadableNumber';
import Link from 'components/Link';
Expand Down Expand Up @@ -192,7 +192,7 @@ export const taskWorkspaceRenderer = (
? paths.projectDetails(workspaceId)
: paths.workspaceDetails(workspaceId)
}>
<DynamicIcon name={workspace?.name} size={24} />
<Avatar palette="muted" square text={workspace?.name ?? ''} />
</Link>
</div>
</Tooltip>
Expand Down
14 changes: 11 additions & 3 deletions webui/react/src/components/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@ import React from 'react';
import { User } from 'types';
import { getDisplayName } from 'utils/user';

export interface Props extends Omit<AvatarProps, 'darkLight' | 'displayName'> {
export interface Props extends Omit<AvatarProps, 'darkLight' | 'text'> {
user?: User;
deactivated?: boolean;
}

const UserAvatar: React.FC<Props> = ({ user, ...rest }) => {
const UserAvatar: React.FC<Props> = ({ user, deactivated, ...rest }) => {
const displayName = getDisplayName(user);

return <Avatar {...rest} displayName={displayName} />;
return (
<Avatar
{...rest}
inactive={deactivated}
text={displayName}
tooltipText={deactivated ? `${displayName} (deactivated)` : displayName}
/>
);
};

export default UserAvatar;
4 changes: 2 additions & 2 deletions webui/react/src/components/WorkspaceFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Avatar from 'determined-ui/Avatar';
import React from 'react';

import DynamicIcon from 'components/DynamicIcon';
import { Workspace } from 'types';

import css from './WorkspaceFilter.module.scss';
Expand All @@ -12,7 +12,7 @@ interface Props {
const WorkspaceFilter: React.FC<Props> = ({ workspace }: Props) => {
return (
<div className={css.item}>
<DynamicIcon name={workspace.name} size={24} />
<Avatar palette="muted" square text={workspace.name} />
<span className={css.name}>{workspace.name}</span>
</div>
);
Expand Down
38 changes: 33 additions & 5 deletions webui/react/src/pages/DesignKit.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Card as AntDCard, Space } from 'antd';
import { SelectValue } from 'antd/es/select';
import Accordion from 'determined-ui/Accordion';
import Avatar from 'determined-ui/Avatar';
import Avatar, { AvatarGroup, Size as AvatarSize } from 'determined-ui/Avatar';
import Breadcrumb from 'determined-ui/Breadcrumb';
import Button from 'determined-ui/Button';
import Card from 'determined-ui/Card';
Expand Down Expand Up @@ -1557,8 +1557,36 @@ const AvatarSection: React.FC = () => {
abbreviated with an option to hover for an unabbreviated view.
</p>
</AntDCard>
<AntDCard title="Usage">
<Avatar displayName="Test User" />
<AntDCard title="Variations">
<strong>Sizes</strong>
ExtraSmall
<Avatar size={AvatarSize.ExtraSmall} text="Test User" />
Small (Default Size)
<Avatar size={AvatarSize.Small} text="Test User" />
Medium
<Avatar size={AvatarSize.Medium} text="Test User" />
Large
<Avatar size={AvatarSize.Large} text="Test User" />
ExtraLarge
<Avatar size={AvatarSize.ExtraLarge} text="Test User" />
<strong>Shape</strong>
Square
<Avatar square text="Test User" />
<strong>Color</strong>
Muted palette
<Avatar palette="muted" text="Test User" />
No Color
<Avatar noColor text="Test User" />
Inactive
<Avatar inactive text="Test User" />
<strong>Tooltip</strong>
Custom tooltip text
<Avatar text="Test User" tooltipText="Custom tooltip text" />
Hide tooltip
<Avatar hideTooltip text="Test User" />
</AntDCard>
<AntDCard title="Group">
<AvatarGroup items={['Test User', 'Sample Person', 'Example Individual']} />
</AntDCard>
</ComponentSection>
);
Expand All @@ -1581,14 +1609,14 @@ const NameplateSection: React.FC = () => {
<li>With name and alias</li>
<Nameplate
alias={testUser.displayName}
icon={<Avatar displayName={testUser.displayName} />}
icon={<Avatar text={testUser.displayName} />}
name={testUser.username}
/>
<li>Compact format</li>
<Nameplate
alias={testUser.displayName}
compact
icon={<Avatar displayName={testUser.displayName} />}
icon={<Avatar text={testUser.displayName} />}
name={testUser.username}
/>
<li>No alias</li>
Expand Down
8 changes: 4 additions & 4 deletions webui/react/src/pages/WorkspaceList/WorkspaceCard.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Typography } from 'antd';
import Avatar, { Size } from 'determined-ui/Avatar';
import Card from 'determined-ui/Card';
import { Columns } from 'determined-ui/Columns';
import Icon from 'determined-ui/Icon';
import Spinner from 'determined-ui/Spinner';
import { Loadable } from 'determined-ui/utils/loadable';
import React from 'react';

import DynamicIcon from 'components/DynamicIcon';
import Avatar from 'components/UserAvatar';
import UserAvatar from 'components/UserAvatar';
import { handlePath, paths } from 'routes/utils';
import userStore from 'stores/users';
import { Workspace } from 'types';
Expand Down Expand Up @@ -43,7 +43,7 @@ const WorkspaceCard: React.FC<Props> = ({ workspace, fetchWorkspaces }: Props) =
<div className={workspace.archived ? css.archived : ''}>
<Columns gap={8}>
<div className={css.icon}>
<DynamicIcon name={workspace.name} size={78} />
<Avatar palette="muted" size={Size.ExtraLarge} square text={workspace.name} />
</div>
<div className={css.info}>
<div className={css.nameRow}>
Expand All @@ -61,7 +61,7 @@ const WorkspaceCard: React.FC<Props> = ({ workspace, fetchWorkspaces }: Props) =
<div className={css.avatarRow}>
<div className={css.avatar}>
<Spinner conditionalRender spinning={Loadable.isNotLoaded(loadableUser)}>
{Loadable.isLoaded(loadableUser) && <Avatar user={user} />}
{Loadable.isLoaded(loadableUser) && <UserAvatar user={user} />}
</Spinner>
</div>
{workspace.archived && <div className={css.archivedBadge}>Archived</div>}
Expand Down

0 comments on commit 47b37eb

Please sign in to comment.