Skip to content

Commit

Permalink
chore: workspace entity search endpoint (#6272)
Browse files Browse the repository at this point in the history
* chore: workspace entity search endpoint

* fix: editor entity search endpoint

* chore: restrict guest users

---------

Co-authored-by: Aaryan Khandelwal <[email protected]>
  • Loading branch information
NarayanBavisetti and aaryan610 authored Dec 26, 2024
1 parent 2d9464e commit f54f3a6
Show file tree
Hide file tree
Showing 10 changed files with 475 additions and 227 deletions.
2 changes: 1 addition & 1 deletion apiserver/plane/app/urls/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
name="project-issue-search",
),
path(
"workspaces/<str:slug>/projects/<uuid:project_id>/entity-search/",
"workspaces/<str:slug>/entity-search/",
SearchEndpoint.as_view(),
name="entity-search",
),
Expand Down
599 changes: 421 additions & 178 deletions apiserver/plane/app/views/search/base.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/types/src/search.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export type TSearchResponse = {

export type TSearchEntityRequestPayload = {
count: number;
project_id?: string;
query_type: TSearchEntities[];
query: string;
team_id?: string;
};
11 changes: 7 additions & 4 deletions web/core/components/editor/lite-text-editor/lite-text-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { useEditorMention } from "@/hooks/use-editor-mention";
// plane web hooks
import { useEditorFlagging } from "@/plane-web/hooks/use-editor-flagging";
import { useFileSize } from "@/plane-web/hooks/use-file-size";
// services
import { ProjectService } from "@/services/project";
const projectService = new ProjectService();
// plane web services
import { WorkspaceService } from "@/plane-web/services";
const workspaceService = new WorkspaceService();

interface LiteTextEditorWrapperProps
extends Omit<ILiteTextEditor, "disabledExtensions" | "fileHandler" | "mentionHandler"> {
Expand Down Expand Up @@ -55,7 +55,10 @@ export const LiteTextEditor = React.forwardRef<EditorRefApi, LiteTextEditorWrapp
// use editor mention
const { fetchMentions } = useEditorMention({
searchEntity: async (payload) =>
await projectService.searchEntity(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload),
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
...payload,
project_id: projectId?.toString() ?? "",
}),
});
// file size
const { maxFileSize } = useFileSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import { getTabIndex } from "@/helpers/tab-indices.helper";
// hooks
import { useProjectInbox } from "@/hooks/store";
import { usePlatformOS } from "@/hooks/use-platform-os";
// plane web services
import { WorkspaceService } from "@/plane-web/services";
// services
import { FileService } from "@/services/file.service";
import { ProjectService } from "@/services/project";
const fileService = new FileService();
const projectService = new ProjectService();
const workspaceService = new WorkspaceService();

