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

feat: ini upload #375

Merged
merged 4 commits into from
Nov 15, 2024
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
26 changes: 26 additions & 0 deletions src/api/custom/postIniFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import axios from 'axios';
import { OpenAPI } from '../generated';
import type { UploadIniFileCommandResponse } from '../generated/models/UploadIniFileCommandResponse';

export const postIniFile = async (
modelId: string,
formData: FormData,
): Promise<UploadIniFileCommandResponse> => {
const token = OpenAPI.TOKEN; // replace with your bearer token
const base = OpenAPI.BASE;

const response = await axios.post(
`/api/uploads/models/${modelId}/ini-file`,
formData,
{
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'multipart/form-data',
},
baseURL: base,
},
);

// create an object URL for the image blob and return it
return response;
};
4 changes: 4 additions & 0 deletions src/api/generated/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type { AddMetadataResponseDto } from './models/AddMetadataResponseDto';
export type { AddParameterDto } from './models/AddParameterDto';
export type { AddStatigraphicGroupForm } from './models/AddStatigraphicGroupForm';
export type { AddStratigraphicGroupCommandResponse } from './models/AddStratigraphicGroupCommandResponse';
export type { AnalogueModelConfigurationDto } from './models/AnalogueModelConfigurationDto';
export type { AnalogueModelDetail } from './models/AnalogueModelDetail';
export type { AnalogueModelImageDto } from './models/AnalogueModelImageDto';
export type { AnalogueModelList } from './models/AnalogueModelList';
Expand All @@ -35,6 +36,7 @@ export type { ComputeCaseInputSettingsDto } from './models/ComputeCaseInputSetti
export type { ComputeCaseModelAreaDto } from './models/ComputeCaseModelAreaDto';
export { ComputeJobStatus } from './models/ComputeJobStatus';
export { ComputeType } from './models/ComputeType';
export type { ConfigurationParameterDto } from './models/ConfigurationParameterDto';
export type { ConvertAnalogueModelCommand } from './models/ConvertAnalogueModelCommand';
export type { ConvertAnalogueModelCommandResponse } from './models/ConvertAnalogueModelCommandResponse';
export type { ConvertAnalogueModelDto } from './models/ConvertAnalogueModelDto';
Expand Down Expand Up @@ -154,6 +156,8 @@ export type { UploadChunkCommandResponse } from './models/UploadChunkCommandResp
export type { UploadDetail } from './models/UploadDetail';
export { UploadFileCategory } from './models/UploadFileCategory';
export { UploadFileType } from './models/UploadFileType';
export type { UploadIniFileCommandResponse } from './models/UploadIniFileCommandResponse';
export type { UploadIniFileDto } from './models/UploadIniFileDto';
export type { UploadList } from './models/UploadList';
export { UploadStatus } from './models/UploadStatus';

Expand Down
27 changes: 27 additions & 0 deletions src/api/generated/models/AnalogueModelConfigurationDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { ConfigurationParameterDto } from './ConfigurationParameterDto';

export type AnalogueModelConfigurationDto = {
analogueModelConfigurationId?: string;
analogueModelId?: string;
template?: ConfigurationParameterDto;
simStopTime?: ConfigurationParameterDto;
outputInterval?: ConfigurationParameterDto;
basinSlope?: ConfigurationParameterDto;
channelWidth?: ConfigurationParameterDto;
riverLength?: ConfigurationParameterDto;
riverDischargeIni?: ConfigurationParameterDto;
riverDischargeFin?: ConfigurationParameterDto;
tidalAmplitude?: ConfigurationParameterDto;
waveHeightIni?: ConfigurationParameterDto;
waveHeightFin?: ConfigurationParameterDto;
waveDirection?: ConfigurationParameterDto;
subsidenceLand?: ConfigurationParameterDto;
subsidenceSea?: ConfigurationParameterDto;
composition?: ConfigurationParameterDto;
};

4 changes: 3 additions & 1 deletion src/api/generated/models/AnalogueModelDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* tslint:disable */
/* eslint-disable */

import type { AnalogueModelConfigurationDto } from './AnalogueModelConfigurationDto';
import type { AnalogueModelImageDto } from './AnalogueModelImageDto';
import type { AnalogueModelSourceType } from './AnalogueModelSourceType';
import type { GeologicalGroupDto } from './GeologicalGroupDto';
Expand Down Expand Up @@ -32,6 +33,7 @@ export type AnalogueModelDetail = {
geologicalGroups: Array<GeologicalGroupDto>;
outcrops: Array<OutcropDto>;
processingStatus: JobStatus;
analogueModelImage?: AnalogueModelImageDto;
analogueModelImage: AnalogueModelImageDto;
iniParameters: AnalogueModelConfigurationDto;
};

