Skip to content

Commit

Permalink
Merge pull request #546 from fairDataSociety/fix/search
Browse files Browse the repository at this point in the history
fix: search
  • Loading branch information
tfius authored Oct 16, 2023
2 parents d31efe8 + fe376b2 commit 8a0c2ad
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/api/pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export function getFdpPathByDirectory(directory: string): string {
return '/';
}

if (directory.startsWith('/')) {
return directory;
}

return '/' + directory;
}

Expand Down
14 changes: 8 additions & 6 deletions src/components/Modals/PreviewFileModal/PreviewFileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import FilePreview, {
isFilePreviewSupported,
} from '@components/FilePreview/FilePreview';
import { FileItem } from '@fairdatasociety/fdp-storage';
import { extractFileExtension } from '@utils/filename';
import { extractFileExtension, rootPathToRelative } from '@utils/filename';
import { useLocales } from '@context/LocalesContext';

interface PreviewModalProps {
Expand Down Expand Up @@ -62,6 +62,8 @@ const PreviewFileModal: FC<PreviewModalProps> = ({
const [showConfirmDeleteModal, setShowConfirmDeleteModal] = useState(false);
const { intl } = useLocales();

const directory = rootPathToRelative(previewFile.path || directoryName);

useEffect(() => {
if (!isFilePreviewSupported(previewFile?.name)) {
return;
Expand All @@ -70,7 +72,7 @@ const PreviewFileModal: FC<PreviewModalProps> = ({
setLoading(true);
downloadFile(fdpClientRef.current, {
filename: previewFile?.name,
directory: previewFile.path || directoryName,
directory,
podName: activePod,
})
.then(async (response) => {
Expand All @@ -92,7 +94,7 @@ const PreviewFileModal: FC<PreviewModalProps> = ({

downloadFile(fdpClientRef.current, {
filename: previewFile?.name,
directory: directoryName,
directory,
podName: activePod,
})
.then((response) => {
Expand All @@ -119,7 +121,7 @@ const PreviewFileModal: FC<PreviewModalProps> = ({
deleteFile(fdpClientRef.current, {
file_name: previewFile?.name,
podName: activePod,
path: formatDirectory(directoryName),
path: formatDirectory(directory),
})
.then(() => {
trackEvent({
Expand Down Expand Up @@ -158,7 +160,7 @@ const PreviewFileModal: FC<PreviewModalProps> = ({
file={previewFile}
source={fileContent}
pod={activePod}
directory={directoryName}
directory={directory}
onError={() => setErrorMessage(intl.get('FILE_PREVIEW_ERROR'))}
/>
) : null}
Expand Down Expand Up @@ -254,7 +256,7 @@ const PreviewFileModal: FC<PreviewModalProps> = ({
closeModal={() => setShowShareFileModal(false)}
fileName={previewFile?.name}
podName={activePod}
path={formatDirectory(directoryName)}
path={formatDirectory(directory)}
/>

<ConfirmDeleteModal
Expand Down
4 changes: 2 additions & 2 deletions src/components/Views/DriveGridView/DriveGridView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const DriveGridView: FC<DriveGridViewProps> = ({
<div className="flex flex-wrap h-full">
{directories?.map((directory) => (
<DriveCard
key={directory.name}
key={directory.path || directory.name}
type="folder"
data={{
name: directory.name,
Expand All @@ -35,7 +35,7 @@ const DriveGridView: FC<DriveGridViewProps> = ({

{files?.map((data) => (
<DriveCard
key={data.name}
key={data.path || data.name}
type="file"
data={{
name: data.name,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Views/DriveListView/DriveListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const DriveListView: FC<DriveListViewProps> = ({
<tbody>
{pageDirectories.map((directory) => (
<DriveTableItem
key={directory.name}
key={directory.path || directory.name}
type="folder"
data={{
name: directory.name,
Expand All @@ -75,7 +75,7 @@ const DriveListView: FC<DriveListViewProps> = ({

{pageFiles.map((data) => (
<DriveTableItem
key={data.name}
key={data.path || data.name}
type="file"
data={{
name: data.name,
Expand Down
22 changes: 12 additions & 10 deletions src/pages/drive/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,24 @@ const Drive: FC = () => {
}

if (Array.isArray(content?.files)) {
matchedFiles = matchedFiles
.concat(content.files.filter(({ name }) => name.includes(search)))
.map((file) => {
file.path = path;
return file;
});
matchedFiles = matchedFiles.concat(
content.files
.filter(({ name }) => name.includes(search))
.map((file) => ({
...file,
path,
}))
);
}

if (Array.isArray(content?.directories)) {
matchedDirectories = matchedDirectories.concat(
content.directories
.filter(({ name }) => name.includes(search))
.map((directory) => {
directory.path = path;
return directory;
})
.map((directory) => ({
...directory,
path,
}))
);

if (depth < maxDepth) {
Expand Down

0 comments on commit 8a0c2ad

Please sign in to comment.