Skip to content

webui: Enable path search with auto-expand in the compression job file lister #1781

@junhaoliao

Description

@junhaoliao

Request

Note

This feature builds on top of the file listing UI added in #1292

Enable the TreeSelect search input with auto-expand behavior. Currently, PathsSelectFormItem has showSearch={false}, disabling the search box entirely.

Proposed behaviour:

  1. Enable "search" so users may manually input a single path per selection
  2. When the user types a path ending with /, automatically load and expand to that directory. For example:
  • /logs/ → loads children of /logs
  • /logs/prod/ → loads children of both /logs and /logs/prod

This allows users to quickly navigate to deep paths (e.g., /logs/production/app1/2024/12/08/) without clicking through each level.

Possible implementation

  1. Change showSearch={false} to showSearch={true} in the TreeSelect props
  2. Add an onSearch handler:
const handleSearch = useCallback(async (value: string) => {
    const trimmed = value.trim();
    if (!trimmed.startsWith(ROOT)) {
        return;
    }
    setIsLoading(true);
    try {
        const ancestors = getAncestorPaths(trimmed);
        for (const p of ancestors.slice(0, -1)) {
            await loadPath(p);
        }
        if (value.endsWith(ROOT) && 1 < trimmed.length) {
            await loadPath(trimmed.slice(0, -1));
        }
        setExpandedKeys((prev) => [...new Set([...prev, ...ancestors])]);
    } catch (e) {
        console.error("Failed to search:", e);
        message.error(e instanceof Error ? e.message : "Failed to search for path");
    } finally {
        setIsLoading(false);
    }
}, [loadPath]);

const getAncestorPaths = (path: string): string[] => {
    const segments = path.split(ROOT).filter(Boolean);
    const paths = [ROOT];
    let current = ROOT;
    for (const seg of segments) {
        current = joinPath(current, seg);
        paths.push(current);
    }
    return paths;
};

Considerations

  • Antd TreeSelect's loadData() is now not triggered when searching in the latest versions. See https://ant.design/components/tree-select#faq-load-data-expand for details / mitigations
  • Sequential loading may be slow for deep paths; consider debouncing
  • Errors in loading any parent directory should halt expansion gracefully

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions