Skip to content

Commit

Permalink
Merge pull request #1021 from The-Commit-Company/develop
Browse files Browse the repository at this point in the history
Version 1.6.8
  • Loading branch information
nikkothari22 authored Aug 17, 2024
2 parents b98d7db + 55cc1b7 commit b4c565a
Show file tree
Hide file tree
Showing 20 changed files with 794 additions and 450 deletions.
50 changes: 25 additions & 25 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "raven-ui",
"private": true,
"license": "AGPL-3.0-only",
"version": "1.6.7",
"version": "1.6.8",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -12,49 +12,49 @@
},
"dependencies": {
"@radix-ui/themes": "^3.1.3",
"@tiptap/extension-code-block-lowlight": "^2.5.9",
"@tiptap/extension-highlight": "^2.5.9",
"@tiptap/extension-image": "^2.5.9",
"@tiptap/extension-link": "^2.5.9",
"@tiptap/extension-mention": "^2.5.9",
"@tiptap/extension-placeholder": "^2.5.9",
"@tiptap/extension-table": "^2.5.9",
"@tiptap/extension-table-cell": "^2.5.9",
"@tiptap/extension-table-header": "^2.5.9",
"@tiptap/extension-table-row": "^2.5.9",
"@tiptap/extension-typography": "^2.5.9",
"@tiptap/extension-underline": "^2.5.9",
"@tiptap/pm": "^2.5.9",
"@tiptap/react": "^2.5.9",
"@tiptap/starter-kit": "^2.5.9",
"@tiptap/suggestion": "^2.5.9",
"@tiptap/extension-code-block-lowlight": "^2.6.4",
"@tiptap/extension-highlight": "^2.6.4",
"@tiptap/extension-image": "^2.6.4",
"@tiptap/extension-link": "^2.6.4",
"@tiptap/extension-mention": "^2.6.4",
"@tiptap/extension-placeholder": "^2.6.4",
"@tiptap/extension-table": "^2.6.4",
"@tiptap/extension-table-cell": "^2.6.4",
"@tiptap/extension-table-header": "^2.6.4",
"@tiptap/extension-table-row": "^2.6.4",
"@tiptap/extension-typography": "^2.6.4",
"@tiptap/extension-underline": "^2.6.4",
"@tiptap/pm": "^2.6.4",
"@tiptap/react": "^2.6.4",
"@tiptap/starter-kit": "^2.6.4",
"@tiptap/suggestion": "^2.6.4",
"@vitejs/plugin-react": "^4.3.1",
"autoprefixer": "^10.4.17",
"autoprefixer": "^10.4.20",
"cal-sans": "^1.0.1",
"clsx": "^2.1.0",
"cmdk": "^1.0.0",
"cva": "npm:class-variance-authority",
"dayjs": "^1.11.11",
"downshift": "^8.3.1",
"emoji-picker-element": "^1.22.2",
"emoji-picker-element": "^1.22.3",
"firebase": "^10.9.0",
"frappe-react-sdk": "^1.7.1",
"frappe-react-sdk": "^1.8.0",
"highlight.js": "^11.9.0",
"html-react-parser": "^5.1.8",
"jotai": "^2.9.2",
"jotai": "^2.9.3",
"js-cookie": "^3.0.5",
"lowlight": "^3.1.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.51.5",
"react-icons": "^5.2.1",
"react-hook-form": "^7.52.2",
"react-icons": "^5.3.0",
"react-idle-timer": "^5.7.2",
"react-intersection-observer": "^9.10.3",
"react-router-dom": "^6.23.1",
"react-router-dom": "^6.26.1",
"react-zoom-pan-pinch": "^3.4.4",
"sonner": "^1.5.0",
"tailwindcss": "^3.4.4",
"tailwindcss": "^3.4.10",
"tailwindcss-animate": "^1.0.7",
"tippy.js": "^6.3.7",
"turndown": "^7.2.0",
Expand Down
98 changes: 98 additions & 0 deletions frontend/src/components/common/LinkField/LinkField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@


import { useCombobox } from "downshift";
import { Filter, SearchResult, useSearch } from "frappe-react-sdk";
import { useState } from "react";
import { Label } from "../Form";
import { Text, TextField } from "@radix-ui/themes";
import { useIsDesktop } from "@/hooks/useMediaQuery";
import clsx from "clsx";

export interface LinkFieldProps {
doctype: string;
filters?: Filter[];
label?: string,
placeholder?: string,
value: string,
setValue: (value: string) => void,
disabled?: boolean,
autofocus?: boolean
}


const LinkField = ({ doctype, filters, label, placeholder, value, setValue, disabled, autofocus }: LinkFieldProps) => {

const [searchText, setSearchText] = useState('')

const isDesktop = useIsDesktop()

const { data } = useSearch(doctype, searchText, filters)

const items: SearchResult[] = data?.message ?? []

const {
isOpen,
// getToggleButtonProps,
getLabelProps,
getMenuProps,
getInputProps,
highlightedIndex,
getItemProps,
selectedItem,
} = useCombobox({
onInputValueChange({ inputValue }) {
setSearchText(inputValue ?? '')
},
items: items,
itemToString(item) {
return item ? item.value : ''
},
selectedItem: items.find(item => item.value === value),
onSelectedItemChange({ selectedItem }) {
setValue(selectedItem?.value ?? '')
},
})

return <div className="w-full">
<div className="flex flex-col gap-1">
<Label className="w-fit" {...getLabelProps()}>
{label}
</Label>
<TextField.Root
placeholder={placeholder ?? `Search ${doctype}`}
className='w-full'
disabled={disabled}
autoFocus={isDesktop && autofocus}
{...getInputProps()}
>

</TextField.Root>
</div>
<ul
className={`sm:w-[550px] w-[24rem] absolute bg-background rounded-b-md mt-1 shadow-md z-[9999] max-h-96 overflow-scroll p-0 ${!(isOpen && items.length) && 'hidden'
}`}
{...getMenuProps()}
>
{isOpen &&
items.map((item, index) => (
<li
className={clsx(
highlightedIndex === index && 'bg-accent-4',
selectedItem === item && 'font-bold',
'py-2 px-3 shadow-sm flex gap-2 items-center',
)}
key={`${item.value}`}
{...getItemProps({ item, index })}
>
<div className='flex flex-col'>
<Text as='span' weight='medium' size='2'>{item.label ?? item.value}</Text>
<Text as='span' size='1' color='gray'>{item.description}</Text>
</div>

</li>
))}
</ul>
</div>
}

export default LinkField
30 changes: 30 additions & 0 deletions frontend/src/components/common/LinkField/LinkFormField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Controller, ControllerProps, useFormContext } from 'react-hook-form'
import LinkField, { LinkFieldProps } from './LinkField'

