Skip to content

Commit

Permalink
chore(weave): add useProjectHasWeaveData hook (#1372)
Browse files Browse the repository at this point in the history
* add useProjectHasWeaveData hook

* add loading

* delete unused funcs

* add calls hook back
  • Loading branch information
jwlee64 authored Mar 26, 2024
1 parent d31d6fe commit 68c6a9d
Showing 1 changed file with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const WFDataModelAutoProvider: FC<{
entityName: string;
projectName: string;
}> = ({entityName, projectName, children}) => {
// const hasTSData = useProjectHasTraceServerCalls(entityName, projectName);
// const { result: hasTSData } = useProjectHasTraceServerData(entityName, projectName);
const hasTSData = true;

if (hasTSData) {
Expand All @@ -104,7 +104,7 @@ export const WFDataModelAutoProvider: FC<{

/**
* Returns true if the client can connect to trace server and the project has
* data in the trace server.
* calls.
*/
export const useProjectHasTraceServerCalls = (
entity: string,
Expand All @@ -114,6 +114,38 @@ export const useProjectHasTraceServerCalls = (
const calls = tsWFDataModelHooks.useCalls(entity, project, {}, 1, {
skip: !hasTraceServer,
});
const loading = calls.loading;
return {
loading,
result: (calls.result ?? []).length > 0,
};
};

/**
* Returns true if the client can connect to trace server and the project has
* objects or calls.
*/
export const useProjectHasTraceServerData = (
entity: string,
project: string
) => {
const hasTraceServer = useHasTraceServerClientContext();
const objs = tsWFDataModelHooks.useRootObjectVersions(
entity,
project,
{},
1,
{
skip: !hasTraceServer,
}
);

return (calls.result ?? []).length > 0;
const calls = tsWFDataModelHooks.useCalls(entity, project, {}, 1, {
skip: !hasTraceServer,
});
const loading = objs.loading || calls.loading;
return {
loading,
result: (objs.result ?? []).length > 0 || (calls.result ?? []).length > 0,
};
};

0 comments on commit 68c6a9d

Please sign in to comment.