Skip to content

Commit 8992b7c

Browse files
author
Laurie T. Malau
committed
Remove free text search on contextURL
1 parent a4dbc1a commit 8992b7c

File tree

9 files changed

+20
-58
lines changed

9 files changed

+20
-58
lines changed

components/dashboard/src/admin/ProjectsSearch.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function ProjectsSearch() {
9797
<path fillRule="evenodd" clipRule="evenodd" d="M6 2a4 4 0 100 8 4 4 0 000-8zM0 6a6 6 0 1110.89 3.477l4.817 4.816a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 010 6z" fill="#A8A29E" />
9898
</svg>
9999
</div>
100-
<input type="search" placeholder="Search Projects" onKeyDown={(k) => k.key === 'Enter' && search()} onChange={(v) => { setSearchTerm(v.target.value) }} />
100+
<input type="search" placeholder="Search Projects" onKeyDown={(k) => k.key === 'Enter' && search()} onChange={(v) => { setSearchTerm((v.target.value).trim()) }} />
101101
</div>
102102
<button disabled={searching} onClick={search}>Search</button>
103103
</div>

components/dashboard/src/admin/TeamsSearch.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export function TeamsSearch() {
8181
<path fillRule="evenodd" clipRule="evenodd" d="M6 2a4 4 0 100 8 4 4 0 000-8zM0 6a6 6 0 1110.89 3.477l4.817 4.816a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 010 6z" fill="#A8A29E" />
8282
</svg>
8383
</div>
84-
<input type="search" placeholder="Search Teams" onKeyDown={(k) => k.key === 'Enter' && search()} onChange={(v) => { setSearchTerm(v.target.value) }} />
84+
<input type="search" placeholder="Search Teams" onKeyDown={(k) => k.key === 'Enter' && search()} onChange={(v) => { setSearchTerm((v.target.value).trim()) }} />
8585
</div>
8686
<button disabled={searching} onClick={search}>Search</button>
8787
</div>

components/dashboard/src/admin/UserSearch.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export default function UserSearch() {
7272
<path fillRule="evenodd" clipRule="evenodd" d="M6 2a4 4 0 100 8 4 4 0 000-8zM0 6a6 6 0 1110.89 3.477l4.817 4.816a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 010 6z" fill="#A8A29E" />
7373
</svg>
7474
</div>
75-
<input type="search" placeholder="Search Users" onKeyDown={(ke) => ke.key === 'Enter' && search() } onChange={(v) => { setSearchTerm(v.target.value) }} />
75+
<input type="search" placeholder="Search Users" onKeyDown={(ke) => ke.key === 'Enter' && search() } onChange={(v) => { setSearchTerm((v.target.value).trim()) }} />
7676
</div>
7777
<button disabled={searching} onClick={search}>Search</button>
7878
</div>

components/dashboard/src/admin/WorkspacesSearch.tsx

+8-14
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,19 @@ export function WorkspaceSearch(props: Props) {
6868
const search = async () => {
6969
setSearching(true);
7070
try {
71-
let searchTerm: string | undefined = queryTerm;
72-
const query: AdminGetWorkspacesQuery = {
73-
ownerId: props?.user?.id,
74-
};
75-
if (matchesInstanceIdOrLegacyWorkspaceIdExactly(searchTerm)) {
76-
query.instanceIdOrWorkspaceId = searchTerm;
77-
} else if (matchesNewWorkspaceIdExactly(searchTerm)) {
78-
query.workspaceId = searchTerm;
79-
}
80-
if (query.workspaceId || query.instanceId || query.instanceIdOrWorkspaceId) {
81-
searchTerm = undefined;
71+
const query: AdminGetWorkspacesQuery = {};
72+
if (matchesInstanceIdOrLegacyWorkspaceIdExactly(queryTerm)) {
73+
query.instanceIdOrWorkspaceId = queryTerm;
74+
} else if (matchesNewWorkspaceIdExactly(queryTerm)) {
75+
query.workspaceId = queryTerm;
8276
}
8377

84-
// const searchTerm = searchTerm;
8578
const result = await getGitpodService().server.adminGetWorkspaces({
8679
limit: 100,
8780
orderBy: 'instanceCreationTime',
8881
offset: 0,
8982
orderDir: "desc",
9083
...query,
91-
searchTerm,
9284
});
9385
setSearchResult(result);
9486
} finally {
@@ -104,7 +96,9 @@ export function WorkspaceSearch(props: Props) {
10496
<path fillRule="evenodd" clipRule="evenodd" d="M6 2a4 4 0 100 8 4 4 0 000-8zM0 6a6 6 0 1110.89 3.477l4.817 4.816a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 010 6z" fill="#A8A29E" />
10597
</svg>
10698
</div>
107-
<input type="search" placeholder="Search Workspaces" onKeyDown={(ke) => ke.key === 'Enter' && search() } onChange={(v) => { setQueryTerm(v.target.value) }} />
99+
<input type="search" placeholder="Search Workspace IDs"
100+
onKeyDown={(ke) => ke.key === 'Enter' && search() }
101+
onChange={(v) => { setQueryTerm((v.target.value).trim()) }} />
108102
</div>
109103
<button disabled={searching} onClick={search}>Search</button>
110104
</div>

components/gitpod-db/src/typeorm/workspace-db-impl.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
754754
return await queryBuilder.getCount();
755755
}
756756

757-
public async findAllWorkspaceAndInstances(offset: number, limit: number, orderBy: keyof WorkspaceAndInstance, orderDir: "ASC" | "DESC", query?: AdminGetWorkspacesQuery, searchTerm?: string): Promise<{ total: number, rows: WorkspaceAndInstance[] }> {
757+
public async findAllWorkspaceAndInstances(offset: number, limit: number, orderBy: keyof WorkspaceAndInstance, orderDir: "ASC" | "DESC", query?: AdminGetWorkspacesQuery): Promise<{ total: number, rows: WorkspaceAndInstance[] }> {
758758
let whereConditions = [];
759759
let whereConditionParams: any = {};
760760
let instanceIdQuery: boolean = false;
@@ -765,28 +765,19 @@ export abstract class AbstractTypeORMWorkspaceDBImpl implements WorkspaceDB {
765765
whereConditions.push("(wsi.id = :instanceId OR ws.id = :workspaceId)");
766766
whereConditionParams.instanceId = query.instanceIdOrWorkspaceId;
767767
whereConditionParams.workspaceId = query.instanceIdOrWorkspaceId;
768+
} else if (query.workspaceId) {
769+
whereConditions.push("ws.id = :workspaceId");
770+
whereConditionParams.workspaceId = query.workspaceId;
768771
} else if (query.instanceId) {
769772
// in addition to adding "instanceId" to the "WHERE" clause like for the other workspace-guided queries,
770773
// we modify the JOIN condition below to a) select the correct instance and b) make the query faster
771774
instanceIdQuery = true;
772775

773776
whereConditions.push("wsi.id = :instanceId");
774777
whereConditionParams.instanceId = query.instanceId;
775-
} else if (query.workspaceId) {
776-
whereConditions.push("ws.id = :workspaceId");
777-
whereConditionParams.workspaceId = query.workspaceId;
778-
} else if (query.ownerId) {
779-
// If an owner id is provided only search for workspaces belonging to that user.
780-
whereConditions.push("ws.ownerId = :ownerId");
781-
whereConditionParams.ownerId = query.ownerId;
782778
}
783779
}
784780

785-
if (searchTerm) {
786-
// If a search term is provided perform a wildcard search in the context url or exact match on the workspace id (aka workspace name) or the instance id.
787-
whereConditions.push(`ws.contextURL LIKE '%${searchTerm}%'`);
788-
}
789-
790781
let orderField: string = orderBy;
791782
switch (orderField) {
792783
case "workspaceId": orderField = "ws.id"; break;

components/gitpod-db/src/workspace-db.spec.db.ts

+3-25
Original file line numberDiff line numberDiff line change
@@ -314,28 +314,6 @@ import { DBWorkspaceInstance } from './typeorm/entity/db-workspace-instance';
314314
expect(dbResult.total).to.eq(1);
315315
}
316316

317-
@test(timeout(10000))
318-
public async testFindAllWorkspaceAndInstances_contextUrl() {
319-
await Promise.all([
320-
this.db.store(this.ws),
321-
this.db.storeInstance(this.wsi1),
322-
this.db.storeInstance(this.wsi2),
323-
this.db.store(this.ws2),
324-
this.db.storeInstance(this.ws2i1),
325-
]);
326-
const dbResult = await this.db.findAllWorkspaceAndInstances(0, 10, "contextURL", "DESC", undefined, this.ws.contextURL);
327-
// It should only find one workspace instance
328-
expect(dbResult.total).to.eq(1);
329-
330-
const workspaceAndInstance = dbResult.rows[0]
331-
332-
// It should find the workspace that uses the queried context url
333-
expect(workspaceAndInstance.workspaceId).to.eq(this.ws.id)
334-
335-
// It should select the workspace instance that was most recently created
336-
expect(workspaceAndInstance.instanceId).to.eq(this.wsi2.id)
337-
}
338-
339317
@test(timeout(10000))
340318
public async testFindAllWorkspaceAndInstances_workspaceId() {
341319
await Promise.all([
@@ -344,7 +322,7 @@ import { DBWorkspaceInstance } from './typeorm/entity/db-workspace-instance';
344322
this.db.store(this.ws2),
345323
this.db.storeInstance(this.ws2i1),
346324
]);
347-
const dbResult = await this.db.findAllWorkspaceAndInstances(0, 10, "workspaceId", "DESC", { workspaceId: this.ws2.id }, undefined);
325+
const dbResult = await this.db.findAllWorkspaceAndInstances(0, 10, "workspaceId", "DESC", { workspaceId: this.ws2.id });
348326
// It should only find one workspace instance
349327
expect(dbResult.total).to.eq(1);
350328

@@ -361,7 +339,7 @@ import { DBWorkspaceInstance } from './typeorm/entity/db-workspace-instance';
361339
this.db.store(this.ws2),
362340
this.db.storeInstance(this.ws2i1),
363341
]);
364-
const dbResult = await this.db.findAllWorkspaceAndInstances(0, 10, "workspaceId", "DESC", { instanceIdOrWorkspaceId: this.ws2.id }, undefined);
342+
const dbResult = await this.db.findAllWorkspaceAndInstances(0, 10, "workspaceId", "DESC", { instanceIdOrWorkspaceId: this.ws2.id });
365343
// It should only find one workspace instance
366344
expect(dbResult.total).to.eq(1);
367345

@@ -379,7 +357,7 @@ import { DBWorkspaceInstance } from './typeorm/entity/db-workspace-instance';
379357
this.db.store(this.ws2),
380358
this.db.storeInstance(this.ws2i1),
381359
]);
382-
const dbResult = await this.db.findAllWorkspaceAndInstances(0, 10, "instanceId", "DESC", { instanceId: this.wsi1.id }, undefined);
360+
const dbResult = await this.db.findAllWorkspaceAndInstances(0, 10, "instanceId", "DESC", { instanceId: this.wsi1.id });
383361

384362
// It should only find one workspace instance
385363
expect(dbResult.total).to.eq(1);

components/gitpod-db/src/workspace-db.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export interface WorkspaceDB {
8181
findWorkspacesForContentDeletion(minSoftDeletedTimeInDays: number, limit: number): Promise<WorkspaceOwnerAndSoftDeleted[]>;
8282
findPrebuiltWorkspacesForGC(daysUnused: number, limit: number): Promise<WorkspaceAndOwner[]>;
8383
findAllWorkspaces(offset: number, limit: number, orderBy: keyof Workspace, orderDir: "ASC" | "DESC", ownerId?: string, searchTerm?: string, minCreationTime?: Date, maxCreationDateTime?: Date, type?: WorkspaceType): Promise<{ total: number, rows: Workspace[] }>;
84-
findAllWorkspaceAndInstances(offset: number, limit: number, orderBy: keyof WorkspaceAndInstance, orderDir: "ASC" | "DESC", query?: AdminGetWorkspacesQuery, searchTerm?: string): Promise<{ total: number, rows: WorkspaceAndInstance[] }>;
84+
findAllWorkspaceAndInstances(offset: number, limit: number, orderBy: keyof WorkspaceAndInstance, orderDir: "ASC" | "DESC", query?: AdminGetWorkspacesQuery): Promise<{ total: number, rows: WorkspaceAndInstance[] }>;
8585
findWorkspaceAndInstance(id: string): Promise<WorkspaceAndInstance | undefined>;
8686
findInstancesByPhaseAndRegion(phase: string, region: string): Promise<WorkspaceInstance[]>;
8787

components/gitpod-protocol/src/admin-protocol.ts

-1
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,4 @@ export type AdminGetWorkspacesQuery = {
116116
instanceIdOrWorkspaceId?: string;
117117
instanceId?: string;
118118
workspaceId?: string;
119-
ownerId?: string;
120119
};

components/server/ee/src/workspace/gitpod-server-impl.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ export class GitpodServerEEImpl extends GitpodServerImpl {
586586

587587
await this.guardAdminAccess("adminGetWorkspaces", { req }, Permission.ADMIN_WORKSPACES);
588588

589-
return await this.workspaceDb.trace(ctx).findAllWorkspaceAndInstances(req.offset, req.limit, req.orderBy, req.orderDir === "asc" ? "ASC" : "DESC", req, req.searchTerm);
589+
return await this.workspaceDb.trace(ctx).findAllWorkspaceAndInstances(req.offset, req.limit, req.orderBy, req.orderDir === "asc" ? "ASC" : "DESC", req);
590590
}
591591

592592
async adminGetWorkspace(ctx: TraceContext, workspaceId: string): Promise<WorkspaceAndInstance> {

0 commit comments

Comments
 (0)