interface LinkFormFieldProps extends Omit<LinkFieldProps, 'value' | 'setValue'> {
name: string,
rules: ControllerProps['rules'],
disabled?: boolean
}

const LinkFormField = ({ name, rules, ...linkFieldProps }: LinkFormFieldProps) => {

const { control } = useFormContext()
return (
<Controller
name={name}
control={control}
disabled={linkFieldProps.disabled}
rules={rules}
render={({ field }) => (
<LinkField
value={field.value}
setValue={field.onChange}
{...linkFieldProps}
/>
)}
/>
)
}

export default LinkFormField
25 changes: 10 additions & 15 deletions frontend/src/components/feature/GlobalSearch/ChannelSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import { Flex, Select, TextField, Box, Checkbox, ScrollArea, Text, Badge } from
import { Loader } from '@/components/common/Loader'
interface Props {
onToggleMyChannels: () => void,
isOpenMyChannels: boolean,
isOnlyInMyChannels: boolean,
input: string,
onClose: () => void
}

export const ChannelSearch = ({ onToggleMyChannels, isOpenMyChannels, input, onClose }: Props) => {
export const ChannelSearch = ({ onToggleMyChannels, isOnlyInMyChannels, input, onClose }: Props) => {

const [searchText, setSearchText] = useState(input)
const debouncedText = useDebounce(searchText)
Expand All @@ -31,10 +31,9 @@ export const ChannelSearch = ({ onToggleMyChannels, isOpenMyChannels, input, onC

const { data, error, isLoading } = useFrappeGetCall<{ message: GetChannelSearchResult[] }>("raven.api.search.get_search_result", {
filter_type: 'Channel',
doctype: 'Raven Channel',
search_text: debouncedText,
channel_type: channelType === 'any' ? undefined : channelType,
my_channel_only: isOpenMyChannels,
my_channel_only: isOnlyInMyChannels,
}, undefined, {
revalidateOnFocus: false
})
Expand Down Expand Up @@ -94,22 +93,19 @@ export const ChannelSearch = ({ onToggleMyChannels, isOpenMyChannels, input, onC
</Select.Content>
</Select.Root>


<Text as="label" className='hidden sm:block' style={{
width: '20%'
}}>
<Text as="label" className='hidden sm:block' style={{ width: '20%' }} size="2">
<Flex gap="2" align='center'>
<Checkbox checked={isOpenMyChannels} onCheckedChange={onToggleMyChannels} /> Only in my channels
<Checkbox checked={isOnlyInMyChannels} onCheckedChange={onToggleMyChannels} /> Only in my channels
</Flex>
</Text>

</Flex>
</Flex>
<ScrollArea type="always" scrollbars="vertical" className='sm:h-[420px] h-[58vh]' mt='4'>
<ErrorBanner error={error} />
{data?.message?.length === 0 && <EmptyStateForSearch />}
{data?.message && data.message.length > 0 ?
<Flex direction='column' gap='2' pr='4'>

<Flex direction='column' gap='0.5' pr='4'>
{data.message.map((channel: GetChannelSearchResult) => {
return (
<Box p='2'
Expand All @@ -121,16 +117,15 @@ export const ChannelSearch = ({ onToggleMyChannels, isOpenMyChannels, input, onC
}}
key={channel.name}>
<Flex gap='2' align='center'>
<ChannelIcon type={channel.type} size='20' />
<ChannelIcon type={channel.type} size='15' />
<Flex gap='3'>
<Text as='span' weight='medium'>{channel.channel_name}</Text>
<Text size={'2'} as='span' weight='medium'>{channel.channel_name}</Text>
{channel.is_archived ? <Badge variant='soft' color='gray' size='1'>Archived</Badge> : null}
</Flex>
</Flex>
</Box>
)
}
)}
})}
</Flex> : null}
</ScrollArea>
</Box>
Expand Down
21 changes: 9 additions & 12 deletions frontend/src/components/feature/GlobalSearch/FileSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { dateOption } from './GlobalSearch'

interface Props {
onToggleMyChannels: () => void,
isOpenMyChannels: boolean,
isOnlyInMyChannels: boolean,
input: string,
fromFilter?: string,
withFilter?: string,
Expand All @@ -36,7 +36,7 @@ export interface FileSearchResult {
message_type: string
}

export const FileSearch = ({ onToggleMyChannels, isOpenMyChannels, onToggleSaved, isSaved, input, fromFilter, withFilter, inFilter }: Props) => {
export const FileSearch = ({ onToggleMyChannels, isOnlyInMyChannels, onToggleSaved, isSaved, input, fromFilter, withFilter, inFilter }: Props) => {

const [searchText, setSearchText] = useState(input)
const debouncedText = useDebounce(searchText)
Expand All @@ -54,23 +54,20 @@ export const FileSearch = ({ onToggleMyChannels, isOpenMyChannels, onToggleSaved

const users = useGetUserRecords()


const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setSearchText(e.target.value)
}


const { data, error, isLoading } = useFrappeGetCall<{ message: GetFileSearchResult[] }>("raven.api.search.get_search_result", {
filter_type: 'File',
doctype: 'Raven Message',
search_text: debouncedText,
message_type: fileType === 'any' || fileType === undefined ? undefined : fileType === 'image' ? 'Image' : 'File',
file_type: fileType === 'any' ? undefined : fileType,
in_channel: channelFilter,
from_user: userFilter,
from_user: userFilter === 'any' ? undefined : userFilter,
in_channel: channelFilter === 'any' ? undefined : channelFilter,
saved: isSaved,
date: dateFilter,
my_channel_only: isOpenMyChannels,
file_type: fileType === 'any' ? undefined : fileType,
message_type: fileType === 'any' || fileType === undefined ? undefined : fileType === 'image' ? 'Image' : 'File',
my_channel_only: isOnlyInMyChannels,
}, undefined, {
revalidateOnFocus: false
})
Expand Down Expand Up @@ -215,7 +212,7 @@ export const FileSearch = ({ onToggleMyChannels, isOpenMyChannels, onToggleSaved

<Text as="label" size="2">
<Flex gap="2">
<Checkbox checked={isOpenMyChannels} onCheckedChange={onToggleMyChannels} /> Only in my channels
<Checkbox checked={isOnlyInMyChannels} onCheckedChange={onToggleMyChannels} /> Only in my channels
</Flex>
</Text>

Expand Down Expand Up @@ -244,7 +241,7 @@ export const FileSearch = ({ onToggleMyChannels, isOpenMyChannels, onToggleSaved
/>}
</Flex>
<Flex direction='column' className='w-[94%]'>
{f.file && <Link weight='medium' size='2' href={f.file} target='_blank'>{getFileName(f.file)} {f.file}</Link>}
{f.file && <Link weight='medium' size='1' href={f.file} target='_blank'>{getFileName(f.file)}</Link>}
{users && <Text size='1' color='gray'>Shared by {Object.values(users).find((user: UserFields) => user.name === f.owner)?.full_name} on <DateMonthYear date={f.creation} /></Text>}
</Flex>
</Flex>
Expand Down
9 changes: 4 additions & 5 deletions frontend/src/components/feature/GlobalSearch/GlobalSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ interface GlobalSearchModalProps {

export default function GlobalSearch(props: GlobalSearchModalProps) {


const { isOpen, onClose } = props

const onOpenChange = (open: boolean) => {
Expand Down Expand Up @@ -56,7 +55,7 @@ export default function GlobalSearch(props: GlobalSearchModalProps) {

const GlobalSearchContent = (props: GlobalSearchModalProps) => {

const [isOpenMyChannels, { toggle: onToggleMyChannels }] = useBoolean()
const [isOnlyInMyChannels, { toggle: onToggleMyChannels }] = useBoolean()
const [isSaved, { toggle: onToggleSaved }] = useBoolean()

const { tabIndex, input, fromFilter, withFilter, inFilter, onClose } = props
Expand All @@ -71,13 +70,13 @@ const GlobalSearchContent = (props: GlobalSearchModalProps) => {
</Tabs.List>
<Box pt="3" pb="2">
<Tabs.Content value="0">
<MessageSearch onToggleMyChannels={onToggleMyChannels} isOpenMyChannels={isOpenMyChannels} onToggleSaved={onToggleSaved} isSaved={isSaved} input={input} fromFilter={fromFilter} inFilter={inFilter} withFilter={withFilter} onClose={onClose} />
<MessageSearch onToggleMyChannels={onToggleMyChannels} isOnlyInMyChannels={isOnlyInMyChannels} onToggleSaved={onToggleSaved} isSaved={isSaved} input={input} fromFilter={fromFilter} inFilter={inFilter} withFilter={withFilter} onClose={onClose} />
</Tabs.Content>
<Tabs.Content value="1">
<FileSearch onToggleMyChannels={onToggleMyChannels} isOpenMyChannels={isOpenMyChannels} onToggleSaved={onToggleSaved} isSaved={isSaved} input={input} fromFilter={fromFilter} inFilter={inFilter} withFilter={withFilter} />
<FileSearch onToggleMyChannels={onToggleMyChannels} isOnlyInMyChannels={isOnlyInMyChannels} onToggleSaved={onToggleSaved} isSaved={isSaved} input={input} fromFilter={fromFilter} inFilter={inFilter} withFilter={withFilter} />
</Tabs.Content>
<Tabs.Content value="2">
<ChannelSearch onToggleMyChannels={onToggleMyChannels} isOpenMyChannels={isOpenMyChannels} input={input} onClose={onClose} />
<ChannelSearch onToggleMyChannels={onToggleMyChannels} isOnlyInMyChannels={isOnlyInMyChannels} input={input} onClose={onClose} />
</Tabs.Content>
</Box>
</Tabs.Root>
Expand Down
Loading

0 comments on commit b4c565a

Please sign in to comment.