Skip to content

Commit

Permalink
CW-mention-arrow-bug
Browse files Browse the repository at this point in the history
Added filtering for AI name
  • Loading branch information
MeyerPV committed Oct 1, 2024
1 parent d0483cf commit fd4dbf7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 10 additions & 1 deletion src/shared/ui-kit/TextEditor/BaseTextEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import {
checkIsEmptyCheckboxCreationText,
} from "./utils";
import styles from "./BaseTextEditor.module.scss";
import { useFeatureFlag } from "@/shared/hooks";
import { AI_PRO_USER, AI_USER, FeatureFlags } from "@/shared/constants";

export interface BaseTextEditorHandles {
focus: () => void;
Expand Down Expand Up @@ -123,6 +125,13 @@ const BaseTextEditor = forwardRef<BaseTextEditorHandles, TextEditorProps>((props
),
[],
);
const featureFlags = useFeatureFlag();
const isAiBotProEnabled = featureFlags?.get(FeatureFlags.AiBotPro);

const usersWithAI = useMemo(
() => [isAiBotProEnabled ? AI_PRO_USER : AI_USER, ...(users ?? [])],
[users],
);

const [target, setTarget] = useState<Range | null>();
const [shouldFocusTarget, setShouldFocusTarget] = useState(false);
Expand Down Expand Up @@ -227,7 +236,7 @@ const BaseTextEditor = forwardRef<BaseTextEditorHandles, TextEditorProps>((props
}
};

const chars = (users ?? []).filter((user) => {
const chars = (usersWithAI ?? []).filter((user) => {
return getUserName(user)
?.toLowerCase()
.startsWith(search.text.substring(1).toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React, { FC, useEffect, useMemo, useRef, useState } from "react";
import { uniq } from "lodash";
import { UserAvatar } from "@/shared/components";
import { AI_PRO_USER, AI_USER, FeatureFlags } from "@/shared/constants";
import { KeyboardKeys } from "@/shared/constants/keyboardKeys";
import { useOutsideClick } from "@/shared/hooks";
import { useFeatureFlag } from "@/shared/hooks/useFeatureFlag";
import { User } from "@/shared/models";
import { Loader } from "@/shared/ui-kit";
import { getUserName } from "@/shared/utils";
Expand All @@ -22,20 +20,15 @@ export interface MentionDropdownProps {
const MentionDropdown: FC<MentionDropdownProps> = (props) => {
const {
onClick,
users: initialUsers = [],
users = [],
onClose,
shouldFocusTarget,
} = props;
const mentionRef = useRef(null);
const listRefs = useRef<HTMLLIElement[]>([]);
const featureFlags = useFeatureFlag();
const isAiBotProEnabled = featureFlags?.get(FeatureFlags.AiBotPro);
const { isOutside, setOutsideValue } = useOutsideClick(mentionRef);
const [index, setIndex] = useState(0);
const users = useMemo(
() => [isAiBotProEnabled ? AI_PRO_USER : AI_USER, ...initialUsers],
[initialUsers, isAiBotProEnabled],
);

const userIds = useMemo(() => users.map(({ uid }) => uid), [users]);

useEffect(() => {
Expand Down

0 comments on commit fd4dbf7

Please sign in to comment.