* Add agents RHS functionality for mobile Implements a dedicated agents interface accessible from the home screen, featuring: - Agent chat screen with bot selector and message input - Thread list screen showing all agent conversations - Remote actions for fetching bots and threads from plugin API - Navigation between chat, threads, and individual conversations - Integration with plus menu for easy access Follows similar pattern to playbooks with modal screens and navigation helpers. * Fix icon name for agents menu item Change robot-happy-outline to robot-happy to resolve PropType validation error. * Add agents button to sidebar and fix agent chat issues - Add AgentsButton component to channel list sidebar below Drafts - Fix thread navigation to use fetchAndSwitchToThread instead of switchToChannelById - Replace custom TextInput with PostDraft component in agent_chat - Fix icon name from message-reply-text-outline to reply-outline - Add missing i18n translations for agents UI * Implement automatic navigation to thread after sending agent message * Implement bot selector bottom sheet with avatars. Replace click-and-cycle behavior with a proper bottom sheet menu showing all available agents with their profile pictures. Add bot avatar display to the dropdown button for better visual identification. * Top bar design modifications. * Add intro graphic and text * Fix autocomplete not working * Tweak styles and icons. * Remove unused * Add version/enabled check * Remove excessive agent button * Style fixes * Use non-blocking then() for onPostCreated callback in send message hook * Add unit tests for agents product components and actions * Review feedback, offline support * I18n * Tests * Address PR review feedback: deletion handling, UI fixes, schema docs * Remove unnecessary deleteNotPresent flag from agents handlers * Fix agents archived channel, empty data guard, and stale relative time * Add smoke test for AgentChat and extend ToolCard test coverage * Fix test quality issues: remove useless tests, strengthen assertions * Address PR review: remove barrel file, add version comment * Mock reanimated in CitationsList test to fix CI failure * Fix CitationsList tests after always-mounted animation change * Address PR review: typography, Pressable, FormattedText, schema bump, and cleanup * Apply CLAUDE.md patterns across agents codebase: Pressable, typography, FormattedText, logDebug * Fix schema test to expect version 19
134 lines
3.9 KiB
TypeScript
134 lines
3.9 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import React, {useEffect, useState} from 'react';
|
|
|
|
import Autocomplete from '@components/autocomplete';
|
|
import {useServerUrl} from '@context/server';
|
|
import {useAutocompleteDefaultAnimatedValues} from '@hooks/autocomplete';
|
|
import {useDefaultHeaderHeight} from '@hooks/header';
|
|
|
|
import Archived from './archived';
|
|
import DraftHandler from './draft_handler';
|
|
import ReadOnly from './read_only';
|
|
|
|
import type {AvailableScreens} from '@typings/screens/navigation';
|
|
|
|
const AUTOCOMPLETE_ADJUST = -5;
|
|
type Props = {
|
|
testID?: string;
|
|
canPost: boolean;
|
|
channelId: string;
|
|
channelIsArchived?: boolean;
|
|
channelIsReadOnly: boolean;
|
|
deactivatedChannel: boolean;
|
|
files?: FileInfo[];
|
|
isSearch?: boolean;
|
|
message?: string;
|
|
rootId?: string;
|
|
containerHeight: number;
|
|
isChannelScreen: boolean;
|
|
canShowPostPriority?: boolean;
|
|
location: AvailableScreens;
|
|
onPostCreated?: (postId: string) => void;
|
|
}
|
|
|
|
function PostDraft({
|
|
testID,
|
|
canPost,
|
|
channelId,
|
|
channelIsArchived,
|
|
channelIsReadOnly,
|
|
deactivatedChannel,
|
|
files,
|
|
isSearch,
|
|
message = '',
|
|
rootId = '',
|
|
containerHeight,
|
|
isChannelScreen,
|
|
canShowPostPriority,
|
|
location,
|
|
onPostCreated,
|
|
}: Props) {
|
|
const [value, setValue] = useState(message);
|
|
const [cursorPosition, setCursorPosition] = useState(message.length);
|
|
const [postInputTop, setPostInputTop] = useState(0);
|
|
const [isFocused, setIsFocused] = useState(false);
|
|
const headerHeight = useDefaultHeaderHeight();
|
|
const serverUrl = useServerUrl();
|
|
|
|
// Update draft in case we switch channels or threads
|
|
useEffect(() => {
|
|
setValue(message);
|
|
setCursorPosition(message.length);
|
|
}, [channelId, message, rootId]);
|
|
|
|
const autocompletePosition = postInputTop + AUTOCOMPLETE_ADJUST;
|
|
const autocompleteAvailableSpace = containerHeight - autocompletePosition - (isChannelScreen ? headerHeight : 0);
|
|
const [animatedAutocompletePosition, animatedAutocompleteAvailableSpace] = useAutocompleteDefaultAnimatedValues(autocompletePosition, autocompleteAvailableSpace);
|
|
|
|
if (channelIsArchived || deactivatedChannel) {
|
|
const archivedTestID = `${testID}.archived`;
|
|
|
|
return (
|
|
<Archived
|
|
testID={archivedTestID}
|
|
deactivated={deactivatedChannel}
|
|
location={location}
|
|
/>
|
|
);
|
|
}
|
|
|
|
if (channelIsReadOnly || !canPost) {
|
|
const readOnlyTestID = `${testID}.read_only`;
|
|
|
|
return (
|
|
<ReadOnly
|
|
testID={readOnlyTestID}
|
|
/>
|
|
);
|
|
}
|
|
|
|
const draftHandler = (
|
|
<DraftHandler
|
|
testID={testID}
|
|
channelId={channelId}
|
|
cursorPosition={cursorPosition}
|
|
files={files}
|
|
rootId={rootId}
|
|
canShowPostPriority={canShowPostPriority}
|
|
updateCursorPosition={setCursorPosition}
|
|
updatePostInputTop={setPostInputTop}
|
|
updateValue={setValue}
|
|
value={value}
|
|
setIsFocused={setIsFocused}
|
|
onPostCreated={onPostCreated}
|
|
location={location}
|
|
/>
|
|
);
|
|
|
|
const autoComplete = isFocused ? (
|
|
<Autocomplete
|
|
position={animatedAutocompletePosition}
|
|
updateValue={setValue}
|
|
rootId={rootId}
|
|
channelId={channelId}
|
|
cursorPosition={cursorPosition}
|
|
value={value}
|
|
isSearch={isSearch}
|
|
shouldDirectlyReact={!Boolean(files?.length)}
|
|
availableSpace={animatedAutocompleteAvailableSpace}
|
|
serverUrl={serverUrl}
|
|
usePortal={true}
|
|
/>
|
|
) : null;
|
|
|
|
return (
|
|
<>
|
|
{draftHandler}
|
|
{autoComplete}
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default PostDraft;
|