-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ConfigurationServiceAPI (#19020)
* adding ConfigurationServiceAPI * binding config service api to server * use getConfiguration in dashboard * adding missing binding * use ApplicationError's * add protobuf classes to query client hydration * fixing pagination param & query * changing to import statements for consistency and clarity on what the imports are for * cleanup * dropping config settings for create for now * use protobuf field names in error messages * removing optional on fields * fixing converters to account for non-optional (undefined) fields * update test * adding more tests for findProjectsBySearchTerm * fixing test to use offset correctly * convert pagination args correctly
- Loading branch information
1 parent
bf06755
commit df7929c
Showing
21 changed files
with
2,679 additions
and
28 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
components/dashboard/src/data/configurations/configuration-queries.ts
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,67 @@ | ||
/** | ||
* Copyright (c) 2023 Gitpod GmbH. All rights reserved. | ||
* Licensed under the GNU Affero General Public License (AGPL). | ||
* See License.AGPL.txt in the project root for license information. | ||
*/ | ||
|
||
import { useQuery } from "@tanstack/react-query"; | ||
import { useCurrentOrg } from "../organizations/orgs-query"; | ||
import { configurationClient } from "../../service/public-api"; | ||
import { Configuration } from "@gitpod/public-api/lib/gitpod/v1/configuration_pb"; | ||
|
||
const BASE_KEY = "configurations"; | ||
|
||
type ListConfigurationsArgs = { | ||
searchTerm?: string; | ||
page: number; | ||
pageSize: number; | ||
}; | ||
|
||
export const useListConfigurations = ({ searchTerm = "", page, pageSize }: ListConfigurationsArgs) => { | ||
const { data: org } = useCurrentOrg(); | ||
|
||
return useQuery( | ||
getListConfigurationsQueryKey(org?.id || "", { searchTerm, page, pageSize }), | ||
async () => { | ||
if (!org) { | ||
throw new Error("No org currently selected"); | ||
} | ||
|
||
const { configurations, pagination } = await configurationClient.listConfigurations({ | ||
organizationId: org.id, | ||
searchTerm, | ||
pagination: { page, pageSize }, | ||
}); | ||
|
||
return { configurations, pagination }; | ||
}, | ||
{ | ||
enabled: !!org, | ||
}, | ||
); | ||
}; | ||
|
||
export const getListConfigurationsQueryKey = (orgId: string, args?: ListConfigurationsArgs) => { | ||
const key: any[] = [BASE_KEY, "list", { orgId }]; | ||
if (args) { | ||
key.push(args); | ||
} | ||
|
||
return key; | ||
}; | ||
|
||
export const useConfiguration = (configurationId: string) => { | ||
return useQuery<Configuration | undefined, Error>(getConfigurationQueryKey(configurationId), async () => { | ||
const { configuration } = await configurationClient.getConfiguration({ | ||
configurationId, | ||
}); | ||
|
||
return configuration; | ||
}); | ||
}; | ||
|
||
export const getConfigurationQueryKey = (configurationId: string) => { | ||
const key: any[] = [BASE_KEY, { configurationId }]; | ||
|
||
return key; | ||
}; |
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 |
---|---|---|
|
@@ -54,6 +54,95 @@ class ProjectDBSpec { | |
const foundProject = await this.projectDb.findProjectsBySearchTerm(0, 10, "creationTime", "DESC", searchTerm); | ||
|
||
expect(foundProject.rows[0].id).to.eq(storedProject.id); | ||
|
||
const foundProjectByName = await this.projectDb.findProjectsBySearchTerm( | ||
0, | ||
10, | ||
"creationTime", | ||
"DESC", | ||
"some-proj", | ||
); | ||
expect(foundProjectByName.rows[0].id).to.eq(storedProject.id); | ||
|
||
const foundProjectEmptySearch = await this.projectDb.findProjectsBySearchTerm( | ||
0, | ||
10, | ||
"creationTime", | ||
"DESC", | ||
" ", | ||
); | ||
expect(foundProjectEmptySearch.rows[0].id).to.eq(storedProject.id); | ||
} | ||
|
||
@test() | ||
public async findProjectBySearchTermPagniation() { | ||
const user = await this.userDb.newUser(); | ||
user.identities.push({ | ||
authProviderId: "GitHub", | ||
authId: "1234", | ||
authName: "newUser", | ||
primaryEmail: "[email protected]", | ||
}); | ||
await this.userDb.storeUser(user); | ||
|
||
const project1 = Project.create({ | ||
name: "some-project", | ||
cloneUrl: "some-random-clone-url", | ||
teamId: "team-1", | ||
appInstallationId: "", | ||
}); | ||
const project2 = Project.create({ | ||
name: "some-project-2", | ||
cloneUrl: "some-random-clone-url-2", | ||
teamId: "team-1", | ||
appInstallationId: "", | ||
}); | ||
const project3 = Project.create({ | ||
name: "some-project-3", | ||
cloneUrl: "some-random-clone-url-1", | ||
teamId: "team-1", | ||
appInstallationId: "", | ||
}); | ||
const project4 = Project.create({ | ||
name: "some-project-4", | ||
cloneUrl: "some-random-clone-url-1", | ||
teamId: "team-1", | ||
appInstallationId: "", | ||
}); | ||
const project5 = Project.create({ | ||
name: "some-project-5", | ||
cloneUrl: "some-random-clone-url-1", | ||
teamId: "team-1", | ||
appInstallationId: "", | ||
}); | ||
const storedProject1 = await this.projectDb.storeProject(project1); | ||
const storedProject2 = await this.projectDb.storeProject(project2); | ||
const storedProject3 = await this.projectDb.storeProject(project3); | ||
const storedProject4 = await this.projectDb.storeProject(project4); | ||
const storedProject5 = await this.projectDb.storeProject(project5); | ||
|
||
const allResults = await this.projectDb.findProjectsBySearchTerm(0, 10, "name", "ASC", ""); | ||
expect(allResults.total).equals(5); | ||
expect(allResults.rows.length).equal(5); | ||
expect(allResults.rows[0].id).to.eq(storedProject1.id); | ||
expect(allResults.rows[1].id).to.eq(storedProject2.id); | ||
expect(allResults.rows[2].id).to.eq(storedProject3.id); | ||
expect(allResults.rows[3].id).to.eq(storedProject4.id); | ||
expect(allResults.rows[4].id).to.eq(storedProject5.id); | ||
|
||
const pageSize = 3; | ||
const page1 = await this.projectDb.findProjectsBySearchTerm(0, pageSize, "name", "ASC", ""); | ||
expect(page1.total).equals(5); | ||
expect(page1.rows.length).equal(3); | ||
expect(page1.rows[0].id).to.eq(storedProject1.id); | ||
expect(page1.rows[1].id).to.eq(storedProject2.id); | ||
expect(page1.rows[2].id).to.eq(storedProject3.id); | ||
|
||
const page2 = await this.projectDb.findProjectsBySearchTerm(pageSize * 1, pageSize, "name", "ASC", ""); | ||
expect(page2.total).equals(5); | ||
expect(page2.rows.length).equal(2); | ||
expect(page2.rows[0].id).to.eq(storedProject4.id); | ||
expect(page2.rows[1].id).to.eq(storedProject5.id); | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.