Skip to content

Commit f54f3a6

Browse files
chore: workspace entity search endpoint (#6272)
* chore: workspace entity search endpoint * fix: editor entity search endpoint * chore: restrict guest users --------- Co-authored-by: Aaryan Khandelwal <aaryankhandu123@gmail.com>
1 parent 2d9464e commit f54f3a6

File tree

10 files changed

+475
-227
lines changed

10 files changed

+475
-227
lines changed

apiserver/plane/app/urls/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
name="project-issue-search",
1717
),
1818
path(
19-
"workspaces/<str:slug>/projects/<uuid:project_id>/entity-search/",
19+
"workspaces/<str:slug>/entity-search/",
2020
SearchEndpoint.as_view(),
2121
name="entity-search",
2222
),

apiserver/plane/app/views/search/base.py

Lines changed: 421 additions & 178 deletions
Large diffs are not rendered by default.

packages/types/src/search.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ export type TSearchResponse = {
7676

7777
export type TSearchEntityRequestPayload = {
7878
count: number;
79+
project_id?: string;
7980
query_type: TSearchEntities[];
8081
query: string;
82+
team_id?: string;
8183
};

web/core/components/editor/lite-text-editor/lite-text-editor.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { useEditorMention } from "@/hooks/use-editor-mention";
1414
// plane web hooks
1515
import { useEditorFlagging } from "@/plane-web/hooks/use-editor-flagging";
1616
import { useFileSize } from "@/plane-web/hooks/use-file-size";
17-
// services
18-
import { ProjectService } from "@/services/project";
19-
const projectService = new ProjectService();
17+
// plane web services
18+
import { WorkspaceService } from "@/plane-web/services";
19+
const workspaceService = new WorkspaceService();
2020

2121
interface LiteTextEditorWrapperProps
2222
extends Omit<ILiteTextEditor, "disabledExtensions" | "fileHandler" | "mentionHandler"> {
@@ -55,7 +55,10 @@ export const LiteTextEditor = React.forwardRef<EditorRefApi, LiteTextEditorWrapp
5555
// use editor mention
5656
const { fetchMentions } = useEditorMention({
5757
searchEntity: async (payload) =>
58-
await projectService.searchEntity(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload),
58+
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
59+
...payload,
60+
project_id: projectId?.toString() ?? "",
61+
}),
5962
});
6063
// file size
6164
const { maxFileSize } = useFileSize();

web/core/components/inbox/modals/create-modal/issue-description.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import { getTabIndex } from "@/helpers/tab-indices.helper";
1919
// hooks
2020
import { useProjectInbox } from "@/hooks/store";
2121
import { usePlatformOS } from "@/hooks/use-platform-os";
22+
// plane web services
23+
import { WorkspaceService } from "@/plane-web/services";
2224
// services
2325
import { FileService } from "@/services/file.service";
24-
import { ProjectService } from "@/services/project";
2526
const fileService = new FileService();
26-
const projectService = new ProjectService();
27+
const workspaceService = new WorkspaceService();
2728