type TInboxIssueDescription = {
containerClassName?: string;
Expand Down Expand Up @@ -75,7 +76,10 @@ export const InboxIssueDescription: FC<TInboxIssueDescription> = observer((props
onChange={(_description: object, description_html: string) => handleData("description_html", description_html)}
placeholder={getDescriptionPlaceholder}
searchMentionCallback={async (payload) =>
await projectService.searchEntity(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload)
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
...payload,
project_id: projectId?.toString() ?? "",
})
}
containerClassName={containerClassName}
onEnterKeyPress={onEnterKeyPress}
Expand Down
14 changes: 7 additions & 7 deletions web/core/components/issues/description-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import { TIssueOperations } from "@/components/issues/issue-detail";
import { getDescriptionPlaceholder } from "@/helpers/issue.helper";
// hooks
import { useWorkspace } from "@/hooks/store";
// plane web services
import { WorkspaceService } from "@/plane-web/services";
// services
import { FileService } from "@/services/file.service";
import { ProjectService } from "@/services/project";
const workspaceService = new WorkspaceService();
const fileService = new FileService();
const projectService = new ProjectService();

export type IssueDescriptionInputProps = {
containerClassName?: string;
Expand Down Expand Up @@ -121,11 +122,10 @@ export const IssueDescriptionInput: FC<IssueDescriptionInputProps> = observer((p
placeholder ? placeholder : (isFocused, value) => getDescriptionPlaceholder(isFocused, value)
}
searchMentionCallback={async (payload) =>
await projectService.searchEntity(
workspaceSlug?.toString() ?? "",
projectId?.toString() ?? "",
payload
)
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
...payload,
project_id: projectId?.toString() ?? "",
})
}
containerClassName={containerClassName}
uploadFile={async (file) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import { getTabIndex } from "@/helpers/tab-indices.helper";
import { useInstance, useWorkspace } from "@/hooks/store";
import useKeypress from "@/hooks/use-keypress";
import { usePlatformOS } from "@/hooks/use-platform-os";
// plane web services
import { WorkspaceService } from "@/plane-web/services";
// services
import { AIService } from "@/services/ai.service";
import { FileService } from "@/services/file.service";
import { ProjectService } from "@/services/project";

type TIssueDescriptionEditorProps = {
control: Control<TIssue>;
Expand All @@ -48,9 +49,9 @@ type TIssueDescriptionEditorProps = {
};

// services
const workspaceService = new WorkspaceService();
const aiService = new AIService();
const fileService = new FileService();
const projectService = new ProjectService();

export const IssueDescriptionEditor: React.FC<TIssueDescriptionEditorProps> = observer((props) => {
const {
Expand Down Expand Up @@ -191,11 +192,10 @@ export const IssueDescriptionEditor: React.FC<TIssueDescriptionEditorProps> = ob
tabIndex={getIndex("description_html")}
placeholder={getDescriptionPlaceholder}
searchMentionCallback={async (payload) =>
await projectService.searchEntity(
workspaceSlug?.toString() ?? "",
projectId?.toString() ?? "",
payload
)
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
...payload,
project_id: projectId?.toString() ?? "",
})
}
containerClassName="pt-3 min-h-[120px]"
uploadFile={async (file) => {
Expand Down
10 changes: 7 additions & 3 deletions web/core/components/pages/editor/editor-body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ import { EditorAIMenu } from "@/plane-web/components/pages";
import { useEditorFlagging } from "@/plane-web/hooks/use-editor-flagging";
import { useFileSize } from "@/plane-web/hooks/use-file-size";
import { useIssueEmbed } from "@/plane-web/hooks/use-issue-embed";
// plane web services
import { WorkspaceService } from "@/plane-web/services";
// services
import { FileService } from "@/services/file.service";
import { ProjectService } from "@/services/project";
// store
import { IPage } from "@/store/pages/page";
// services init
const workspaceService = new WorkspaceService();
const fileService = new FileService();
const projectService = new ProjectService();

type Props = {
editorRef: React.RefObject<EditorRefApi>;
Expand All @@ -63,7 +64,10 @@ export const PageEditorBody: React.FC<Props> = observer((props) => {
// use editor mention
const { fetchMentions } = useEditorMention({
searchEntity: async (payload) =>
await projectService.searchEntity(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload),
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
...payload,
project_id: projectId?.toString() ?? "",
}),
});
// editor flaggings
const { documentEditor: disabledExtensions } = useEditorFlagging(workspaceSlug?.toString());
Expand Down
25 changes: 1 addition & 24 deletions web/core/services/project/project.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import type {
GithubRepositoriesResponse,
ISearchIssueResponse,
TProjectIssuesSearchParams,
TSearchEntityRequestPayload,
TSearchResponse,
} from "@plane/types";
import type { GithubRepositoriesResponse, ISearchIssueResponse, TProjectIssuesSearchParams } from "@plane/types";
// helpers
import { API_BASE_URL } from "@/helpers/common.helper";
// plane web types
Expand Down Expand Up @@ -170,21 +164,4 @@ export class ProjectService extends APIService {
throw error?.response?.data;
});
}

async searchEntity(
workspaceSlug: string,
projectId: string,
params: TSearchEntityRequestPayload
): Promise<TSearchResponse> {
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/entity-search/`, {
params: {
...params,
query_type: params.query_type.join(","),
},
})
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}
15 changes: 15 additions & 0 deletions web/core/services/workspace.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
IUserProjectsRole,
IWorkspaceView,
TIssuesResponse,
TSearchResponse,
TSearchEntityRequestPayload,
} from "@plane/types";
import { APIService } from "@/services/api.service";
// helpers
Expand Down Expand Up @@ -277,4 +279,17 @@ export class WorkspaceService extends APIService {
throw error?.response?.data;
});
}

async searchEntity(workspaceSlug: string, params: TSearchEntityRequestPayload): Promise<TSearchResponse> {
return this.get(`/api/workspaces/${workspaceSlug}/entity-search/`, {
params: {
...params,
query_type: params.query_type.join(","),
},
})
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
});
}
}

0 comments on commit f54f3a6

Please sign in to comment.