Skip to content

Commit

Permalink
refactor: rename functions to match finalized terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
dbouwman committed Sep 15, 2023
1 parent 8a26008 commit 3fcb47f
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 191 deletions.
46 changes: 17 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 6 additions & 23 deletions packages/common/e2e/associations.e2e.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {
IHubInitiative,
fetchConnectedProjects,
fetchAssociatedProjects,
fetchAcceptedProjects,
fetchHubEntity,
fetchUnConnectedProjects,
fetchPendingProjects,
} from "../src";
import Artifactory from "./helpers/Artifactory";
import config from "./helpers/config";
Expand Down Expand Up @@ -98,7 +97,7 @@ fdescribe("associations development harness:", () => {
});
});
describe("flex the functions:", () => {
it("search for associated projects", async () => {
it("search for accepted projects", async () => {
const ctxMgr = await factory.getContextManager(orgName, "admin");
const context = ctxMgr.context;
const entity = (await fetchHubEntity(
Expand All @@ -107,38 +106,22 @@ fdescribe("associations development harness:", () => {
context
)) as IHubInitiative;
// debugger;
const projects = await fetchAssociatedProjects(
const projects = await fetchAcceptedProjects(
entity,
context.hubRequestOptions
);
expect(projects.length).toBe(6);
});
it("search for un-related projects", async () => {
const ctxMgr = await factory.getContextManager(orgName, "admin");
const context = ctxMgr.context;
const entity = (await fetchHubEntity(
"initiative",
TEST_ITEMS.initiative,
context
)) as IHubInitiative;
// debugger;
const projects = await fetchUnConnectedProjects(
entity,
context.hubRequestOptions
);
// need to update this so we fetch all pages
expect(projects.length).toBe(10);
});

it("search for related projects", async () => {
it("search for pending projects", async () => {
const ctxMgr = await factory.getContextManager(orgName, "admin");
const context = ctxMgr.context;
const entity = (await fetchHubEntity(
"initiative",
TEST_ITEMS.initiative,
context
)) as IHubInitiative;
const projects = await fetchConnectedProjects(
const projects = await fetchPendingProjects(
entity,
context.hubRequestOptions
);
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/groups/HubGroups.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IGroup } from "@esri/arcgis-rest-types";
import { fetchGroupEnrichments } from "./_internal/enrichments";
import { getProp, setProp } from "../objects";
import { getGroupThumbnailUrl, IHubSearchResult } from "../search";
import { getGroupThumbnailUrl } from "../search/utils";
import { parseInclude } from "../search/_internal/parseInclude";
import { IHubRequestOptions } from "../types";
import { getGroupHomeUrl } from "../urls";
Expand All @@ -20,6 +20,7 @@ import { DEFAULT_GROUP } from "./defaults";
import { convertHubGroupToGroup } from "./_internal/convertHubGroupToGroup";
import { convertGroupToHubGroup } from "./_internal/convertGroupToHubGroup";
import { getRelativeWorkspaceUrl } from "../core/getRelativeWorkspaceUrl";
import { IHubSearchResult } from "../search/types/IHubSearchResult";

/**
* Enrich a generic search result
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/groups/_internal/computeProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { UserSession } from "@esri/arcgis-rest-auth";
import { IHubGroup } from "../../core/types/IHubGroup";
import { IGroup } from "@esri/arcgis-rest-types";
import { isDiscussable } from "../../discussions";
import { getGroupThumbnailUrl } from "../../search";
import { getGroupThumbnailUrl } from "../../search/utils";

/**
* Given a model and a group, set various computed properties that can't be directly mapped
Expand Down
109 changes: 55 additions & 54 deletions packages/common/src/initiatives/HubInitiatives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,62 +282,41 @@ export async function enrichInitiativeSearchResult(
}

/**
* Fetch the Projects that are "Associated" with an Initiative.
* This is a subset of the "Connected" projects, limited
* are included in the Initiative's Catalog.
* This is how we can get the "Approved" Projects
* Fetch the Projects that are "Accepted" with an Initiative.
* This is a subset of the "Associated" projects, limited
* to those included in the Initiative's Catalog.
* @param initiative
* @param requestOptions
* @param query: Optional `IQuery` to further filter the results
* @returns
*/
export async function fetchAssociatedProjects(
export async function fetchAcceptedProjects(
initiative: IHubInitiative,
requestOptions: IHubRequestOptions,
query?: IQuery
): Promise<IEntityInfo[]> {
let projectQuery = getAssociatedProjectsQuery(initiative);
let projectQuery = getAcceptedProjectsQuery(initiative);
// combineQueries will purge undefined/null entries
projectQuery = combineQueries([projectQuery, query]);

return queryAsEntityInfo(projectQuery, requestOptions);
}

/**
* Fetch the Projects that are "Connected" to the Initiative but are not
* "Associated", meaning they are not in the Initiative's Catalog.
* This is how we can get the list of Projects awaiting Approval
* Fetch the Projects that are "Associated" to the Initiative but are not
* "Accepted", meaning they have the keyword but are not included in the Initiative's Catalog.
* This is how we can get the list of Projects awaiting Acceptance
* @param initiative
* @param requestOptions
* @param query
* @returns
*/
export async function fetchConnectedProjects(
export async function fetchPendingProjects(
initiative: IHubInitiative,
requestOptions: IHubRequestOptions,
query?: IQuery
): Promise<IEntityInfo[]> {
let projectQuery = getConnectedProjectsQuery(initiative);
// combineQueries will purge undefined/null entries
projectQuery = combineQueries([projectQuery, query]);

return queryAsEntityInfo(projectQuery, requestOptions);
}

/**
* Fetch Projects which are not "Connected" and are not in the
* Initiative's Catalog.
* @param initiative
* @param requestOptions
* @param query
* @returns
*/
export async function fetchUnConnectedProjects(
initiative: IHubInitiative,
requestOptions: IHubRequestOptions,
query?: IQuery
): Promise<IEntityInfo[]> {
let projectQuery = getUnConnectedProjectsQuery(initiative);
let projectQuery = getPendingProjectsQuery(initiative);
// combineQueries will purge undefined/null entries
projectQuery = combineQueries([projectQuery, query]);

Expand Down Expand Up @@ -374,7 +353,7 @@ async function queryAsEntityInfo(
* @param initiative
* @returns
*/
export function getAssociatedProjectsQuery(initiative: IHubInitiative): IQuery {
export function getAcceptedProjectsQuery(initiative: IHubInitiative): IQuery {
// get query that returns Hub Projects with the initiative keyword
let query = getTypeWithKeywordQuery(
"Hub Project",
Expand All @@ -397,7 +376,7 @@ export function getAssociatedProjectsQuery(initiative: IHubInitiative): IQuery {
* @param initiative
* @returns
*/
export function getConnectedProjectsQuery(initiative: IHubInitiative): IQuery {
export function getPendingProjectsQuery(initiative: IHubInitiative): IQuery {
// get query that returns Hub Projects with the initiative keyword
let query = getTypeWithKeywordQuery(
"Hub Project",
Expand All @@ -412,25 +391,47 @@ export function getConnectedProjectsQuery(initiative: IHubInitiative): IQuery {
return query;
}

/**
* Un-connected projects are those without Initiative id in the typekeywords
* and is NOT included in the Initiative's catalog.
* This can be used to locate "Other" Projects
* @param initiative
* @returns
*/
export function getUnConnectedProjectsQuery(
initiative: IHubInitiative
): IQuery {
// get query that returns Hub Projects with the initiative keyword
let query = getTypeWithoutKeywordQuery(
"Hub Project",
`initiative|${initiative.id}`
);
// The the item scope from the catalog...
const qry = getProp(initiative, "catalog.scopes.item");
// ALTHOUGH WE DON"T CURRENTLY HAVE A UX THAT NEEDS THIS
// THERE IS SOME DISCUSSION ABOUT IT BEING USEFUL SO I'M LEAVING
// THE CODE HERE, COMMENTED. SAME FOR TESTS
// /**
// * Fetch Projects which are not "Connected" and are not in the
// * Initiative's Catalog.
// * @param initiative
// * @param requestOptions
// * @param query
// * @returns
// */
// export async function fetchUnConnectedProjects(
// initiative: IHubInitiative,
// requestOptions: IHubRequestOptions,
// query?: IQuery
// ): Promise<IEntityInfo[]> {
// let projectQuery = getUnConnectedProjectsQuery(initiative);
// // combineQueries will purge undefined/null entries
// projectQuery = combineQueries([projectQuery, query]);

// negate the scope, combine that with the base query
query = combineQueries([query, negateGroupPredicates(qry)]);
return query;
}
// return queryAsEntityInfo(projectQuery, requestOptions);
// }
// /**
// * Un-connected projects are those without Initiative id in the typekeywords
// * and is NOT included in the Initiative's catalog.
// * This can be used to locate "Other" Projects
// * @param initiative
// * @returns
// */
// export function getUnConnectedProjectsQuery(
// initiative: IHubInitiative
// ): IQuery {
// // get query that returns Hub Projects with the initiative keyword
// let query = getTypeWithoutKeywordQuery(
// "Hub Project",
// `initiative|${initiative.id}`
// );
// // The the item scope from the catalog...
// const qry = getProp(initiative, "catalog.scopes.item");

// // negate the scope, combine that with the base query
// query = combineQueries([query, negateGroupPredicates(qry)]);
// return query;
// }
6 changes: 3 additions & 3 deletions packages/common/src/projects/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ export async function enrichProjectSearchResult(
* chosen to connect to. If project has not defined any associations
* to any Initiatives, will return `null`.
* Currently, we have not implemented a means to get the list of initiatives that have
* "Approved" the Project via inclusion in it's catalog.
* "Accepted" the Project via inclusion in it's catalog.
*
* If needed, this could be done by getting all the groups the project is shared into
* then cross-walking that into the catalogs of all the Connected Initiatives
* then cross-walking that into the catalogs of all the Associated Initiatives
* @param project
* @returns
*/
export function getConnectedInitiativesQuery(project: IHubProject): IQuery {
export function getAssociatedInitiativesQuery(project: IHubProject): IQuery {
// get the list of ids from the keywords
const ids = listAssociations(project, "initiative").map((a) => a.id);
if (ids.length) {
Expand Down
Loading

0 comments on commit 3fcb47f

Please sign in to comment.