mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-21 23:33:58 +00:00
19 lines
704 B
TypeScript
19 lines
704 B
TypeScript
|
|
import { useEffect, useState } from 'react';
|
||
|
|
import { useGetEntitiesQuery } from '../../graphql/entity.generated';
|
||
|
|
import { Entity } from '../../types.generated';
|
||
|
|
|
||
|
|
export function useGetEntities(urns: string[]): Entity[] {
|
||
|
|
const [verifiedUrns, setVerifiedUrns] = useState<string[]>([]);
|
||
|
|
|
||
|
|
useEffect(() => {
|
||
|
|
urns.forEach((urn) => {
|
||
|
|
if (urn.startsWith('urn:li:') && !verifiedUrns.includes(urn)) {
|
||
|
|
setVerifiedUrns((prevUrns) => [...prevUrns, urn]);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}, [urns, verifiedUrns]);
|
||
|
|
|
||
|
|
const { data } = useGetEntitiesQuery({ variables: { urns: verifiedUrns }, skip: !verifiedUrns.length });
|
||
|
|
return (data?.entities || []) as Entity[];
|
||
|
|
}
|