-
Notifications
You must be signed in to change notification settings - Fork 0
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
626 save advanced searches #629
Open
elevchyt
wants to merge
23
commits into
main
Choose a base branch
from
626-save-advanced-searches
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
8a19c45
base layout
7a4fcdf
userId/orgId - queryString name is now unique
trixobird 469b748
more layout changes + graphql query for searchQueryStrings
884bb7d
graphql fixes
eb68bce
data flow
5d680de
cleanup
9d61f90
remove isOrg from deleteSearchQueryString
trixobird aa002e7
delete search action
216df98
saved searches dropdown & delete logic
fea2727
create & update search operation with access rights
039ee3c
access rights fix
3db0bc9
update search name logic
feda13f
update org search fix
f5a0800
translations
fe9c601
more translations
29bf088
save as org access rights
aa2becb
type fix
c7d6007
Update apps/web/src/components/search/saved-searches/saved-searches.tsx
elevchyt ee894da
Update apps/web/src/components/search/saved-searches/saved-searches.tsx
elevchyt 2b50ea7
Update apps/web/src/components/search/saved-searches/saved-searches.tsx
elevchyt ca1f4f9
Update apps/web/src/components/search/saved-searches/saved-searches.tsx
elevchyt 3de5a8e
translation fix
0c7711d
disabled save fix
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
This file contains 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 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 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 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 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 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 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 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,4 @@ | ||
import { atom } from 'jotai'; | ||
import { type SearchQueryStringsQuery } from '@/graphql/generated/schema-server'; | ||
|
||
export const searchesAtom = atom<SearchQueryStringsQuery['searchQueryStrings']>([]); |
This file contains 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 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 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,43 @@ | ||
'use client'; | ||
|
||
import { ActionIcon, Text, Tooltip } from '@mantine/core'; | ||
import { modals } from '@mantine/modals'; | ||
import { IconTrash } from '@tabler/icons-react'; | ||
import { useTranslations } from 'next-intl'; | ||
|
||
interface PropsType { | ||
canUserAlter: boolean; | ||
selectedSearchID: string | null; | ||
isPending: boolean; | ||
handleDelete: () => void; | ||
} | ||
|
||
export default function Delete(props: PropsType): React.ReactNode { | ||
const tSearch = useTranslations('insights.search'); | ||
|
||
const openModal = (): void => { | ||
modals.openConfirmModal({ | ||
title: tSearch('deleteSearchPresetTitle'), | ||
children: <Text size="sm">{tSearch('deleteDescription')}</Text>, | ||
labels: { confirm: tSearch('delete'), cancel: tSearch('cancel') }, | ||
confirmProps: { loading: props.isPending, color: 'red' }, | ||
onConfirm: () => { | ||
props.handleDelete(); | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Tooltip label={tSearch('delete')}> | ||
<ActionIcon | ||
disabled={props.isPending || !props.selectedSearchID || !props.canUserAlter} | ||
color="red.4" | ||
variant="outline" | ||
size={34} | ||
onClick={openModal} | ||
> | ||
<IconTrash /> | ||
</ActionIcon> | ||
</Tooltip> | ||
); | ||
} |
This file contains 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,115 @@ | ||
'use client'; | ||
|
||
import { ActionIcon, Flex, Radio, Text, TextInput, Tooltip } from '@mantine/core'; | ||
import { useForm, zodResolver } from '@mantine/form'; | ||
import { modals } from '@mantine/modals'; | ||
import { IconDeviceFloppy } from '@tabler/icons-react'; | ||
import { useTranslations } from 'next-intl'; | ||
import { useEffect, useRef } from 'react'; | ||
import { z } from 'zod'; | ||
|
||
interface PropsType { | ||
canUserAlter: boolean; | ||
canSaveAsOrg: boolean; | ||
selectedSearchID: string | null; | ||
selectedSearchName: string; | ||
isSelectedSearchOrganization: boolean; | ||
isPending: boolean; | ||
handleSave: (name: string, isOrganization: boolean, id: string | null) => void; | ||
} | ||
|
||
enum SaveTypes { | ||
Update = 'Update', | ||
SaveAsNew = 'SaveAsNew', | ||
SaveAsNewForOrg = 'SaveAsNewForOrg', | ||
} | ||
|
||
const ValidationSchema = z.object({ | ||
name: z.string().min(1, { message: 'Name is required' }), | ||
}); | ||
|
||
export default function Save(props: PropsType): React.ReactNode { | ||
const tSearch = useTranslations('insights.search'); | ||
const nameRef = useRef<HTMLInputElement>(null); | ||
|
||
const form = useForm({ | ||
mode: 'uncontrolled', | ||
initialValues: { | ||
name: '', | ||
saveType: SaveTypes.SaveAsNew, | ||
}, | ||
validate: zodResolver(ValidationSchema), | ||
}); | ||
|
||
// Synchronize form name with selectedSearchName whenever props.selectedSearchName changes | ||
useEffect(() => { | ||
form.setFieldValue('name', props.selectedSearchName); | ||
}, [form, props.selectedSearchName]); | ||
|
||
const getFormNameValue = (): string => { | ||
if (!nameRef.current) return ''; | ||
return nameRef.current.value; | ||
}; | ||
|
||
const openModal = (): void => { | ||
modals.openConfirmModal({ | ||
title: tSearch('saveSearchPresetTitle'), | ||
children: ( | ||
<form | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
}} | ||
> | ||
<Flex direction="column" gap="sm"> | ||
<TextInput | ||
description={tSearch('presetName')} | ||
placeholder={tSearch('presetName')} | ||
mb="sm" | ||
key={form.key('name')} | ||
{...form.getInputProps('name')} | ||
ref={nameRef} | ||
/> | ||
<Text size="sm">{tSearch('saveDescription')}</Text> | ||
<Radio.Group key={form.key('saveType')} {...form.getInputProps('saveType')}> | ||
<Flex direction="column" gap="sm"> | ||
<Radio | ||
disabled={!props.selectedSearchID || !props.canUserAlter} | ||
value={SaveTypes.Update} | ||
label={tSearch('updateSelectedSearch')} | ||
/> | ||
<Radio value={SaveTypes.SaveAsNew} label={tSearch('saveAsNewUser')} /> | ||
<Radio | ||
value={SaveTypes.SaveAsNewForOrg} | ||
label={tSearch('saveAsNewOrg')} | ||
disabled={!props.canSaveAsOrg} | ||
/> | ||
</Flex> | ||
</Radio.Group> | ||
</Flex> | ||
</form> | ||
), | ||
labels: { confirm: tSearch('save'), cancel: tSearch('cancel') }, | ||
confirmProps: { loading: props.isPending }, | ||
onCancel: () => { | ||
form.reset(); | ||
}, | ||
onConfirm: () => { | ||
const name = getFormNameValue(); | ||
const values = form.getValues(); | ||
let isOrganization = values.saveType === SaveTypes.SaveAsNewForOrg; | ||
if (values.saveType === SaveTypes.Update) isOrganization = props.isSelectedSearchOrganization; | ||
const idToUpdate = values.saveType === SaveTypes.Update ? props.selectedSearchID : null; | ||
props.handleSave(name, isOrganization, idToUpdate); | ||
form.reset(); | ||
}, | ||
}); | ||
}; | ||
|
||
return ( | ||
<Tooltip label={tSearch('saveTooltip')}> | ||
<ActionIcon disabled={props.isPending} variant="outline" size={34} onClick={openModal}> | ||
<IconDeviceFloppy /> | ||
</ActionIcon> | ||
</Tooltip> | ||
); | ||
} |
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.
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.
when the type is Update, we may want to order the searches again, since this is the current behavior. For example if I rename aaa to zzz, I would expect the updated entry to be on the bottom (which it does if you refresh)
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.
Doesn't seem to behave that way (this is the fetched data withou updating).