mirror of https://github.com/buster-so/buster.git
remove shortcuts now works
This commit is contained in:
parent
5ada81129b
commit
c7ae1e2da6
|
@ -1,5 +1,6 @@
|
||||||
import type { ListShortcutsResponse, Shortcut } from '@buster/server-shared/shortcuts';
|
import type { ListShortcutsResponse, Shortcut } from '@buster/server-shared/shortcuts';
|
||||||
import { useNavigate } from '@tanstack/react-router';
|
import { useNavigate } from '@tanstack/react-router';
|
||||||
|
import type { Editor } from '@tiptap/react';
|
||||||
import { useMemo, useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import { useDeleteShortcut, useGetShortcut } from '@/api/buster_rest/shortcuts/queryRequests';
|
import { useDeleteShortcut, useGetShortcut } from '@/api/buster_rest/shortcuts/queryRequests';
|
||||||
import { ErrorCard } from '@/components/ui/error/ErrorCard';
|
import { ErrorCard } from '@/components/ui/error/ErrorCard';
|
||||||
|
@ -35,10 +36,10 @@ export const useCreateShortcutsMentionsSuggestions = (
|
||||||
() =>
|
() =>
|
||||||
createMentionSuggestionExtension({
|
createMentionSuggestionExtension({
|
||||||
trigger: SHORTCUT_MENTION_TRIGGER,
|
trigger: SHORTCUT_MENTION_TRIGGER,
|
||||||
items: ({ defaultQueryMentionsFilter, query }) => {
|
items: ({ defaultQueryMentionsFilter, editor, query }) => {
|
||||||
const shortcuts = currentItemsRef.current;
|
const shortcuts = currentItemsRef.current;
|
||||||
const allItems = [
|
const allItems = [
|
||||||
...shortcuts.map(createShortcutForMention),
|
...shortcuts.map((s) => createShortcutForMention(s, editor)),
|
||||||
{ type: 'separator' as const },
|
{ type: 'separator' as const },
|
||||||
{
|
{
|
||||||
value: 'manageShortcuts',
|
value: 'manageShortcuts',
|
||||||
|
@ -79,7 +80,10 @@ export const useCreateShortcutsMentionsSuggestions = (
|
||||||
export const useCreateShortcutForMention = () => {
|
export const useCreateShortcutForMention = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { mutateAsync: deleteShortcut } = useDeleteShortcut();
|
const { mutateAsync: deleteShortcut } = useDeleteShortcut();
|
||||||
const createShortcutForMention = (shortcut: Shortcut): MentionTriggerItem<string> => {
|
const createShortcutForMention = (
|
||||||
|
shortcut: Shortcut,
|
||||||
|
editor?: Editor
|
||||||
|
): MentionTriggerItem<string> => {
|
||||||
return {
|
return {
|
||||||
value: shortcut.id,
|
value: shortcut.id,
|
||||||
label: shortcut.name,
|
label: shortcut.name,
|
||||||
|
@ -106,6 +110,11 @@ export const useCreateShortcutForMention = () => {
|
||||||
value: 'delete',
|
value: 'delete',
|
||||||
onClick: async () => {
|
onClick: async () => {
|
||||||
await deleteShortcut({ id: shortcut.id });
|
await deleteShortcut({ id: shortcut.id });
|
||||||
|
//remove the trigger character from the editor
|
||||||
|
editor?.commands.deleteRange({
|
||||||
|
from: editor.state.selection.from - 1,
|
||||||
|
to: editor.state.selection.from,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { posToDOMRect, ReactRenderer } from '@tiptap/react';
|
import { type Editor, posToDOMRect, ReactRenderer } from '@tiptap/react';
|
||||||
import { defaultQueryMentionsFilter } from './defaultQueryMentionsFilter';
|
import { defaultQueryMentionsFilter } from './defaultQueryMentionsFilter';
|
||||||
import type {
|
import type {
|
||||||
MentionInputTriggerItem,
|
MentionInputTriggerItem,
|
||||||
|
@ -25,6 +25,7 @@ export const createMentionSuggestionExtension = ({
|
||||||
| ((props: {
|
| ((props: {
|
||||||
query: string;
|
query: string;
|
||||||
defaultQueryMentionsFilter: typeof defaultQueryMentionsFilter;
|
defaultQueryMentionsFilter: typeof defaultQueryMentionsFilter;
|
||||||
|
editor: Editor;
|
||||||
}) => MentionInputTriggerItem[]); //if no function is provided we will use a literal string match
|
}) => MentionInputTriggerItem[]); //if no function is provided we will use a literal string match
|
||||||
popoverContent?: MentionPopoverContentCallback;
|
popoverContent?: MentionPopoverContentCallback;
|
||||||
pillStyling?: MentionStylePillProps;
|
pillStyling?: MentionStylePillProps;
|
||||||
|
|
Loading…
Reference in New Issue