revert(ui): use reverted API for workflow library

This commit is contained in:
psychedelicious
2025-03-12 06:28:34 +10:00
parent a8759ea0a6
commit dd5f353465
2 changed files with 19 additions and 23 deletions

View File

@@ -20,7 +20,7 @@ import { memo, useCallback, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { PiArrowCounterClockwiseBold, PiUsersBold } from 'react-icons/pi';
import { useDispatch } from 'react-redux';
import { useGetTagCountsWithFilterQuery, useListWorkflowsQuery } from 'services/api/endpoints/workflows';
import { useGetCountsByTagQuery, useListWorkflowsQuery } from 'services/api/endpoints/workflows';
import type { S } from 'services/api/types';
export const WorkflowLibrarySideNav = () => {
@@ -182,15 +182,13 @@ RecentWorkflows.displayName = 'RecentWorkflows';
const useCountForIndividualTag = (tag: string) => {
const allTags = useStore($workflowLibraryTagOptions);
const tags = useAppSelector(selectWorkflowLibraryTags);
const queryArg = useMemo(
() =>
({
tags_to_count: allTags,
selected_tags: tags,
categories: ['default'], // We only allow filtering by tag for default workflows
}) satisfies Parameters<typeof useGetTagCountsWithFilterQuery>[0],
[allTags, tags]
tags: allTags,
categories: ['default'],
}) satisfies Parameters<typeof useGetCountsByTagQuery>[0],
[allTags]
);
const queryOptions = useMemo(
() =>
@@ -198,26 +196,24 @@ const useCountForIndividualTag = (tag: string) => {
selectFromResult: ({ data }) => ({
count: data?.[tag] ?? 0,
}),
}) satisfies Parameters<typeof useGetTagCountsWithFilterQuery>[1],
}) satisfies Parameters<typeof useGetCountsByTagQuery>[1],
[tag]
);
const { count } = useGetTagCountsWithFilterQuery(queryArg, queryOptions);
const { count } = useGetCountsByTagQuery(queryArg, queryOptions);
return count;
};
const useCountForTagCategory = (tagCategory: WorkflowTagCategory) => {
const allTags = useStore($workflowLibraryTagOptions);
const tags = useAppSelector(selectWorkflowLibraryTags);
const queryArg = useMemo(
() =>
({
tags_to_count: allTags,
selected_tags: tags,
tags: allTags,
categories: ['default'], // We only allow filtering by tag for default workflows
}) satisfies Parameters<typeof useGetTagCountsWithFilterQuery>[0],
[allTags, tags]
}) satisfies Parameters<typeof useGetCountsByTagQuery>[0],
[allTags]
);
const queryOptions = useMemo(
() =>
@@ -230,11 +226,11 @@ const useCountForTagCategory = (tagCategory: WorkflowTagCategory) => {
count: tagCategory.tags.reduce((acc, tag) => acc + (data[tag] ?? 0), 0),
};
},
}) satisfies Parameters<typeof useGetTagCountsWithFilterQuery>[1],
}) satisfies Parameters<typeof useGetCountsByTagQuery>[1],
[tagCategory]
);
const { count } = useGetTagCountsWithFilterQuery(queryArg, queryOptions);
const { count } = useGetCountsByTagQuery(queryArg, queryOptions);
return count;
};
@@ -306,7 +302,7 @@ TagCategory.displayName = 'TagCategory';
const TagCheckbox = memo(({ tag, ...rest }: CheckboxProps & { tag: string }) => {
const dispatch = useAppDispatch();
const selectedTags = useAppSelector(selectWorkflowLibraryTags);
const isSelected = selectedTags.includes(tag);
const isChecked = selectedTags.includes(tag);
const count = useCountForIndividualTag(tag);
const onChange = useCallback(() => {
@@ -318,7 +314,7 @@ const TagCheckbox = memo(({ tag, ...rest }: CheckboxProps & { tag: string }) =>
}
return (
<Checkbox isChecked={isSelected} onChange={onChange} {...rest} flexShrink={0}>
<Checkbox isChecked={isChecked} onChange={onChange} {...rest} flexShrink={0}>
<Text>{`${tag} (${count})`}</Text>
</Checkbox>
);

View File

@@ -71,12 +71,12 @@ export const workflowsApi = api.injectEndpoints({
}),
providesTags: ['FetchOnReconnect', { type: 'Workflow', id: LIST_TAG }],
}),
getTagCountsWithFilter: build.query<
paths['/api/v1/workflows/tag_counts_with_filter']['get']['responses']['200']['content']['application/json'],
NonNullable<paths['/api/v1/workflows/tag_counts_with_filter']['get']['parameters']['query']>
getCountsByTag: build.query<
paths['/api/v1/workflows/counts_by_tag']['get']['responses']['200']['content']['application/json'],
NonNullable<paths['/api/v1/workflows/counts_by_tag']['get']['parameters']['query']>
>({
query: (params) => ({
url: `${buildWorkflowsUrl('tag_counts_with_filter')}?${queryString.stringify(params, { arrayFormat: 'none' })}`,
url: `${buildWorkflowsUrl('counts_by_tag')}?${queryString.stringify(params, { arrayFormat: 'none' })}`,
}),
providesTags: ['WorkflowTagCountsWithFilter'],
}),
@@ -150,7 +150,7 @@ export const workflowsApi = api.injectEndpoints({
export const {
useUpdateOpenedAtMutation,
useGetTagCountsWithFilterQuery,
useGetCountsByTagQuery,
useLazyGetWorkflowQuery,
useGetWorkflowQuery,
useCreateWorkflowMutation,