Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,40 +69,11 @@ const StyledWrapper = styled.div`
flex-shrink: 0;
}

.input-wrap {
position: relative;

.textbox {
padding-right: 2.25rem;
color: ${(props) => props.theme.text};
font-weight: 400;
font-size: ${(props) => props.theme.font.size.sm};
line-height: 20px;
}

.copy-btn {
position: absolute;
top: 50%;
right: 0.5rem;
transform: translateY(-50%);
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.25rem;
background: transparent;
border: none;
cursor: pointer;
color: ${(props) => props.theme.colors.text.muted};

&:hover:not(:disabled) {
color: ${(props) => props.theme.text};
}

&:disabled {
opacity: 0.5;
cursor: default;
}
}
.new-version-input {
color: ${(props) => props.theme.text};
font-weight: 400;
font-size: ${(props) => props.theme.font.size.sm};
line-height: 20px;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { IconArrowRight, IconCopy, IconCheck, IconAlertTriangle } from '@tabler/icons';
import { IconArrowRight, IconAlertTriangle } from '@tabler/icons';

import Modal from 'components/Modal';
import Portal from 'components/Portal';
Expand Down Expand Up @@ -30,14 +30,12 @@ const ChangeCollectionVersion = ({ collectionUid, onClose }) => {
const isYml = isOpenCollectionFormat(collection);
const targetKey = isYml ? 'info.version' : 'collectionVersion';
const targetFile = isYml ? 'opencollection.yml' : 'bruno.json';
const [newVersion, setNewVersion] = useState(currentVersion);
const [newVersion, setNewVersion] = useState('');
const [isSaving, setIsSaving] = useState(false);
const [copied, setCopied] = useState(false);

useEffect(() => {
if (inputRef.current) {
inputRef.current.focus();
inputRef.current.select();
}
}, []);

Expand All @@ -55,15 +53,6 @@ const ChangeCollectionVersion = ({ collectionUid, onClose }) => {
.catch(() => setIsSaving(false));
};

const handleCopy = () => {
if (!trimmedVersion || !navigator.clipboard) return;
navigator.clipboard.writeText(trimmedVersion)
.then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 1500);
}).catch(() => {});
};

if (!collection) {
return <CollectionNotFound onClose={onClose} />;
}
Expand Down Expand Up @@ -98,32 +87,20 @@ const ChangeCollectionVersion = ({ collectionUid, onClose }) => {

<div className="version-col">
<div className="col-label">New Version</div>
<div className="input-wrap">
<input
ref={inputRef}
type="text"
className="textbox w-full"
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
spellCheck="false"
placeholder="e.g. v1.0.0"
maxLength={50}
value={newVersion}
onChange={(e) => setNewVersion(e.target.value)}
data-testid="change-version-input"
/>
<button
type="button"
className="copy-btn"
aria-label={copied ? 'Copied' : 'Copy version'}
onClick={handleCopy}
disabled={!trimmedVersion}
data-testid="change-version-copy"
>
{copied ? <IconCheck size={15} stroke={1.5} /> : <IconCopy size={15} stroke={1.5} />}
</button>
</div>
<input
ref={inputRef}
type="text"
className="textbox w-full new-version-input"
autoComplete="off"
autoCorrect="off"
autoCapitalize="off"
spellCheck="false"
placeholder="e.g. v1.0.0"
maxLength={50}
value={newVersion}
onChange={(e) => setNewVersion(e.target.value)}
data-testid="change-version-input"
/>
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ beforeEach(() => {
});

describe('ChangeCollectionVersion', () => {
it('opens with an empty new-version input, even when the collection already has a version', () => {
renderModal(buildCollection());
expect(screen.getByTestId('change-version-input')).toHaveValue('');
expect(screen.getByTestId('change-version-submit-btn')).toBeDisabled();
});

it('lets you save only when the new version is different from the current one', () => {
renderModal(buildCollection());
const submit = screen.getByTestId('change-version-submit-btn');
Expand Down
2 changes: 1 addition & 1 deletion tests/collection/change-version/change-version.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test.describe('Change Collection Version (yml collection)', () => {
await test.step('open the Change Collection Version modal', async () => {
await page.getByTestId('info-version-change').click();
await expect(page.getByTestId('change-version-current')).toHaveText('1.0.0');
await expect(page.getByTestId('change-version-input')).toHaveValue('1.0.0');
await expect(page.getByTestId('change-version-input')).toHaveValue('');
});

await test.step('the Update button stays off until the version is changed', async () => {
Expand Down
Loading