-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance associations logic to handle forming associations (#1395)
- enhance wellKnownCatalog utils to accept optional filters to apply to the catalog scopes - rename getWellKnownAssociationsCatalog module > wellKnownAssociationCatalogs - add new util getAvailableToRequestAssociationCatalogs - fix getAssociationStats to handle hubSearch errors - expose a new util, getReferencedEntityIds - export a constant for ASSOCIATION_REFERENCE_LIMIT - extend ICardActionLink interface to optionally accept disabled and tooltip properties
- Loading branch information
1 parent
fe02c09
commit 6eb7e5f
Showing
13 changed files
with
302 additions
and
20 deletions.
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
packages/common/src/associations/getReferencedEntityIds.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,29 @@ | ||
import { HubEntity, HubEntityType } from "../core/types"; | ||
import { getIdsFromKeywords } from "./internal/getIdsFromKeywords"; | ||
|
||
/** | ||
* The following util returns an array of ids that the provided | ||
* entity "references" via a typeKeyword of the form ref|<associationType>|<id> | ||
* | ||
* Note: if a specific associationType is not provided, this util | ||
* will return ALL the ids that the provided entity "references" | ||
* | ||
* Additional context: the model for associations is built around | ||
* platform capabilities. Platform imposes a limit of 128 on the | ||
* number of typeKeywords that can be set on an item. Since "child" | ||
* entities form their half of an association connection via | ||
* typeKeywords, we must limit the number of associations a child | ||
* can request or accept to far fewer than 128. For now, we are | ||
* imposing a limit of 50. From the application, we can then use | ||
* this util to determine if a child has already reached the limit | ||
* | ||
* @param entity - hub entity to extract ids from | ||
* @param associationType - entity type to extract reference ids for | ||
* @returns {string[]} | ||
*/ | ||
export const getReferencedEntityIds = ( | ||
entity: HubEntity, | ||
associationType?: HubEntityType | ||
): string[] => { | ||
return getIdsFromKeywords(entity, associationType); | ||
}; |
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
21 changes: 21 additions & 0 deletions
21
packages/common/test/associations/getReferencedEntityIds.test.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,21 @@ | ||
import { HubEntity } from "../../src/core/types"; | ||
import { getReferencedEntityIds } from "../../src/associations/getReferencedEntityIds"; | ||
import * as GetIdsFromKeywordsModule from "../../src/associations/internal/getIdsFromKeywords"; | ||
|
||
describe("getReferencedEntityIds", () => { | ||
let getIdsFromKeywordsSpy: jasmine.Spy; | ||
|
||
beforeEach(() => { | ||
getIdsFromKeywordsSpy = spyOn( | ||
GetIdsFromKeywordsModule, | ||
"getIdsFromKeywords" | ||
).and.returnValue([]); | ||
}); | ||
it("delegates to getIdsFromKeywords", () => { | ||
const entity = { id: "00c", typeKeywords: [] } as unknown as HubEntity; | ||
const associationType = "initiative"; | ||
|
||
getReferencedEntityIds(entity, associationType); | ||
expect(getIdsFromKeywordsSpy).toHaveBeenCalledWith(entity, associationType); | ||
}); | ||
}); |
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
Oops, something went wrong.