mirror of
https://github.com/usebruno/bruno.git
synced 2025-06-25 14:31:44 +02:00
Made changes so only one file can be selected in raw file upload.
This commit is contained in:
parent
b54b5ff19a
commit
50482ee340
@ -0,0 +1,54 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import path from 'path';
|
||||||
|
import { useDispatch } from 'react-redux';
|
||||||
|
import { browseFile } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
|
import { IconX } from '@tabler/icons';
|
||||||
|
import { isWindowsOS } from 'utils/common/platform';
|
||||||
|
import slash from 'utils/common/slash';
|
||||||
|
|
||||||
|
const RawFilePickerEditor = ({ value, onChange, collection }) => {
|
||||||
|
value = value || '';
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const separator = isWindowsOS() ? '\\' : '/';
|
||||||
|
const filename = value != '' ? value.split(separator).pop() : value;
|
||||||
|
const title = `- ${filename}`;
|
||||||
|
|
||||||
|
const browse = () => {
|
||||||
|
dispatch(browseFile())
|
||||||
|
.then((filePath) => {
|
||||||
|
const collectionDir = collection.pathname;
|
||||||
|
|
||||||
|
filePath = filePath.startsWith(collectionDir) ?
|
||||||
|
path.relative(slash(collectionDir), slash(filePath)) : filePath;
|
||||||
|
|
||||||
|
onChange(filePath);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const clear = () => {
|
||||||
|
onChange(null);
|
||||||
|
};
|
||||||
|
|
||||||
|
return filename.length > 0 ? (
|
||||||
|
<div
|
||||||
|
className="btn btn-secondary px-1"
|
||||||
|
style={{ fontWeight: 400, width: '100%', textOverflow: 'ellipsis', overflowX: 'hidden' }}
|
||||||
|
title={title}
|
||||||
|
>
|
||||||
|
<button className="align-middle" onClick={clear}>
|
||||||
|
<IconX size={18} />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
{filename}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<button className="btn btn-secondary px-1" style={{ width: '100%' }} onClick={browse}>
|
||||||
|
Select Files
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default RawFilePickerEditor;
|
@ -3,23 +3,20 @@ import get from 'lodash/get';
|
|||||||
import cloneDeep from 'lodash/cloneDeep';
|
import cloneDeep from 'lodash/cloneDeep';
|
||||||
import { useDispatch } from 'react-redux';
|
import { useDispatch } from 'react-redux';
|
||||||
import { useTheme } from 'providers/Theme';
|
import { useTheme } from 'providers/Theme';
|
||||||
import { updateRawFile } from 'providers/ReduxStore/slices/collections';
|
|
||||||
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
import { sendRequest, saveRequest } from 'providers/ReduxStore/slices/collections/actions';
|
||||||
import StyledWrapper from './StyledWrapper';
|
import StyledWrapper from './StyledWrapper';
|
||||||
import FilePickerEditor from 'components/FilePickerEditor';
|
import RawFilePickerEditor from 'components/RawFilePickerEditor';
|
||||||
|
import { updateRequestBody } from 'providers/ReduxStore/slices/collections/index';
|
||||||
|
|
||||||
const RawFileParams = ({ item, collection }) => {
|
const RawFileParams = ({ item, collection }) => {
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const { storedTheme } = useTheme();
|
const { storedTheme } = useTheme();
|
||||||
const fileName = item.draft ? get(item, 'draft.request.body.rawFile') : get(item, 'request.body.rawFile') || [];
|
const fileName = item.draft ? get(item, 'draft.request.body.rawFile') : get(item, 'request.body.rawFile') || [];
|
||||||
|
|
||||||
const handleFileChange = (e, __filename) => {
|
const handleFileChange = (e) => {
|
||||||
const fileName = cloneDeep(__filename);
|
|
||||||
fileName.value = e.target.value;
|
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
updateRawFile({
|
updateRequestBody({
|
||||||
param: fileName,
|
content: e.target.value,
|
||||||
itemUid: item.uid,
|
itemUid: item.uid,
|
||||||
collectionUid: collection.uid
|
collectionUid: collection.uid
|
||||||
})
|
})
|
||||||
@ -28,16 +25,15 @@ const RawFileParams = ({ item, collection }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledWrapper>
|
<StyledWrapper>
|
||||||
<FilePickerEditor
|
<RawFilePickerEditor
|
||||||
value={ fileName ? fileName.value : null }
|
value={ fileName ? fileName : null }
|
||||||
onChange={(newValue) =>
|
onChange={(newValue) =>
|
||||||
handleFileChange(
|
handleFileChange(
|
||||||
{
|
{
|
||||||
target: {
|
target: {
|
||||||
value: newValue
|
value: newValue
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
fileName
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
collection={collection} />
|
collection={collection} />
|
||||||
|
@ -762,23 +762,6 @@ export const collectionsSlice = createSlice({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateRawFile: (state, action) => {
|
|
||||||
const collection = findCollectionByUid(state.collections, action.payload.collectionUid);
|
|
||||||
|
|
||||||
if(collection) {
|
|
||||||
const item = findItemInCollection(collection, action.payload.itemUid);
|
|
||||||
|
|
||||||
if (item && isItemARequest(item)) {
|
|
||||||
if (!item.draft) {
|
|
||||||
item.draft = cloneDeep(item);
|
|
||||||
}
|
|
||||||
const param = find(item.draft.request.body.rawFile, (p) => p.uid === action.payload.param.uid);
|
|
||||||
if (param) {
|
|
||||||
param.value = action.payload.param.value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
updateRequestAuthMode: (state, action) => {
|
updateRequestAuthMode: (state, action) => {
|
||||||
const collection = findCollectionByUid(state.collections, action.payload.collectionUid);
|
const collection = findCollectionByUid(state.collections, action.payload.collectionUid);
|
||||||
|
|
||||||
@ -1682,7 +1665,6 @@ export const {
|
|||||||
addMultipartFormParam,
|
addMultipartFormParam,
|
||||||
updateMultipartFormParam,
|
updateMultipartFormParam,
|
||||||
deleteMultipartFormParam,
|
deleteMultipartFormParam,
|
||||||
updateRawFile,
|
|
||||||
updateRequestAuthMode,
|
updateRequestAuthMode,
|
||||||
updateRequestBodyMode,
|
updateRequestBodyMode,
|
||||||
updateRequestBody,
|
updateRequestBody,
|
||||||
|
@ -83,7 +83,8 @@ const requestBodySchema = Yup.object({
|
|||||||
sparql: Yup.string().nullable(),
|
sparql: Yup.string().nullable(),
|
||||||
formUrlEncoded: Yup.array().of(keyValueSchema).nullable(),
|
formUrlEncoded: Yup.array().of(keyValueSchema).nullable(),
|
||||||
multipartForm: Yup.array().of(multipartFormSchema).nullable(),
|
multipartForm: Yup.array().of(multipartFormSchema).nullable(),
|
||||||
graphql: graphqlBodySchema.nullable()
|
graphql: graphqlBodySchema.nullable(),
|
||||||
|
rawFile: Yup.string().nullable(),
|
||||||
})
|
})
|
||||||
.noUnknown(true)
|
.noUnknown(true)
|
||||||
.strict();
|
.strict();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user