2 changes: 2 additions & 0 deletions src/api/generated/models/AnalogueModelList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/* tslint:disable */
/* eslint-disable */

import type { AnalogueModelConfigurationDto } from './AnalogueModelConfigurationDto';
import type { AnalogueModelSourceType } from './AnalogueModelSourceType';
import type { GeologicalGroupDto } from './GeologicalGroupDto';
import type { JobStatus } from './JobStatus';
Expand All @@ -21,6 +22,7 @@ export type AnalogueModelList = {
stratigraphicGroups: Array<StratigraphicGroupDto>;
geologicalGroups: Array<GeologicalGroupDto>;
outcrops: Array<OutcropDto>;
iniParameters: AnalogueModelConfigurationDto;
analogueModelId: string;
name: string;
description: string;
Expand Down
11 changes: 11 additions & 0 deletions src/api/generated/models/ConfigurationParameterDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

export type ConfigurationParameterDto = {
name?: string | null;
value?: string | null;
description?: string | null;
};

1 change: 1 addition & 0 deletions src/api/generated/models/UploadFileType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum UploadFileType {
NET_CDF = 'NetCDF',
RES_QMLEPC = 'ResQMLEpc',
RES_QMLDATA = 'ResQMLData',
INI_DATA = 'IniData',
}
15 changes: 15 additions & 0 deletions src/api/generated/models/UploadIniFileCommandResponse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { UploadIniFileDto } from './UploadIniFileDto';

export type UploadIniFileCommandResponse = {
success?: boolean;
count?: number | null;
message?: string | null;
validationErrors?: Array<string> | null;
data: UploadIniFileDto;
};

17 changes: 17 additions & 0 deletions src/api/generated/models/UploadIniFileDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* generated using openapi-typescript-codegen -- do no edit */
/* istanbul ignore file */
/* tslint:disable */
/* eslint-disable */

import type { UploadFileCategory } from './UploadFileCategory';
import type { UploadFileType } from './UploadFileType';
import type { UploadStatus } from './UploadStatus';

export type UploadIniFileDto = {
uploadId: string;
originalFileName: string;
uploadStatus: UploadStatus;
uploadFileType: UploadFileType;
uploadFileCategory: UploadFileCategory;
};

34 changes: 34 additions & 0 deletions src/api/generated/services/UploadsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { PrepareChunkedUploadCommandResponse } from '../models/PrepareChunk
import type { UploadAnalogueModelCommandResponse } from '../models/UploadAnalogueModelCommandResponse';
import type { UploadChunkCommandResponse } from '../models/UploadChunkCommandResponse';
import type { UploadFileType } from '../models/UploadFileType';
import type { UploadIniFileCommandResponse } from '../models/UploadIniFileCommandResponse';

import type { CancelablePromise } from '../core/CancelablePromise';
import { OpenAPI } from '../core/OpenAPI';
Expand Down Expand Up @@ -155,4 +156,37 @@ export class UploadsService {
});
}

