Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix path filtering when directory has whitespace in it #3600

Merged
merged 2 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ui/v2.5/src/components/List/Filters/PathFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const PathFilter: React.FC<IInputFilterProps> = ({
currentDirectory={criterion.value ? criterion.value.toString() : ""}
setCurrentDirectory={(v) => onValueChanged(v)}
collapsible
quoteSpaced
hideError
defaultDirectories={libraryPaths}
/>
)}
Expand Down
29 changes: 23 additions & 6 deletions ui/v2.5/src/components/Shared/FolderSelect/FolderSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface IProps {
defaultDirectories?: string[];
appendButton?: JSX.Element;
collapsible?: boolean;
quoteSpaced?: boolean;
hideError?: boolean;
}

export const FolderSelect: React.FC<IProps> = ({
Expand All @@ -21,15 +23,26 @@ export const FolderSelect: React.FC<IProps> = ({
defaultDirectories,
appendButton,
collapsible = false,
quoteSpaced = false,
hideError = false,
}) => {
const [showBrowser, setShowBrowser] = React.useState(false);
const [directory, setDirectory] = useState(currentDirectory);
const { data, error, loading } = useDirectory(directory);

const isQuoted =
quoteSpaced && directory.startsWith('"') && directory.endsWith('"');
const { data, error, loading } = useDirectory(
isQuoted ? directory.slice(1, -1) : directory
);

const intl = useIntl();

const defaultDirectoriesOrEmpty = defaultDirectories ?? [];

const selectableDirectories: string[] = currentDirectory
? data?.directory.directories ?? defaultDirectories ?? []
: defaultDirectories ?? [];
? data?.directory.directories ??
(error && hideError ? [] : defaultDirectoriesOrEmpty)
: defaultDirectoriesOrEmpty;

const debouncedSetDirectory = useDebouncedSetState(setDirectory, 250);

Expand All @@ -40,6 +53,10 @@ export const FolderSelect: React.FC<IProps> = ({
}, [currentDirectory, directory, debouncedSetDirectory]);

function setInstant(value: string) {
if (quoteSpaced && value.includes(" ")) {
value = `"${value}"`;
}

setCurrentDirectory(value);
setDirectory(value);
}
Expand Down Expand Up @@ -95,13 +112,13 @@ export const FolderSelect: React.FC<IProps> = ({
<InputGroup.Append className="align-self-center">
{loading ? (
<LoadingIndicator inline small message="" />
) : (
) : !hideError ? (
<Icon icon={faTimes} color="red" className="ml-3" />
)}
) : undefined}
</InputGroup.Append>
) : undefined}
</InputGroup>
{error !== undefined && (
{!hideError && error !== undefined && (
<h5 className="mt-4 text-break">Error: {error.message}</h5>
)}
<Collapse in={!collapsible || showBrowser}>
Expand Down