mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-22 20:25:38 +00:00
Add tag filtering to collection runner
This commit is contained in:
@@ -9,6 +9,7 @@ import { IconRefresh, IconCircleCheck, IconCircleX, IconCircleOff, IconCheck, Ic
|
||||
import ResponsePane from './ResponsePane';
|
||||
import StyledWrapper from './StyledWrapper';
|
||||
import { areItemsLoading } from 'utils/collections';
|
||||
import TagList from 'components/RequestPane/Tags/TagList/TagList';
|
||||
|
||||
const getDisplayName = (fullPath, pathname, name = '') => {
|
||||
let relativePath = path.relative(fullPath, pathname);
|
||||
@@ -42,6 +43,8 @@ export default function RunnerResults({ collection }) {
|
||||
const dispatch = useDispatch();
|
||||
const [selectedItem, setSelectedItem] = useState(null);
|
||||
const [delay, setDelay] = useState(null);
|
||||
const [tags, setTags] = useState({ include: [], exclude: [] });
|
||||
const [tagsEnabled, setTagsEnabled] = useState(false);
|
||||
|
||||
// ref for the runner output body
|
||||
const runnerBodyRef = useRef();
|
||||
@@ -88,11 +91,19 @@ export default function RunnerResults({ collection }) {
|
||||
.filter(Boolean);
|
||||
|
||||
const runCollection = () => {
|
||||
dispatch(runCollectionFolder(collection.uid, null, true, Number(delay)));
|
||||
dispatch(runCollectionFolder(collection.uid, null, true, Number(delay), tagsEnabled && tags));
|
||||
};
|
||||
|
||||
const runAgain = () => {
|
||||
dispatch(runCollectionFolder(collection.uid, runnerInfo.folderUid, runnerInfo.isRecursive, Number(delay)));
|
||||
dispatch(
|
||||
runCollectionFolder(
|
||||
collection.uid,
|
||||
runnerInfo.folderUid,
|
||||
runnerInfo.isRecursive,
|
||||
Number(delay),
|
||||
tagsEnabled && tags
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const resetRunner = () => {
|
||||
@@ -140,6 +151,37 @@ export default function RunnerResults({ collection }) {
|
||||
onChange={(e) => setDelay(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-6 flex flex-col">
|
||||
<div className="flex gap-2">
|
||||
<label className="block font-medium">Filter requests with tags</label>
|
||||
<input
|
||||
className="cursor-pointer"
|
||||
type="checkbox"
|
||||
checked={tagsEnabled}
|
||||
onChange={() => setTagsEnabled(!tagsEnabled)}
|
||||
/>
|
||||
</div>
|
||||
{tagsEnabled && (
|
||||
<div className="flex p-4 gap-4 max-w-xl justify-between">
|
||||
<div className="w-1/2">
|
||||
<span>Included tags:</span>
|
||||
<TagList
|
||||
tags={tags.include}
|
||||
onTagAdd={(tag) => setTags({ ...tags, include: [...tags.include, tag] })}
|
||||
onTagRemove={(tag) => setTags({ ...tags, include: tags.include.filter((t) => t !== tag) })}
|
||||
/>
|
||||
</div>
|
||||
<div className="w-1/2">
|
||||
<span>Excluded tags:</span>
|
||||
<TagList
|
||||
tags={tags.exclude}
|
||||
onTagAdd={(tag) => setTags({ ...tags, exclude: [...tags.exclude, tag] })}
|
||||
onTagRemove={(tag) => setTags({ ...tags, exclude: tags.exclude.filter((t) => t !== tag) })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<button type="submit" className="submit btn btn-sm btn-secondary mt-6" onClick={runCollection}>
|
||||
Run Collection
|
||||
|
||||
@@ -315,7 +315,7 @@ export const cancelRunnerExecution = (cancelTokenUid) => (dispatch) => {
|
||||
cancelNetworkRequest(cancelTokenUid).catch((err) => console.log(err));
|
||||
};
|
||||
|
||||
export const runCollectionFolder = (collectionUid, folderUid, recursive, delay) => (dispatch, getState) => {
|
||||
export const runCollectionFolder = (collectionUid, folderUid, recursive, delay, tags) => (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const { globalEnvironments, activeGlobalEnvironmentUid } = state.globalEnvironments;
|
||||
const collection = findCollectionByUid(state.collections.collections, collectionUid);
|
||||
@@ -354,7 +354,8 @@ export const runCollectionFolder = (collectionUid, folderUid, recursive, delay)
|
||||
environment,
|
||||
collectionCopy.runtimeVariables,
|
||||
recursive,
|
||||
delay
|
||||
delay,
|
||||
tags
|
||||
)
|
||||
.then(resolve)
|
||||
.catch((err) => {
|
||||
|
||||
@@ -30,6 +30,7 @@ const { preferencesUtil } = require('../../store/preferences');
|
||||
const { getProcessEnvVars } = require('../../store/process-env');
|
||||
const { getBrunoConfig } = require('../../store/bruno-config');
|
||||
const Oauth2Store = require('../../store/oauth2');
|
||||
const { isRequestTagsIncluded } = require('@usebruno/common');
|
||||
|
||||
const saveCookies = (url, headers) => {
|
||||
if (preferencesUtil.shouldStoreCookies()) {
|
||||
@@ -935,7 +936,7 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
|
||||
ipcMain.handle(
|
||||
'renderer:run-collection-folder',
|
||||
async (event, folder, collection, environment, runtimeVariables, recursive, delay) => {
|
||||
async (event, folder, collection, environment, runtimeVariables, recursive, delay, tags) => {
|
||||
const collectionUid = collection.uid;
|
||||
const collectionPath = collection.pathname;
|
||||
const folderUid = folder ? folder.uid : null;
|
||||
@@ -996,6 +997,15 @@ const registerNetworkIpc = (mainWindow) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Filter requests based on tags
|
||||
if (tags && tags.include && tags.exclude) {
|
||||
const includeTags = tags.include ? tags.include : [];
|
||||
const excludeTags = tags.exclude ? tags.exclude : [];
|
||||
folderRequests = folderRequests.filter(({ request }) => {
|
||||
return isRequestTagsIncluded(request.tags, includeTags, excludeTags)
|
||||
});
|
||||
}
|
||||
|
||||
let currentRequestIndex = 0;
|
||||
let nJumps = 0; // count the number of jumps to avoid infinite loops
|
||||
while (currentRequestIndex < folderRequests.length) {
|
||||
|
||||
Reference in New Issue
Block a user