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

task/WG-427: add file modal to point cloud #317

Merged
merged 5 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
14 changes: 2 additions & 12 deletions react/src/components/AssetsPanel/AssetsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import FeatureFileTree from '@hazmapper/components/FeatureFileTree';
import { FeatureCollection, Project, TapisFilePath } from '@hazmapper/types';
import { Button } from '@tacc/core-components';
import { useFeatures, useImportFeature } from '@hazmapper/hooks';
import { IMPORTABLE_FEATURE_TYPES } from '@hazmapper/utils/fileUtils';
import FileBrowserModal from '../FileBrowserModal/FileBrowserModal';

const getFilename = (projectName: string) => {
Expand Down Expand Up @@ -94,25 +95,14 @@ const AssetsPanel: React.FC<Props> = ({
setIsModalOpen(!isModalOpen);
};

const allowedFileExtensions = [
'shp',
'jpg',
'jpeg',
'json',
'geojson',
'gpx',
'rq',
'png',
];

return (
<div className={styles.root}>
<div className={styles.topSection}>
<FileBrowserModal
isOpen={isModalOpen}
toggle={toggleModal}
onImported={handleFileImport}
allowedFileExtensions={allowedFileExtensions}
allowedFileExtensions={IMPORTABLE_FEATURE_TYPES}
/>
<Button onClick={toggleModal} type="secondary" iconNameBefore="add">
Import from DesignSafe
Expand Down
47 changes: 27 additions & 20 deletions react/src/components/PointCloudsPanel/PointCloudPanelButtons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ interface DeletePointCloudButtonProps {
pointCloudId: number;
}

import React from 'react';
import React, { useState } from 'react';
import { Button } from 'antd';
import { UploadOutlined, DeleteOutlined } from '@ant-design/icons';

import { PointCloud } from '@hazmapper/types';
import { PointCloud, TapisFilePath } from '@hazmapper/types';
import FileBrowserModal from '../FileBrowserModal/FileBrowserModal';
import { useDeletePointCloud, useImportPointCloudFile } from '@hazmapper/hooks';
import { IMPORTABLE_POINT_CLOUD_TYPES } from '@hazmapper/utils/fileUtils';

interface UploadPointCloudButtonProps {
pointCloud: PointCloud;
Expand All @@ -17,31 +19,36 @@ interface UploadPointCloudButtonProps {
export const UploadPointCloudButton: React.FC<UploadPointCloudButtonProps> = ({
pointCloud,
}) => {
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const { mutate: addPointCloudFile } = useImportPointCloudFile({
projectId: pointCloud.project_id,
pointCloudId: pointCloud.id,
});

const handleAddFile = () => {
console.log('TODO: Opening file browser for point cloud:', pointCloud.id);
addPointCloudFile({
files: [
{
system: 'project-4072868216578445806-242ac117-0001-012',
path: 'point_clouds_good/red-rocks.laz',
},
],
});
const handleFileImport = (files: TapisFilePath[]) => {
addPointCloudFile({ files });
setIsModalOpen(false);
};

return (
<Button
data-testid={`upload-point-cloud-${pointCloud.id}`}
size="small"
icon={<UploadOutlined />}
onClick={() => handleAddFile()}
>
Add las/laz
</Button>
<>
<Button
data-testid={`upload-point-cloud-${pointCloud.id}`}
size="small"
icon={<UploadOutlined />}
onClick={() => setIsModalOpen(true)}
>
Add las/laz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting an error when selecting a project:
Screenshot 2025-02-11 at 5 55 34 PM

</Button>
{isModalOpen && (
<FileBrowserModal
isOpen={isModalOpen}
toggle={() => setIsModalOpen(false)}
onImported={handleFileImport}
allowedFileExtensions={IMPORTABLE_POINT_CLOUD_TYPES}
/>
)}
</>
);
};

Expand Down
22 changes: 22 additions & 0 deletions react/src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
import { FileData } from 'chonky';
import { TapisFilePath, File } from '@hazmapper/types';

export const IMPORTABLE_FEATURE_TYPES = [
'shp',
'jpg',
'jpeg',
'json',
'geojson',
'gpx',
'rq',
];

export const IMPORTABLE_FEATURE_ASSET_TYPES = [
'jpeg',
'jpg',
'png',
'mp4',
'mov',
'mpeg4',
'webm',
];

export const IMPORTABLE_POINT_CLOUD_TYPES = ['las', 'laz'];

export const serializeToChonkyFile = (
file: File,
allowedFileExtensions: string[]
Expand Down
Loading