-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[AI] Refactor settings search to use SearchInput and restructure Skills tab #18876
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
4 commits
Select commit
Hold shift + click to select a range
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
162 changes: 162 additions & 0 deletions
162
packages/twenty-front/src/pages/settings/ai/components/SettingsAgentSkills.tsx
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,162 @@ | ||
| import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar'; | ||
| import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown'; | ||
| import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent'; | ||
| import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer'; | ||
| import { useSortedArray } from '@/ui/layout/table/hooks/useSortedArray'; | ||
| import { styled } from '@linaria/react'; | ||
| import { useLingui } from '@lingui/react/macro'; | ||
| import { useContext, useMemo, useState } from 'react'; | ||
| import { SettingsPath } from 'twenty-shared/types'; | ||
| import { getSettingsPath } from 'twenty-shared/utils'; | ||
| import { H2Title, IconArchive, IconPlus } from 'twenty-ui/display'; | ||
| import { Button, SearchInput } from 'twenty-ui/input'; | ||
| import { MenuItemToggle, UndecoratedLink } from 'twenty-ui/navigation'; | ||
| import { ThemeContext, themeCssVariables } from 'twenty-ui/theme-constants'; | ||
|
|
||
| import { useMutation, useQuery } from '@apollo/client/react'; | ||
| import { Section } from 'twenty-ui/layout'; | ||
| import { | ||
| ActivateSkillDocument, | ||
| DeleteSkillDocument, | ||
| FindManySkillsDocument, | ||
| } from '~/generated-metadata/graphql'; | ||
| import { SETTINGS_SKILL_TABLE_METADATA } from '~/pages/settings/ai/constants/SettingsSkillTableMetadata'; | ||
| import { normalizeSearchText } from '~/utils/normalizeSearchText'; | ||
| import { SettingsAgentSkillsTable } from './SettingsAgentSkillsTable'; | ||
|
|
||
| const StyledCoverImage = styled.div` | ||
| background-size: cover; | ||
| height: 160px; | ||
| overflow: hidden; | ||
| `; | ||
|
|
||
| const StyledFooterContainer = styled.div` | ||
| align-items: center; | ||
| display: flex; | ||
| justify-content: flex-end; | ||
| margin-top: ${themeCssVariables.spacing[4]}; | ||
| `; | ||
|
|
||
| const StyledSearchInput = styled(SearchInput)` | ||
| margin-bottom: ${themeCssVariables.spacing[4]}; | ||
| `; | ||
|
|
||
| export const SettingsAgentSkills = () => { | ||
| const { t } = useLingui(); | ||
| const { colorScheme } = useContext(ThemeContext); | ||
| const { enqueueSuccessSnackBar, enqueueErrorSnackBar } = useSnackBar(); | ||
|
|
||
| const { data, loading, refetch } = useQuery(FindManySkillsDocument); | ||
| const [activateSkill] = useMutation(ActivateSkillDocument); | ||
| const [deleteSkill] = useMutation(DeleteSkillDocument); | ||
|
|
||
| const [searchTerm, setSearchTerm] = useState(''); | ||
| const [showDeactivated, setShowDeactivated] = useState(true); | ||
|
|
||
| const skills = data?.skills ?? []; | ||
|
|
||
| const sortedSkills = useSortedArray(skills, SETTINGS_SKILL_TABLE_METADATA); | ||
|
|
||
| const filteredSkills = useMemo( | ||
| () => | ||
| sortedSkills.filter((skill) => { | ||
| const searchNormalized = normalizeSearchText(searchTerm); | ||
| const matchesSearch = | ||
| normalizeSearchText(skill.name).includes(searchNormalized) || | ||
| normalizeSearchText(skill.label).includes(searchNormalized); | ||
|
|
||
| if (!matchesSearch) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!skill.isActive && !showDeactivated) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| }), | ||
| [sortedSkills, searchTerm, showDeactivated], | ||
| ); | ||
|
|
||
| const handleActivate = async (skillId: string) => { | ||
| try { | ||
| await activateSkill({ variables: { id: skillId } }); | ||
| enqueueSuccessSnackBar({ message: t`Skill activated` }); | ||
| refetch(); | ||
| } catch { | ||
| enqueueErrorSnackBar({ message: t`Failed to activate skill` }); | ||
| } | ||
| }; | ||
|
|
||
| const handleDelete = async (skillId: string) => { | ||
| try { | ||
| await deleteSkill({ variables: { id: skillId } }); | ||
| enqueueSuccessSnackBar({ message: t`Skill deleted` }); | ||
| refetch(); | ||
| } catch { | ||
| enqueueErrorSnackBar({ message: t`Failed to delete skill` }); | ||
| } | ||
| }; | ||
|
|
||
| const coverImage = | ||
| colorScheme === 'light' | ||
| ? '/images/ai/ai-skills-cover-light.png' | ||
| : '/images/ai/ai-skills-cover-dark.png'; | ||
|
|
||
| return ( | ||
| <> | ||
| <StyledCoverImage style={{ backgroundImage: `url('${coverImage}')` }} /> | ||
| <Section> | ||
| <H2Title | ||
| title={t`Skills`} | ||
| description={t`Use filter to see existing tools or create your own`} | ||
| /> | ||
|
|
||
| <StyledSearchInput | ||
| placeholder={t`Search a skill...`} | ||
| value={searchTerm} | ||
| onChange={setSearchTerm} | ||
| filterDropdown={(filterButton) => ( | ||
| <Dropdown | ||
| dropdownId="settings-skills-filter-dropdown" | ||
| dropdownPlacement="bottom-end" | ||
| dropdownOffset={{ x: 0, y: 8 }} | ||
| clickableComponent={filterButton} | ||
| dropdownComponents={ | ||
| <DropdownContent> | ||
| <DropdownMenuItemsContainer> | ||
| <MenuItemToggle | ||
| LeftIcon={IconArchive} | ||
| onToggleChange={() => | ||
| setShowDeactivated(!showDeactivated) | ||
| } | ||
| toggled={showDeactivated} | ||
| text={t`Deactivated`} | ||
| toggleSize="small" | ||
| /> | ||
| </DropdownMenuItemsContainer> | ||
| </DropdownContent> | ||
| } | ||
| /> | ||
| )} | ||
| /> | ||
| <SettingsAgentSkillsTable | ||
| skills={filteredSkills} | ||
| loading={loading} | ||
| onActivate={handleActivate} | ||
| onDelete={handleDelete} | ||
| /> | ||
| <StyledFooterContainer> | ||
| <UndecoratedLink to={getSettingsPath(SettingsPath.AINewSkill)}> | ||
| <Button | ||
| Icon={IconPlus} | ||
| title={t`New Skill`} | ||
| size="small" | ||
| variant="secondary" | ||
| /> | ||
| </UndecoratedLink> | ||
| </StyledFooterContainer> | ||
| </Section> | ||
| </> | ||
| ); | ||
| }; | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Use a single search field for custom-object filtering instead of matching both
nameandlabel.(Based on your team's feedback about keeping custom-object search vectors single-field.)
View Feedback
Prompt for AI agents