mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 06:28:33 +00:00
* fix: 3296 Folder-level No Auth inheritance is ignored; requests still use Collection Auth
114 lines
4.3 KiB
JavaScript
114 lines
4.3 KiB
JavaScript
import React, { useMemo } from 'react';
|
|
import classnames from 'classnames';
|
|
import { updatedFolderSettingsSelectedTab } from 'providers/ReduxStore/slices/collections';
|
|
import { useDispatch } from 'react-redux';
|
|
import Headers from './Headers';
|
|
import Script from './Script';
|
|
import Tests from './Tests';
|
|
import StyledWrapper from './StyledWrapper';
|
|
import Vars from './Vars';
|
|
import Documentation from './Documentation';
|
|
import Auth from './Auth';
|
|
import StatusDot from 'components/StatusDot';
|
|
import { hasEffectiveAuth } from 'utils/auth';
|
|
|
|
const FolderSettings = ({ collection, folder }) => {
|
|
const dispatch = useDispatch();
|
|
let tab = 'headers';
|
|
const { folderLevelSettingsSelectedTab } = collection;
|
|
if (folderLevelSettingsSelectedTab?.[folder?.uid]) {
|
|
tab = folderLevelSettingsSelectedTab[folder?.uid];
|
|
}
|
|
|
|
const folderRoot = folder?.draft || folder?.root;
|
|
const hasScripts = folderRoot?.request?.script?.res || folderRoot?.request?.script?.req;
|
|
const hasTests = folderRoot?.request?.tests;
|
|
|
|
const headers = folderRoot?.request?.headers || [];
|
|
const activeHeadersCount = headers.filter((header) => header.enabled).length;
|
|
|
|
const requestVars = folderRoot?.request?.vars?.req || [];
|
|
const responseVars = folderRoot?.request?.vars?.res || [];
|
|
const activeVarsCount = requestVars.filter((v) => v.enabled).length + responseVars.filter((v) => v.enabled).length;
|
|
|
|
const folderAuthMode = folder?.draft?.request?.auth?.mode ?? folder?.root?.request?.auth?.mode;
|
|
const hasAuth = useMemo(
|
|
() => hasEffectiveAuth(collection, folder),
|
|
[folder, folderAuthMode, collection]
|
|
);
|
|
|
|
const setTab = (tab) => {
|
|
dispatch(
|
|
updatedFolderSettingsSelectedTab({
|
|
collectionUid: collection?.uid,
|
|
folderUid: folder?.uid,
|
|
tab
|
|
})
|
|
);
|
|
};
|
|
|
|
const getTabPanel = (tab) => {
|
|
switch (tab) {
|
|
case 'headers': {
|
|
return <Headers collection={collection} folder={folder} />;
|
|
}
|
|
case 'script': {
|
|
return <Script collection={collection} folder={folder} />;
|
|
}
|
|
case 'test': {
|
|
return <Tests collection={collection} folder={folder} />;
|
|
}
|
|
case 'vars': {
|
|
return <Vars collection={collection} folder={folder} />;
|
|
}
|
|
case 'auth': {
|
|
return <Auth collection={collection} folder={folder} />;
|
|
}
|
|
case 'docs': {
|
|
return <Documentation collection={collection} folder={folder} />;
|
|
}
|
|
}
|
|
};
|
|
|
|
const getTabClassname = (tabName) => {
|
|
return classnames(`tab select-none ${tabName}`, {
|
|
active: tabName === tab
|
|
});
|
|
};
|
|
|
|
return (
|
|
<StyledWrapper className="flex flex-col h-full overflow-auto">
|
|
<div className="flex flex-col h-full relative px-4 py-4">
|
|
<div className="flex flex-wrap items-center tabs" role="tablist">
|
|
<div className={getTabClassname('headers')} role="tab" data-testid="folder-settings-tab-headers" onClick={() => setTab('headers')}>
|
|
Headers
|
|
{activeHeadersCount > 0 && <sup className="ml-1 font-medium">{activeHeadersCount}</sup>}
|
|
</div>
|
|
<div className={getTabClassname('script')} role="tab" data-testid="folder-settings-tab-script" onClick={() => setTab('script')}>
|
|
Script
|
|
{hasScripts && <StatusDot />}
|
|
</div>
|
|
<div className={getTabClassname('test')} role="tab" data-testid="folder-settings-tab-test" onClick={() => setTab('test')}>
|
|
Test
|
|
{hasTests && <StatusDot />}
|
|
</div>
|
|
<div className={getTabClassname('vars')} role="tab" data-testid="folder-settings-tab-vars" onClick={() => setTab('vars')}>
|
|
Vars
|
|
{activeVarsCount > 0 && <sup className="ml-1 font-medium">{activeVarsCount}</sup>}
|
|
</div>
|
|
<div className={getTabClassname('auth')} role="tab" data-testid="folder-settings-tab-auth" onClick={() => setTab('auth')}>
|
|
Auth
|
|
{hasAuth && <StatusDot dataTestId="auth" />}
|
|
</div>
|
|
<div className={getTabClassname('docs')} role="tab" data-testid="folder-settings-tab-docs" onClick={() => setTab('docs')}>
|
|
Docs
|
|
</div>
|
|
</div>
|
|
<section className="folder-settings-content flex mt-4 h-full overflow-auto">{getTabPanel(tab)}</section>
|
|
</div>
|
|
</StyledWrapper>
|
|
);
|
|
};
|
|
|
|
export default FolderSettings;
|