Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CONST/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8749,6 +8749,12 @@ const CONST = {
MFA_OVERLAY: {
BACKDROP: 'MfaOverlay-Backdrop',
},
AGENTS: {
TABLE_ROW: 'Agents-TableRow',
CHAT: 'Agents-Chat',
COPILOT: 'Agents-Copilot',
EDIT: 'Agents-Edit',
},
DOMAIN: {
ADMINS: {
ROW: 'DomainAdmins-Row',
Expand Down
133 changes: 133 additions & 0 deletions src/components/Tables/AgentsTable/AgentsTableRow.tsx
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}
Comment thread
luacmartins marked this conversation as resolved.
Resolved
>
{({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>
);
}
93 changes: 93 additions & 0 deletions src/components/Tables/AgentsTable/index.tsx
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};
1 change: 1 addition & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,7 @@ ${amount} für ${merchant} – ${date}`,
agentsPage: {
title: 'Agenten',
subtitle: `<muted-text>Agents übernehmen Ihre Workflows für Sie, sodass Sie täglich Stunden zurückgewinnen. <a href="${CONST.CUSTOM_AGENTS_HELP_URL}">Mehr erfahren</a>.</muted-text>`,
findAgent: 'Agent suchen',
newAgent: 'Neue:r Agent:in',
emptyAgents: {
title: 'Keine Agenten erstellt',
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2947,6 +2947,7 @@ const translations = {
agentsPage: {
title: 'Agents',
subtitle: `<muted-text>Agents handle your workflows for you, so you get hours back in your day. <a href="${CONST.CUSTOM_AGENTS_HELP_URL}">Learn more</a>.</muted-text>`,
findAgent: 'Find agent',
newAgent: 'New agent',
emptyAgents: {
title: 'No agents created',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2739,6 +2739,7 @@ ${amount} para ${merchant} - ${date}`,
agentsPage: {
title: 'Agentes',
subtitle: `<muted-text>Los agentes gestionan tus flujos de trabajo por ti, para que recuperes horas en tu día. <a href="${CONST.CUSTOM_AGENTS_HELP_URL}">Más información</a>.</muted-text>`,
findAgent: 'Buscar agente',
newAgent: 'Nuevo agente',
emptyAgents: {
title: 'No se han creado agentes.',
Expand Down
1 change: 1 addition & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2884,6 +2884,7 @@ ${amount} pour ${merchant} - ${date}`,
agentsPage: {
title: 'Agents',
subtitle: `<muted-text>Les agents gèrent vos workflows pour vous, afin que vous gagniez des heures dans votre journée. <a href="${CONST.CUSTOM_AGENTS_HELP_URL}">En savoir plus</a>.</muted-text>`,
findAgent: 'Trouver un agent',
newAgent: 'Nouvel agent',
emptyAgents: {
title: 'Aucun agent créé',
Expand Down
1 change: 1 addition & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2872,6 +2872,7 @@ ${amount} per ${merchant} - ${date}`,
agentsPage: {
title: 'Agenti',
subtitle: `<muted-text>Gli agenti gestiscono i tuoi flussi di lavoro al posto tuo, così ti ritrovi ore in più nella tua giornata. <a href="${CONST.CUSTOM_AGENTS_HELP_URL}">Scopri di più</a>.</muted-text>`,
findAgent: 'Trova agente',
newAgent: 'Nuovo agente',
emptyAgents: {
title: 'Nessun agente creato',
Expand Down
1 change: 1 addition & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2841,6 +2841,7 @@ ${date} の ${merchant} への ${amount}`,
agentsPage: {
title: '担当者',
subtitle: `<muted-text>エージェントがワークフローを代わりに処理するので、毎日の時間を数時間取り戻せます。<a href="${CONST.CUSTOM_AGENTS_HELP_URL}">詳しく見る</a>。</muted-text>`,
findAgent: '担当者を探す',
newAgent: '新しいエージェント',
emptyAgents: {
title: 'エージェントは作成されていません',
Expand Down
1 change: 1 addition & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2870,6 +2870,7 @@ ${amount} voor ${merchant} - ${date}`,
agentsPage: {
title: 'Agenten',
subtitle: `<muted-text>Agents verwerken je workflows voor je, zodat je uren per dag terugkrijgt. <a href="${CONST.CUSTOM_AGENTS_HELP_URL}">Meer informatie</a>.</muted-text>`,
findAgent: 'Agent zoeken',
newAgent: 'Nieuwe medewerker',
emptyAgents: {
title: 'Geen agents aangemaakt',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2857,6 +2857,7 @@ ${amount} dla ${merchant} - ${date}`,
agentsPage: {
title: 'Agenci',
subtitle: `<muted-text>Agenci obsługują za ciebie twoje procesy, dzięki czemu odzyskujesz godziny w ciągu dnia. <a href="${CONST.CUSTOM_AGENTS_HELP_URL}">Dowiedz się więcej</a>.</muted-text>`,
findAgent: 'Znajdź agenta',
newAgent: 'Nowy agent',
emptyAgents: {
title: 'Nie utworzono agentów',
Expand Down
1 change: 1 addition & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2860,6 +2860,7 @@ ${amount} para ${merchant} - ${date}`,
agentsPage: {
title: 'Agentes',
subtitle: `<muted-text>Agentes cuidam dos seus fluxos de trabalho para você, para que você ganhe horas de volta no seu dia. <a href="${CONST.CUSTOM_AGENTS_HELP_URL}">Saiba mais</a>.</muted-text>`,
findAgent: 'Encontrar agente',
newAgent: 'Novo agente',
emptyAgents: {
title: 'Nenhum agente criado',
Expand Down
1 change: 1 addition & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2773,6 +2773,7 @@ ${amount},商户:${merchant} - 日期:${date}`,
agentsPage: {
title: '代理人',
subtitle: `<muted-text>智能代理为你处理工作流程,让你每天多出数小时。<a href="${CONST.CUSTOM_AGENTS_HELP_URL}">了解详情</a>。</muted-text>`,
findAgent: '查找代理',
newAgent: '新代理人',
emptyAgents: {
title: '尚未创建代理',
Expand Down
58 changes: 0 additions & 58 deletions src/pages/settings/Agents/AgentInfoRow.tsx

This file was deleted.

Loading
Loading