Skip to content

Commit

Permalink
chore: remove duplication and Auth mode naming discrepancies
Browse files Browse the repository at this point in the history
  • Loading branch information
pietrygamat committed Aug 29, 2024
1 parent 93080de commit e4e5e9f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const AuthMode = ({ collection }) => {
const onDropdownCreate = (ref) => (dropdownTippyRef.current = ref);
const authMode = get(collection, 'root.request.auth.mode');

const authModes = ['awsv4', 'basic', 'bearer', 'digest', 'oauth2', 'none'];

const Icon = forwardRef((props, ref) => {
return (
<div ref={ref} className="flex items-center justify-center auth-mode-label select-none">
Expand All @@ -34,60 +36,21 @@ const AuthMode = ({ collection }) => {
<StyledWrapper>
<div className="inline-flex items-center cursor-pointer auth-mode-selector">
<Dropdown onCreate={onDropdownCreate} icon={<Icon />} placement="bottom-end">
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
onModeChange('awsv4');
}}
>
AWS Sig v4
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
onModeChange('basic');
}}
>
Basic Auth
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
onModeChange('bearer');
}}
>
Bearer Token
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
onModeChange('digest');
}}
>
Digest Auth
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
onModeChange('oauth2');
}}
>
Oauth2
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
onModeChange('none');
}}
>
No Auth
</div>
{authModes.map((mode) => {
return (
<>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef.current.hide();
onModeChange(mode);
}}
>
{humanizeRequestAuthMode(mode)}
</div>
</>
);
})}
</Dropdown>
</div>
</StyledWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const AuthMode = ({ item, collection }) => {
const onDropdownCreate = (ref) => (dropdownTippyRef.current = ref);
const authMode = item.draft ? get(item, 'draft.request.auth.mode') : get(item, 'request.auth.mode');

const authModes = ['awsv4', 'basic', 'bearer', 'digest', 'oauth2', 'inherit', 'none'];

const Icon = forwardRef((props, ref) => {
return (
<div ref={ref} className="flex items-center justify-center auth-mode-label select-none">
Expand All @@ -35,69 +37,21 @@ const AuthMode = ({ item, collection }) => {
<StyledWrapper>
<div className="inline-flex items-center cursor-pointer auth-mode-selector">
<Dropdown onCreate={onDropdownCreate} icon={<Icon />} placement="bottom-end">
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef?.current?.hide();
onModeChange('awsv4');
}}
>
AWS Sig v4
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef?.current?.hide();
onModeChange('basic');
}}
>
Basic Auth
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef?.current?.hide();
onModeChange('bearer');
}}
>
Bearer Token
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef?.current?.hide();
onModeChange('digest');
}}
>
Digest Auth
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef?.current?.hide();
onModeChange('oauth2');
}}
>
OAuth 2.0
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef?.current?.hide();
onModeChange('inherit');
}}
>
Inherit
</div>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef?.current?.hide();
onModeChange('none');
}}
>
No Auth
</div>
{authModes.map((mode) => {
return (
<>
<div
className="dropdown-item"
onClick={() => {
dropdownTippyRef?.current?.hide();
onModeChange(mode);
}}
>
{humanizeRequestAuthMode(mode)}
</div>
</>
);
})}
</Dropdown>
</div>
</StyledWrapper>
Expand Down

0 comments on commit e4e5e9f

Please sign in to comment.