mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-28 23:24:05 +00:00
fix: imports for ws files
This commit is contained in:
@@ -60,49 +60,6 @@ const SingleWSMessage = ({
|
||||
};
|
||||
const onSave = () => dispatch(saveRequest(item.uid, collection.uid));
|
||||
|
||||
const onRegenerateMessage = async () => {
|
||||
try {
|
||||
const methodPath = item.draft?.request?.method || item.request?.method;
|
||||
|
||||
if (!methodPath) {
|
||||
toastError(new Error('Method path not found in request'));
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the method metadata from the appropriate cache
|
||||
let methodMetadata = null;
|
||||
|
||||
const result = await generateGrpcSampleMessage(methodPath, content, {
|
||||
arraySize: 2,
|
||||
methodMetadata // Pass the method metadata to the function
|
||||
});
|
||||
|
||||
if (result.success) {
|
||||
const currentMessages = [...(body.ws || [])];
|
||||
|
||||
currentMessages[index] = {
|
||||
name: name ? name : `message ${index + 1}`,
|
||||
content: result.message
|
||||
};
|
||||
|
||||
dispatch(
|
||||
updateRequestBody({
|
||||
content: currentMessages,
|
||||
itemUid: item.uid,
|
||||
collectionUid: collection.uid
|
||||
})
|
||||
);
|
||||
|
||||
toast.success('Sample message generated successfully!');
|
||||
} else {
|
||||
toastError(new Error(result.error || 'Failed to generate sample message'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error generating sample message:', error);
|
||||
toastError(error);
|
||||
}
|
||||
};
|
||||
|
||||
const onDeleteMessage = () => {
|
||||
const currentMessages = [...(body.ws || [])];
|
||||
|
||||
@@ -168,38 +125,6 @@ const SingleWSMessage = ({
|
||||
</button>
|
||||
</ToolHint>
|
||||
|
||||
<ToolHint text="Generate a new sample message based on schema" toolhintId={`regenerate-msg-${index}`}>
|
||||
<button
|
||||
onClick={onRegenerateMessage}
|
||||
className="p-1 rounded hover:bg-zinc-200 dark:hover:bg-zinc-600 transition-colors"
|
||||
>
|
||||
<IconRefresh size={16} strokeWidth={1.5} className="text-zinc-700 dark:text-zinc-300" />
|
||||
</button>
|
||||
</ToolHint>
|
||||
|
||||
{canClientStream && (
|
||||
<ToolHint
|
||||
text={isConnectionActive ? 'Send WS message' : 'Connection not active'}
|
||||
toolhintId={`send-msg-${index}`}
|
||||
>
|
||||
<button
|
||||
onClick={onSend}
|
||||
disabled={!isConnectionActive}
|
||||
className={`p-1 rounded ${
|
||||
isConnectionActive ? 'hover:bg-zinc-200 dark:hover:bg-zinc-600' : 'opacity-50 cursor-not-allowed'
|
||||
} transition-colors`}
|
||||
>
|
||||
<IconSend
|
||||
size={16}
|
||||
strokeWidth={1.5}
|
||||
className={`${
|
||||
isConnectionActive ? 'text-zinc-700 dark:text-zinc-300' : 'text-zinc-400 dark:text-zinc-500'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
</ToolHint>
|
||||
)}
|
||||
|
||||
{index > 0 && (
|
||||
<ToolHint text="Delete this message" toolhintId={`delete-msg-${index}`}>
|
||||
<button
|
||||
|
||||
@@ -261,7 +261,8 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
|
||||
formUrlEncoded: copyFormUrlEncodedParams(si.request.body.formUrlEncoded),
|
||||
multipartForm: copyMultipartFormParams(si.request.body.multipartForm),
|
||||
file: copyFileParams(si.request.body.file),
|
||||
grpc: si.request.body.grpc
|
||||
grpc: si.request.body.grpc,
|
||||
ws: si.request.body.ws
|
||||
},
|
||||
script: si.request.script,
|
||||
vars: si.request.vars,
|
||||
@@ -423,6 +424,13 @@ export const transformCollectionToSaveToExportAsFile = (collection, options = {}
|
||||
content: replaceTabsWithSpaces(content)
|
||||
}));
|
||||
}
|
||||
|
||||
if (di.request.body.mode === 'ws') {
|
||||
di.request.body.ws = di.request.body.ws.map(({ name, content }, index) => ({
|
||||
name: name ? name : `message ${index + 1}`,
|
||||
content: replaceTabsWithSpaces(content)
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (si.type == 'folder' && si?.root) {
|
||||
@@ -658,7 +666,7 @@ export const transformRequestToSaveToFilesystem = (item) => {
|
||||
if (itemToSave.request.body.mode === 'ws') {
|
||||
itemToSave.request.body = {
|
||||
...itemToSave.request.body,
|
||||
grpc: itemToSave.request.body.ws.map(({ name, content }, index) => ({
|
||||
ws: itemToSave.request.body.ws.map(({ name, content }, index) => ({
|
||||
name: name ? name : `message ${index + 1}`,
|
||||
content: replaceTabsWithSpaces(content)
|
||||
}))
|
||||
|
||||
@@ -62,9 +62,10 @@ export const updateUidsInCollection = (_collection) => {
|
||||
export const transformItemsInCollection = (collection) => {
|
||||
const transformItems = (items = []) => {
|
||||
each(items, (item) => {
|
||||
if (['http', 'graphql', 'grpc'].includes(item.type)) {
|
||||
if (['http', 'graphql', 'grpc', 'ws'].includes(item.type)) {
|
||||
item.type = `${item.type}-request`;
|
||||
const isGrpcRequest = item.type === 'grpc-request';
|
||||
const isWSRequest = item.type === 'ws-request';
|
||||
|
||||
if (item.request.query) {
|
||||
item.request.params = item.request.query.map((queryItem) => ({
|
||||
@@ -77,6 +78,11 @@ export const transformItemsInCollection = (collection) => {
|
||||
if (isGrpcRequest) {
|
||||
delete item.request.params;
|
||||
}
|
||||
|
||||
if (isWSRequest) {
|
||||
delete item.request.params;
|
||||
delete item.request.method;
|
||||
}
|
||||
|
||||
delete item.request.query;
|
||||
|
||||
@@ -100,7 +106,6 @@ export const transformItemsInCollection = (collection) => {
|
||||
};
|
||||
|
||||
transformItems(collection.items);
|
||||
|
||||
return collection;
|
||||
};
|
||||
|
||||
|
||||
@@ -601,7 +601,7 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
// Recursive function to parse the collection items and create files/folders
|
||||
const parseCollectionItems = (items = [], currentPath) => {
|
||||
items.forEach(async (item) => {
|
||||
if (['http-request', 'graphql-request', 'grpc-request'].includes(item.type)) {
|
||||
if (['http-request', 'graphql-request', 'grpc-request', 'ws-request'].includes(item.type)) {
|
||||
let sanitizedFilename = sanitizeName(item?.filename || `${item.name}.bru`);
|
||||
const content = await stringifyRequestViaWorker(item);
|
||||
const filePath = path.join(currentPath, sanitizedFilename);
|
||||
|
||||
@@ -81,7 +81,7 @@ export const bruRequestToJson = (data: string | any, parsed: boolean = false): a
|
||||
transformedJson.request.auth.mode = _.get(json, 'ws.auth', 'none');
|
||||
transformedJson.request.body = _.get(json, 'body', {
|
||||
mode: 'ws',
|
||||
grpc: _.get(json, 'body.ws', [
|
||||
ws: _.get(json, 'body.ws', [
|
||||
{
|
||||
name: 'message 1',
|
||||
content: '{}'
|
||||
|
||||
Reference in New Issue
Block a user