mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
feat(backend): workflow_records.get_many arg "filter_text" -> "query"
This commit is contained in:
@ -84,12 +84,14 @@ async def create_workflow(
|
||||
async def list_workflows(
|
||||
page: int = Query(default=0, description="The page to get"),
|
||||
per_page: int = Query(default=10, description="The number of workflows per page"),
|
||||
order_by: WorkflowRecordOrderBy = Query(default=WorkflowRecordOrderBy.Name, description="The order by"),
|
||||
direction: SQLiteDirection = Query(default=SQLiteDirection.Ascending, description="The order by"),
|
||||
category: WorkflowCategory = Query(default=WorkflowCategory.User, description="The category to get"),
|
||||
filter_text: Optional[str] = Query(default=None, description="The name to filter by"),
|
||||
order_by: WorkflowRecordOrderBy = Query(
|
||||
default=WorkflowRecordOrderBy.Name, description="The attribute to order by"
|
||||
),
|
||||
direction: SQLiteDirection = Query(default=SQLiteDirection.Ascending, description="The direction to order by"),
|
||||
category: WorkflowCategory = Query(default=WorkflowCategory.User, description="The category of workflow to get"),
|
||||
query: Optional[str] = Query(default=None, description="The text to query by (matches name and description)"),
|
||||
) -> PaginatedResults[WorkflowRecordListItemDTO]:
|
||||
"""Gets a page of workflows"""
|
||||
return ApiDependencies.invoker.services.workflow_records.get_many(
|
||||
page=page, per_page=per_page, order_by=order_by, direction=direction, filter_text=filter_text, category=category
|
||||
page=page, per_page=per_page, order_by=order_by, direction=direction, query=query, category=category
|
||||
)
|
||||
|
@ -44,7 +44,7 @@ class WorkflowRecordsStorageBase(ABC):
|
||||
order_by: WorkflowRecordOrderBy,
|
||||
direction: SQLiteDirection,
|
||||
category: WorkflowCategory,
|
||||
filter_text: Optional[str],
|
||||
query: Optional[str],
|
||||
) -> PaginatedResults[WorkflowRecordListItemDTO]:
|
||||
"""Gets many workflows."""
|
||||
pass
|
||||
|
@ -130,7 +130,7 @@ class SqliteWorkflowRecordsStorage(WorkflowRecordsStorageBase):
|
||||
order_by: WorkflowRecordOrderBy,
|
||||
direction: SQLiteDirection,
|
||||
category: WorkflowCategory,
|
||||
filter_text: Optional[str] = None,
|
||||
query: Optional[str] = None,
|
||||
) -> PaginatedResults[WorkflowRecordListItemDTO]:
|
||||
try:
|
||||
self._lock.acquire()
|
||||
@ -151,15 +151,15 @@ class SqliteWorkflowRecordsStorage(WorkflowRecordsStorageBase):
|
||||
FROM workflow_library
|
||||
WHERE category = ?
|
||||
"""
|
||||
main_params = [category.value]
|
||||
count_params = [category.value]
|
||||
stripped_filter_name = filter_text.strip() if filter_text else None
|
||||
if stripped_filter_name:
|
||||
filter_string = "%" + stripped_filter_name + "%"
|
||||
main_params: list[int | str] = [category.value]
|
||||
count_params: list[int | str] = [category.value]
|
||||
stripped_query = query.strip() if query else None
|
||||
if stripped_query:
|
||||
wildcard_query = "%" + stripped_query + "%"
|
||||
main_query += " AND name LIKE ? OR description LIKE ? "
|
||||
count_query += " AND name LIKE ? OR description LIKE ?;"
|
||||
main_params.extend([filter_string, filter_string])
|
||||
count_params.extend([filter_string, filter_string])
|
||||
main_params.extend([wildcard_query, wildcard_query])
|
||||
count_params.extend([wildcard_query, wildcard_query])
|
||||
|
||||
main_query += f" ORDER BY {order_by.value} {direction.value} LIMIT ? OFFSET ?;"
|
||||
main_params.extend([per_page, page * per_page])
|
||||
|
@ -51,12 +51,12 @@ const WorkflowLibraryList = () => {
|
||||
const { t } = useTranslation();
|
||||
const [category, setCategory] = useState<WorkflowCategory>('user');
|
||||
const [page, setPage] = useState(0);
|
||||
const [filter_text, setFilterText] = useState('');
|
||||
const [query, setQuery] = useState('');
|
||||
const [order_by, setOrderBy] = useState<WorkflowRecordOrderBy>('opened_at');
|
||||
const [direction, setDirection] = useState<SQLiteDirection>('ASC');
|
||||
const [debouncedFilterText] = useDebounce(filter_text, 500);
|
||||
const [debouncedQuery] = useDebounce(query, 500);
|
||||
|
||||
const query = useMemo(() => {
|
||||
const queryArg = useMemo<Parameters<typeof useListWorkflowsQuery>[0]>(() => {
|
||||
if (category === 'user') {
|
||||
return {
|
||||
page,
|
||||
@ -64,7 +64,7 @@ const WorkflowLibraryList = () => {
|
||||
order_by,
|
||||
direction,
|
||||
category,
|
||||
filter_text: debouncedFilterText,
|
||||
query: debouncedQuery,
|
||||
};
|
||||
}
|
||||
return {
|
||||
@ -73,11 +73,12 @@ const WorkflowLibraryList = () => {
|
||||
order_by: 'name' as const,
|
||||
direction: 'ASC' as const,
|
||||
category,
|
||||
filter_text: debouncedFilterText,
|
||||
query: debouncedQuery,
|
||||
};
|
||||
}, [category, debouncedFilterText, direction, order_by, page]);
|
||||
}, [category, debouncedQuery, direction, order_by, page]);
|
||||
|
||||
const { data, isLoading, isError, isFetching } = useListWorkflowsQuery(query);
|
||||
const { data, isLoading, isError, isFetching } =
|
||||
useListWorkflowsQuery(queryArg);
|
||||
|
||||
const handleChangeOrderBy = useCallback(
|
||||
(value: string | null) => {
|
||||
@ -102,7 +103,7 @@ const WorkflowLibraryList = () => {
|
||||
);
|
||||
|
||||
const resetFilterText = useCallback(() => {
|
||||
setFilterText('');
|
||||
setQuery('');
|
||||
setPage(0);
|
||||
}, []);
|
||||
|
||||
@ -120,7 +121,7 @@ const WorkflowLibraryList = () => {
|
||||
|
||||
const handleChangeFilterText = useCallback(
|
||||
(e: ChangeEvent<HTMLInputElement>) => {
|
||||
setFilterText(e.target.value);
|
||||
setQuery(e.target.value);
|
||||
setPage(0);
|
||||
},
|
||||
[]
|
||||
@ -189,12 +190,12 @@ const WorkflowLibraryList = () => {
|
||||
<InputGroup w="20rem">
|
||||
<Input
|
||||
placeholder={t('workflows.searchWorkflows')}
|
||||
value={filter_text}
|
||||
value={query}
|
||||
onKeyDown={handleKeydownFilterText}
|
||||
onChange={handleChangeFilterText}
|
||||
data-testid="workflow-search-input"
|
||||
/>
|
||||
{filter_text.trim().length && (
|
||||
{query.trim().length && (
|
||||
<InputRightElement>
|
||||
<IconButton
|
||||
onClick={resetFilterText}
|
||||
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user