Repository navigation
Update the agents table to the new style #94995
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
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7f2f4d6
Add AgentsTable component for compact agent list styling.
luacmartins e3c3527
Migrate AgentsPage to the shared AgentsTable component.
luacmartins a7ef838
Add findAgent search label translation for the agents table.
luacmartins d3d17ad
apply copy
luacmartins 4b33244
Fix CI failures for agents table migration.
luacmartins b5d46a2
Fix AgentsPage typecheck by using flatMap for agent rows.
luacmartins 8872c11
add buttons
luacmartins 7cb6fac
adjust padding, change copy
luacmartins 48e6e5d
Fix AgentsTableRow unit tests for wide layout action buttons.
luacmartins af0cdb1
Fix eslint in AgentsTableRow unit test reanimated mock.
luacmartins 232915f
resolve conflicts
luacmartins ba2ac0f
fix spacing, add errors
luacmartins 03ca362
Merge branch 'main' into cmartins-agentsTable
luacmartins e15355b
use search, filter deleted, styles
luacmartins e5229eb
fix eslint
luacmartins dd610ab
fix jest
luacmartins 0d4cf10
Merge branch 'main' into cmartins-agentsTable
luacmartins b901683
fix subtitle
luacmartins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| import Button from '@components/ButtonComposed'; | ||
| import Icon from '@components/Icon'; | ||
| import ReportActionAvatars from '@components/ReportActionAvatars'; | ||
| import Table from '@components/Table'; | ||
| import TextWithTooltip from '@components/TextWithTooltip'; | ||
|
|
||
| import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; | ||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useStyleUtils from '@hooks/useStyleUtils'; | ||
| import useTheme from '@hooks/useTheme'; | ||
| import useThemeStyles from '@hooks/useThemeStyles'; | ||
|
|
||
| import variables from '@styles/variables'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
|
|
||
| import React from 'react'; | ||
| import {View} from 'react-native'; | ||
|
|
||
| import type {AgentRowData} from '.'; | ||
|
|
||
| type AgentsTableRowProps = { | ||
| /** Data about the agent */ | ||
| item: AgentRowData; | ||
|
|
||
| /** The index of the row relative to all other rows */ | ||
| rowIndex: number; | ||
|
|
||
| /** Whether to use narrow table row layout */ | ||
| shouldUseNarrowTableLayout: boolean; | ||
| }; | ||
|
|
||
| export default function AgentsTableRow({item, rowIndex, shouldUseNarrowTableLayout}: AgentsTableRowProps) { | ||
| const theme = useTheme(); | ||
| const styles = useThemeStyles(); | ||
| const styleUtils = useStyleUtils(); | ||
| const {translate} = useLocalize(); | ||
| const icons = useMemoizedLazyExpensifyIcons(['ArrowRight', 'ChatBubble']); | ||
|
|
||
| const avatarSize = shouldUseNarrowTableLayout ? CONST.AVATAR_SIZE.DEFAULT : CONST.AVATAR_SIZE.SMALL; | ||
| const isPendingDeletion = item.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; | ||
| const isPendingAddOrDelete = item.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD || isPendingDeletion; | ||
| const areActionsDisabled = isPendingAddOrDelete || item.accountID <= 0 || !item.login; | ||
| const accessibilityLabel = [item.displayName, item.login].filter(Boolean).join(', '); | ||
|
|
||
| const getSecondaryAvatarContainerStyle = (hovered: boolean) => [ | ||
| styleUtils.getBackgroundAndBorderStyle(theme.sidebar), | ||
| hovered ? styleUtils.getBackgroundAndBorderStyle(styles.sidebarLinkHover?.backgroundColor ?? theme.sidebar) : undefined, | ||
| ]; | ||
|
|
||
| return ( | ||
| <Table.Row | ||
| interactive | ||
| rowIndex={rowIndex} | ||
| disabled={item.disabled} | ||
| accessibilityLabel={accessibilityLabel} | ||
| sentryLabel={CONST.SENTRY_LABEL.AGENTS.TABLE_ROW} | ||
| offlineWithFeedback={{ | ||
| errors: item.errors, | ||
| pendingAction: item.pendingAction, | ||
| onClose: item.dismissError, | ||
| shouldHideOnDelete: false, | ||
| }} | ||
| onPress={item.action} | ||
| > | ||
| {({hovered}) => ( | ||
| <> | ||
| <View style={[styles.flex1, styles.flexRow, styles.alignItemsCenter]}> | ||
| <ReportActionAvatars | ||
| size={avatarSize} | ||
| accountIDs={[item.accountID]} | ||
| fallbackDisplayName={item.displayName} | ||
| shouldShowTooltip | ||
| secondaryAvatarContainerStyle={getSecondaryAvatarContainerStyle(!!hovered)} | ||
| /> | ||
| <View style={[shouldUseNarrowTableLayout && styles.gap1, styles.flex1]}> | ||
| <TextWithTooltip | ||
| shouldShowTooltip | ||
| text={item.displayName} | ||
| style={[styles.optionDisplayName, styles.pre, isPendingDeletion && styles.offlineFeedbackDeleted]} | ||
| /> | ||
| <TextWithTooltip | ||
| shouldShowTooltip | ||
| text={item.login} | ||
| style={[styles.textLabelSupporting, styles.lh16, styles.pre, isPendingDeletion && styles.offlineFeedbackDeleted]} | ||
| /> | ||
| </View> | ||
| </View> | ||
|
|
||
| <View style={[styles.flexRow, styles.alignItemsCenter, styles.justifyContentEnd, styles.gap2]}> | ||
| {!shouldUseNarrowTableLayout && ( | ||
| <View style={[styles.flexRow, styles.alignItemsCenter, styles.gap2]}> | ||
| <Button | ||
| size={CONST.BUTTON_SIZE.SMALL} | ||
| onPress={item.onChatPress} | ||
| isDisabled={areActionsDisabled} | ||
| accessibilityLabel={translate('editAgentPage.chatWithAgent')} | ||
| sentryLabel={CONST.SENTRY_LABEL.AGENTS.CHAT} | ||
| > | ||
| <Button.Icon src={icons.ChatBubble} /> | ||
| </Button> | ||
| <Button | ||
| size={CONST.BUTTON_SIZE.SMALL} | ||
| onPress={item.onCopilotPress} | ||
| isDisabled={areActionsDisabled} | ||
| accessibilityLabel={translate('editAgentPage.copilotIntoAccount')} | ||
| sentryLabel={CONST.SENTRY_LABEL.AGENTS.COPILOT} | ||
| > | ||
| <Button.Text>{translate('delegate.copilot')}</Button.Text> | ||
| </Button> | ||
| <Button | ||
| size={CONST.BUTTON_SIZE.SMALL} | ||
| onPress={item.action} | ||
| isDisabled={isPendingDeletion} | ||
| sentryLabel={CONST.SENTRY_LABEL.AGENTS.EDIT} | ||
| > | ||
| <Button.Text>{translate('common.edit')}</Button.Text> | ||
| </Button> | ||
| </View> | ||
| )} | ||
| <Icon | ||
| src={icons.ArrowRight} | ||
| fill={theme.icon} | ||
| additionalStyles={[styles.alignSelfCenter, (!hovered || item.disabled) && styles.opacitySemiTransparent]} | ||
| width={variables.iconSizeNormal} | ||
| height={variables.iconSizeNormal} | ||
| /> | ||
| </View> | ||
| </> | ||
| )} | ||
| </Table.Row> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import type {CompareItemsCallback, IsItemInSearchCallback, TableColumn, TableData} from '@components/Table'; | ||
| import Table from '@components/Table'; | ||
|
|
||
| import useLocalize from '@hooks/useLocalize'; | ||
| import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
|
|
||
| import tokenizedSearch from '@libs/tokenizedSearch'; | ||
|
|
||
| import variables from '@styles/variables'; | ||
|
|
||
| import type * as OnyxCommon from '@src/types/onyx/OnyxCommon'; | ||
|
|
||
| import type {ListRenderItemInfo} from '@shopify/flash-list'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| import AgentsTableRow from './AgentsTableRow'; | ||
|
|
||
| type AgentsTableColumnKey = 'agent' | 'actions'; | ||
|
|
||
| type AgentRowData = TableData & { | ||
| accountID: number; | ||
| displayName: string; | ||
| login: string; | ||
| errors?: OnyxCommon.Errors; | ||
| pendingAction?: OnyxCommon.PendingAction; | ||
| action: () => void; | ||
| onChatPress: () => void; | ||
| onCopilotPress: () => void; | ||
| dismissError: () => void; | ||
| }; | ||
|
|
||
| type AgentsTableProps = { | ||
| agents: AgentRowData[]; | ||
| }; | ||
|
|
||
| export default function AgentsTable({agents}: AgentsTableProps) { | ||
| const {translate, localeCompare} = useLocalize(); | ||
| const {shouldUseNarrowLayout, isMediumScreenWidth} = useResponsiveLayout(); | ||
|
|
||
| const shouldUseNarrowTableLayout = shouldUseNarrowLayout || isMediumScreenWidth; | ||
|
|
||
| const agentsTableColumns: Array<TableColumn<AgentsTableColumnKey>> = [ | ||
| { | ||
| key: 'agent', | ||
| label: translate('agentsPage.title'), | ||
| sortable: true, | ||
| }, | ||
| { | ||
| key: 'actions', | ||
| label: '', | ||
| sortable: false, | ||
| width: shouldUseNarrowTableLayout ? variables.tableCaretColumnWidth : variables.agentsTableActionColumnWidth, | ||
| }, | ||
| ]; | ||
|
|
||
| const compareTableItems: CompareItemsCallback<AgentRowData> = (item1, item2, activeSorting) => { | ||
| const orderMultiplier = activeSorting.order === 'asc' ? 1 : -1; | ||
| return localeCompare(item1.displayName, item2.displayName) * orderMultiplier; | ||
| }; | ||
|
|
||
| const isTableItemInSearch: IsItemInSearchCallback<AgentRowData> = (item, searchValue) => { | ||
| const results = tokenizedSearch([item], searchValue, (option) => [option.displayName, option.login]); | ||
| return results.length > 0; | ||
| }; | ||
|
|
||
| const renderTableItem = ({item, index}: ListRenderItemInfo<AgentRowData>) => ( | ||
| <AgentsTableRow | ||
| item={item} | ||
| rowIndex={index} | ||
| shouldUseNarrowTableLayout={shouldUseNarrowTableLayout} | ||
| /> | ||
| ); | ||
|
|
||
| return ( | ||
| <Table | ||
| data={agents} | ||
| columns={agentsTableColumns} | ||
| renderItem={renderTableItem} | ||
| compareItems={compareTableItems} | ||
| isItemInSearch={isTableItemInSearch} | ||
| initialSortColumn="agent" | ||
| title={translate('agentsPage.title')} | ||
| keyExtractor={(item) => item.keyForList} | ||
| > | ||
| <Table.FilterBar label={translate('agentsPage.findAgent')} /> | ||
| <Table.Header /> | ||
| <Table.Body /> | ||
| </Table> | ||
| ); | ||
| } | ||
|
|
||
| export type {AgentRowData, AgentsTableColumnKey}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.