2829
type TInboxIssueDescription = {
2930
containerClassName?: string;
@@ -75,7 +76,10 @@ export const InboxIssueDescription: FC<TInboxIssueDescription> = observer((props
7576
onChange={(_description: object, description_html: string) => handleData("description_html", description_html)}
7677
placeholder={getDescriptionPlaceholder}
7778
searchMentionCallback={async (payload) =>
78-
await projectService.searchEntity(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload)
79+
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
80+
...payload,
81+
project_id: projectId?.toString() ?? "",
82+
})
7983
}
8084
containerClassName={containerClassName}
8185
onEnterKeyPress={onEnterKeyPress}

web/core/components/issues/description-input.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ import { TIssueOperations } from "@/components/issues/issue-detail";
1616
import { getDescriptionPlaceholder } from "@/helpers/issue.helper";
1717
// hooks
1818
import { useWorkspace } from "@/hooks/store";
19+
// plane web services
20+
import { WorkspaceService } from "@/plane-web/services";
1921
// services
2022
import { FileService } from "@/services/file.service";
21-
import { ProjectService } from "@/services/project";
23+
const workspaceService = new WorkspaceService();
2224
const fileService = new FileService();
23-
const projectService = new ProjectService();
2425

2526
export type IssueDescriptionInputProps = {
2627
containerClassName?: string;
@@ -121,11 +122,10 @@ export const IssueDescriptionInput: FC<IssueDescriptionInputProps> = observer((p
121122
placeholder ? placeholder : (isFocused, value) => getDescriptionPlaceholder(isFocused, value)
122123
}
123124
searchMentionCallback={async (payload) =>
124-
await projectService.searchEntity(
125-
workspaceSlug?.toString() ?? "",
126-
projectId?.toString() ?? "",
127-
payload
128-
)
125+
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
126+
...payload,
127+
project_id: projectId?.toString() ?? "",
128+
})
129129
}
130130
containerClassName={containerClassName}
131131
uploadFile={async (file) => {

web/core/components/issues/issue-modal/components/description-editor.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@ import { getTabIndex } from "@/helpers/tab-indices.helper";
2323
import { useInstance, useWorkspace } from "@/hooks/store";
2424
import useKeypress from "@/hooks/use-keypress";
2525
import { usePlatformOS } from "@/hooks/use-platform-os";
26+
// plane web services
27+
import { WorkspaceService } from "@/plane-web/services";
2628
// services
2729
import { AIService } from "@/services/ai.service";
2830
import { FileService } from "@/services/file.service";
29-
import { ProjectService } from "@/services/project";
3031

3132
type TIssueDescriptionEditorProps = {
3233
control: Control<TIssue>;
@@ -48,9 +49,9 @@ type TIssueDescriptionEditorProps = {
4849
};
4950

5051
// services
52+
const workspaceService = new WorkspaceService();
5153
const aiService = new AIService();
5254
const fileService = new FileService();
53-
const projectService = new ProjectService();
5455

5556
export const IssueDescriptionEditor: React.FC<TIssueDescriptionEditorProps> = observer((props) => {
5657
const {
@@ -191,11 +192,10 @@ export const IssueDescriptionEditor: React.FC<TIssueDescriptionEditorProps> = ob
191192
tabIndex={getIndex("description_html")}
192193
placeholder={getDescriptionPlaceholder}
193194
searchMentionCallback={async (payload) =>
194-
await projectService.searchEntity(
195-
workspaceSlug?.toString() ?? "",
196-
projectId?.toString() ?? "",
197-
payload
198-
)
195+
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
196+
...payload,
197+
project_id: projectId?.toString() ?? "",
198+
})
199199
}
200200
containerClassName="pt-3 min-h-[120px]"
201201
uploadFile={async (file) => {

web/core/components/pages/editor/editor-body.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ import { EditorAIMenu } from "@/plane-web/components/pages";
3030
import { useEditorFlagging } from "@/plane-web/hooks/use-editor-flagging";
3131
import { useFileSize } from "@/plane-web/hooks/use-file-size";
3232
import { useIssueEmbed } from "@/plane-web/hooks/use-issue-embed";
33+
// plane web services
34+
import { WorkspaceService } from "@/plane-web/services";
3335
// services
3436
import { FileService } from "@/services/file.service";
35-
import { ProjectService } from "@/services/project";
3637
// store
3738
import { IPage } from "@/store/pages/page";
3839
// services init
40+
const workspaceService = new WorkspaceService();
3941
const fileService = new FileService();
40-
const projectService = new ProjectService();
4142

4243
type Props = {
4344
editorRef: React.RefObject<EditorRefApi>;
@@ -63,7 +64,10 @@ export const PageEditorBody: React.FC<Props> = observer((props) => {
6364
// use editor mention
6465
const { fetchMentions } = useEditorMention({
6566
searchEntity: async (payload) =>
66-
await projectService.searchEntity(workspaceSlug?.toString() ?? "", projectId?.toString() ?? "", payload),
67+
await workspaceService.searchEntity(workspaceSlug?.toString() ?? "", {
68+
...payload,
69+
project_id: projectId?.toString() ?? "",
70+
}),
6771
});
6872
// editor flaggings
6973
const { documentEditor: disabledExtensions } = useEditorFlagging(workspaceSlug?.toString());

web/core/services/project/project.service.ts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import type {
2-
GithubRepositoriesResponse,
3-
ISearchIssueResponse,
4-
TProjectIssuesSearchParams,
5-
TSearchEntityRequestPayload,
6-
TSearchResponse,
7-
} from "@plane/types";
1+
import type { GithubRepositoriesResponse, ISearchIssueResponse, TProjectIssuesSearchParams } from "@plane/types";
82
// helpers
93
import { API_BASE_URL } from "@/helpers/common.helper";
104
// plane web types
@@ -170,21 +164,4 @@ export class ProjectService extends APIService {
170164
throw error?.response?.data;
171165
});
172166
}
173-
174-
async searchEntity(
175-
workspaceSlug: string,
176-
projectId: string,
177-
params: TSearchEntityRequestPayload
178-
): Promise<TSearchResponse> {
179-
return this.get(`/api/workspaces/${workspaceSlug}/projects/${projectId}/entity-search/`, {
180-
params: {
181-
...params,
182-
query_type: params.query_type.join(","),
183-
},
184-
})
185-
.then((response) => response?.data)
186-
.catch((error) => {
187-
throw error?.response?.data;
188-
});
189-
}
190167
}

web/core/services/workspace.service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
IUserProjectsRole,
1313
IWorkspaceView,
1414
TIssuesResponse,
15+
TSearchResponse,
16+
TSearchEntityRequestPayload,
1517
} from "@plane/types";
1618
import { APIService } from "@/services/api.service";
1719
// helpers
@@ -277,4 +279,17 @@ export class WorkspaceService extends APIService {
277279
throw error?.response?.data;
278280
});
279281
}
282+
283+
async searchEntity(workspaceSlug: string, params: TSearchEntityRequestPayload): Promise<TSearchResponse> {
284+
return this.get(`/api/workspaces/${workspaceSlug}/entity-search/`, {
285+
params: {
286+
...params,
287+
query_type: params.query_type.join(","),
288+
},
289+
})
290+
.then((response) => response?.data)
291+
.catch((error) => {
292+
throw error?.response?.data;
293+
});
294+
}
280295
}

0 commit comments

Comments
 (0)