-
-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: change ownerReference to union of string and object It replaces the `reference` from the ownerReference to a union of string and an object with id and collection. The string refers to the owner id. The object with id and collection keep compatibility with `reference` in case someone use like that. It adds a collection utility to get the owner from the onwerReference. Fix #1034 * Create wild-items-shout.md --------- Co-authored-by: David Boyne <[email protected]>
- Loading branch information
1 parent
60919ab
commit 04ab91d
Showing
7 changed files
with
78 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@eventcatalog/core": patch | ||
--- | ||
|
||
fix(core): fixed issue with teams/owners not showing in the UI |
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { getCollection, type CollectionEntry } from 'astro:content'; | ||
|
||
const getOwners = (function () { | ||
type Owners = CollectionEntry<'users' | 'teams'>; | ||
let cachedOwners: Map<string, Owners> | null = null; | ||
let initializingPromise: Promise<Map<string, Owners>> | null = null; | ||
|
||
/** | ||
* Initializes and caches the owners by fetching from the 'users' and 'teams' collections. | ||
*/ | ||
async function init() { | ||
const ownersMap = new Map<string, CollectionEntry<'users' | 'teams'>>(); | ||
|
||
const owners = await Promise.all([ | ||
getCollection('users', (entry) => entry.data.hidden !== true), | ||
getCollection('teams', (entry) => entry.data.hidden !== true), | ||
]); | ||
|
||
for (const owner of owners.flat()) { | ||
ownersMap.set(owner.data.id, owner); | ||
} | ||
|
||
cachedOwners = ownersMap; | ||
initializingPromise = null; | ||
|
||
return cachedOwners; | ||
} | ||
|
||
return () => | ||
cachedOwners || // Return cached owners if already initialized | ||
initializingPromise || // Return the promise if initialization is in progress | ||
(initializingPromise = init()); // Initialize if neither cache nor promise exists | ||
})(); | ||
|
||
export async function getOwner(lookup: { id: string }): Promise<CollectionEntry<'users' | 'teams'> | undefined> { | ||
const lookupId = typeof lookup === 'string' ? lookup : lookup.id; | ||
|
||
const owner = (await getOwners()).get(lookupId); | ||
|
||
if (!owner) console.warn(`Entry ${lookupId} not found in "teams"/"users" collections.`); | ||
|
||
return owner; | ||
} |