/**
* @param id
* @param formData
* @returns UploadIniFileCommandResponse Success
* @throws ApiError
*/
public static postApiUploadsModelsIniFile(
id: string,
formData?: {
ContentType?: string;
ContentDisposition?: string;
Headers?: Record<string, Array<string>>;
Length?: number;
Name?: string;
FileName?: string;
},
): CancelablePromise<UploadIniFileCommandResponse> {
return __request(OpenAPI, {
method: 'POST',
url: '/api/uploads/models/{id}/ini-file',
path: {
'id': id,
},
formData: formData,
mediaType: 'multipart/form-data',
errors: {
400: `Bad Request`,
403: `Forbidden`,
404: `Not Found`,
},
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import {
ModelAreaTypeDto,
} from '../../api/generated';
import { useMutateAreaCoordinates } from '../../hooks/useMutateAreaCoordinates';
import { ErrorMessage } from '../ErrorMessage/ErrorMessage';
import { AnalogueModelImageView } from '../ImageView/AnalogueModelImageView';
import * as Styled from './AreaCoordinates.styled';
import { CoordinateInput } from './CoordinateInput/CoordinateInput';
import {
Expand All @@ -29,6 +27,8 @@ import {
analogueModelDefault,
usePepmContextStore,
} from '../../hooks/GlobalState';
import { ErrorMessage } from './ErrorMessage/ErrorMessage';
import { AnalogueModelImageView } from './ImageView/AnalogueModelImageView';

export type AreaCoordinateType = {
modelAreaId: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Typography } from '@equinor/eds-core-react';
import { CoordinateErrorType } from '../AreaCoordinates/hooks/AreaCoordinates.hooks';
import { CoordinateErrorType } from '../hooks/AreaCoordinates.hooks';

export const ErrorMessage = ({ errors }: { errors: CoordinateErrorType }) => {
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from 'styled-components';
import { spacings } from '../../tokens/spacings';
import { theme } from '../../tokens/theme';
import { theme } from '../../../tokens/theme';
import { spacings } from '../../../tokens/spacings';

export const ImageWrapper = styled.div`
display: flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Typography } from '@equinor/eds-core-react';
import { AreaCoordinateType } from '../AreaCoordinates/AreaCoordinates';
import { AreaCoordinateType } from '../../AreaCoordinates/AreaCoordinates';
import { ModelImageCanvas } from './ModelImageCanvas/ModelImageCanvas';
import { CanvasWrapper } from './AnalogueModelImageView.styled';
import { usePepmContextStore } from '../../hooks/GlobalState';
import { usePepmContextStore } from '../../../hooks/GlobalState';

export const AnalogueModelImageView = ({
coordinateBox,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef } from 'react';
import { ImageMetadataDto } from '../../../api/generated';
import { AreaCoordinateType } from '../../AreaCoordinates/AreaCoordinates';
import { AreaCoordinateType } from '../../../AreaCoordinates/AreaCoordinates';
import { ImageMetadataDto } from '../../../../api/generated';

export const ModelImageCanvas = ({
imageData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { delete_to_trash as deleteIcon } from '@equinor/eds-icons';
import { ChangeEvent } from 'react';
import IconButton from '../../../components/IconButton/IconButton';
import { FileUploader } from '../FileUploader/FileUploader';
import * as Styled from './FileColumn.styled';
import * as Styled from './FileRow.styled';

type FileDisplay = { isVisible: boolean; toggle: () => void };

Expand All @@ -15,7 +15,7 @@ interface FileColumnProps {
fileDisplay?: FileDisplay;
fileSize?: number;
}
export const FileColumn = ({
export const FileRow = ({
onChange,
onDelete,
INI,
Expand Down
7 changes: 5 additions & 2 deletions src/features/HandleModel/FileUploader/FileUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export const FileUploader = ({
<>{file.name}</>
) : (
<form method="post" encType="multipart/form-data">
<FileUpload htmlFor="file-upload" className="custom-file-upload">
<FileUpload
htmlFor={`${acceptType.toLowerCase()}`}
className="custom-file-upload"
>
{INI && (
<Icon fill={theme.light.text.staticIconsTertiary} data={arrowIcon} />
)}
Expand All @@ -36,7 +39,7 @@ export const FileUploader = ({
</SelectFile>
{INI && '(optional)'}
<input
id="file-upload"
id={`${acceptType.toLowerCase()}`}
required={!INI}
type="file"
accept={`.${acceptType.toLowerCase()}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@ import { useEffect } from 'react';
import { AnalogueModelDetail } from '../../../api/generated';
import { ErrorType, FilesProps } from './HandleModelComponent';
export const useHandleModelComponent = (
setFileSize: React.Dispatch<React.SetStateAction<number>>,
setMetadata: React.Dispatch<React.SetStateAction<AnalogueModelDetail>>,
files: FilesProps,
rawFile?: File,
existingData?: AnalogueModelDetail,
) => {
useEffect(() => {
if (rawFile === undefined) return;
setFileSize(rawFile.size);
}, [rawFile, setFileSize]);

useEffect(() => {
if (files.NC === undefined) setFileSize(0);
}, [files, setFileSize]);

useEffect(() => {
if (existingData) setMetadata(existingData);
}, [existingData, setMetadata]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from 'styled-components';
import { spacings } from '../../../tokens/spacings';
import { theme } from '../../../tokens/theme';
import { TextField } from '@equinor/eds-core-react';

export const Wrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -52,3 +53,9 @@ export const InfoNavigation = styled.div`

row-gap: ${spacings.MEDIUM};
`;

export const IniFileTextField = styled(TextField)`
display: flex;
flex-direction: column;
row-gap: ${spacings.MEDIUM};
`;
Loading