feat: search activities (#972)
This commit is contained in:
@ -107,7 +107,7 @@ export function Timeline({ entity }: { entity: CommentableEntity }) {
|
||||
},
|
||||
});
|
||||
|
||||
const openCreateCommandThread = useOpenCreateActivityDrawer();
|
||||
const openCreateActivity = useOpenCreateActivityDrawer();
|
||||
|
||||
const activities: ActivityForDrawer[] = queryResult?.findManyActivities ?? [];
|
||||
|
||||
@ -121,8 +121,8 @@ export function Timeline({ entity }: { entity: CommentableEntity }) {
|
||||
<StyledEmptyTimelineTitle>No activity yet</StyledEmptyTimelineTitle>
|
||||
<StyledEmptyTimelineSubTitle>Create one:</StyledEmptyTimelineSubTitle>
|
||||
<ActivityCreateButton
|
||||
onNoteClick={() => openCreateCommandThread(entity, ActivityType.Note)}
|
||||
onTaskClick={() => openCreateCommandThread(entity, ActivityType.Task)}
|
||||
onNoteClick={() => openCreateActivity(entity, ActivityType.Note)}
|
||||
onTaskClick={() => openCreateActivity(entity, ActivityType.Task)}
|
||||
/>
|
||||
</StyledTimelineEmptyContainer>
|
||||
);
|
||||
@ -132,8 +132,8 @@ export function Timeline({ entity }: { entity: CommentableEntity }) {
|
||||
<StyledMainContainer>
|
||||
<StyledTopActionBar>
|
||||
<ActivityCreateButton
|
||||
onNoteClick={() => openCreateCommandThread(entity, ActivityType.Note)}
|
||||
onTaskClick={() => openCreateCommandThread(entity, ActivityType.Task)}
|
||||
onNoteClick={() => openCreateActivity(entity, ActivityType.Note)}
|
||||
onTaskClick={() => openCreateActivity(entity, ActivityType.Task)}
|
||||
/>
|
||||
</StyledTopActionBar>
|
||||
<StyledTimelineContainer>
|
||||
|
||||
@ -1,11 +1,18 @@
|
||||
import { useState } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
|
||||
import { useFilteredSearchCompanyQuery } from '@/companies/queries';
|
||||
import { useFilteredSearchPeopleQuery } from '@/people/queries';
|
||||
import { useOpenActivityRightDrawer } from '@/activities/hooks/useOpenActivityRightDrawer';
|
||||
import { useScopedHotkeys } from '@/ui/hotkey/hooks/useScopedHotkeys';
|
||||
import { AppHotkeyScope } from '@/ui/hotkey/types/AppHotkeyScope';
|
||||
import { IconNotes } from '@/ui/icon';
|
||||
import { Avatar } from '@/users/components/Avatar';
|
||||
import {
|
||||
QueryMode,
|
||||
useSearchActivityQuery,
|
||||
useSearchCompanyQuery,
|
||||
useSearchPeopleQuery,
|
||||
} from '~/generated/graphql';
|
||||
import { getLogoUrlFromDomainName } from '~/utils';
|
||||
|
||||
import { useCommandMenu } from '../hooks/useCommandMenu';
|
||||
import { isCommandMenuOpenedState } from '../states/isCommandMenuOpenedState';
|
||||
@ -21,6 +28,7 @@ import {
|
||||
|
||||
export function CommandMenu() {
|
||||
const { openCommandMenu, closeCommandMenu } = useCommandMenu();
|
||||
const openActivityRightDrawer = useOpenActivityRightDrawer();
|
||||
const isCommandMenuOpened = useRecoilValue(isCommandMenuOpenedState);
|
||||
const [search, setSearch] = useState('');
|
||||
|
||||
@ -33,16 +41,41 @@ export function CommandMenu() {
|
||||
[openCommandMenu],
|
||||
);
|
||||
|
||||
const people = useFilteredSearchPeopleQuery({
|
||||
searchFilter: search,
|
||||
selectedIds: [],
|
||||
limit: 3,
|
||||
const { data: peopleData } = useSearchPeopleQuery({
|
||||
variables: {
|
||||
where: {
|
||||
OR: [
|
||||
{ firstName: { contains: search, mode: QueryMode.Insensitive } },
|
||||
{ lastName: { contains: search, mode: QueryMode.Insensitive } },
|
||||
],
|
||||
},
|
||||
limit: 3,
|
||||
},
|
||||
});
|
||||
const companies = useFilteredSearchCompanyQuery({
|
||||
searchFilter: search,
|
||||
selectedIds: [],
|
||||
limit: 3,
|
||||
const people = peopleData?.searchResults ?? [];
|
||||
|
||||
const { data: companyData } = useSearchCompanyQuery({
|
||||
variables: {
|
||||
where: {
|
||||
OR: [{ name: { contains: search, mode: QueryMode.Insensitive } }],
|
||||
},
|
||||
limit: 3,
|
||||
},
|
||||
});
|
||||
const companies = companyData?.searchResults ?? [];
|
||||
|
||||
const { data: activityData } = useSearchActivityQuery({
|
||||
variables: {
|
||||
where: {
|
||||
OR: [
|
||||
{ title: { contains: search, mode: QueryMode.Insensitive } },
|
||||
{ body: { contains: search, mode: QueryMode.Insensitive } },
|
||||
],
|
||||
},
|
||||
limit: 3,
|
||||
},
|
||||
});
|
||||
const activities = activityData?.searchResults ?? [];
|
||||
|
||||
/*
|
||||
TODO: Allow performing actions on page through CommandBar
|
||||
@ -99,35 +132,35 @@ export function CommandMenu() {
|
||||
/>
|
||||
<StyledList>
|
||||
<StyledEmpty>No results found.</StyledEmpty>
|
||||
{!!people.entitiesToSelect.length && (
|
||||
{!!people.length && (
|
||||
<StyledGroup heading="People">
|
||||
{people.entitiesToSelect.map((person) => (
|
||||
{people.map((person) => (
|
||||
<CommandMenuItem
|
||||
to={`person/${person.id}`}
|
||||
label={person.name}
|
||||
label={person.displayName}
|
||||
key={person.id}
|
||||
icon={
|
||||
<Avatar
|
||||
avatarUrl={person.avatarUrl}
|
||||
avatarUrl={null}
|
||||
size="sm"
|
||||
colorId={person.id}
|
||||
placeholder={person.name}
|
||||
placeholder={person.displayName}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
))}
|
||||
</StyledGroup>
|
||||
)}
|
||||
{!!companies.entitiesToSelect.length && (
|
||||
{!!companies.length && (
|
||||
<StyledGroup heading="Companies">
|
||||
{companies.entitiesToSelect.map((company) => (
|
||||
{companies.map((company) => (
|
||||
<CommandMenuItem
|
||||
to={`companies/${company.id}`}
|
||||
label={company.name}
|
||||
key={company.id}
|
||||
icon={
|
||||
<Avatar
|
||||
avatarUrl={company.avatarUrl}
|
||||
avatarUrl={getLogoUrlFromDomainName(company.domainName)}
|
||||
size="sm"
|
||||
colorId={company.id}
|
||||
placeholder={company.name}
|
||||
@ -137,6 +170,18 @@ export function CommandMenu() {
|
||||
))}
|
||||
</StyledGroup>
|
||||
)}
|
||||
{!!activities.length && (
|
||||
<StyledGroup heading="Notes">
|
||||
{activities.map((activity) => (
|
||||
<CommandMenuItem
|
||||
onClick={() => openActivityRightDrawer(activity.id)}
|
||||
label={activity.title ?? ''}
|
||||
key={activity.id}
|
||||
icon={<IconNotes />}
|
||||
/>
|
||||
))}
|
||||
</StyledGroup>
|
||||
)}
|
||||
<StyledGroup heading="Navigate">
|
||||
<CommandMenuItem
|
||||
to="/people"
|
||||
|
||||
@ -17,6 +17,8 @@ export const SEARCH_PEOPLE_QUERY = gql`
|
||||
city
|
||||
firstName
|
||||
lastName
|
||||
displayName
|
||||
avatarUrl
|
||||
createdAt
|
||||
}
|
||||
}
|
||||
@ -68,3 +70,21 @@ export const SEARCH_COMPANY_QUERY = gql`
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const SEARCH_ACTIVITY_QUERY = gql`
|
||||
query SearchActivity(
|
||||
$where: ActivityWhereInput
|
||||
$limit: Int
|
||||
$orderBy: [ActivityOrderByWithRelationInput!]
|
||||
) {
|
||||
searchResults: findManyActivities(
|
||||
where: $where
|
||||
take: $limit
|
||||
orderBy: $orderBy
|
||||
) {
|
||||
id
|
||||
title
|
||||
body
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user