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 @@ -39,6 +39,15 @@ const StyledWrapper = styled.div`
}
}

&.version {
background-color: ${(props) => rgba(props.theme.colors.text.yellow, 0.1)};
border: 1px solid ${(props) => rgba(props.theme.colors.text.yellow, 0.1)};

svg {
color: ${(props) => props.theme.colors.text.yellow};
}
}

&.generate-docs {
background-color: ${(props) => rgba(props.theme.accents.primary, 0.08)};
border: 1px solid ${(props) => rgba(props.theme.accents.primary, 0.09)};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { getTotalRequestCountInCollection } from 'utils/collections/';
import { IconFolder, IconWorld, IconApi, IconShare, IconBook } from '@tabler/icons';
import { areItemsLoading, getItemsLoadStats } from 'utils/collections/index';
import { IconFolder, IconWorld, IconApi, IconShare, IconBook, IconTag } from '@tabler/icons';
import { areItemsLoading, getItemsLoadStats, getCollectionVersion } from 'utils/collections/index';
import { useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import ShareCollection from 'components/ShareCollection/index';
import GenerateDocumentation from 'components/Sidebar/Collections/Collection/GenerateDocumentation';
import ChangeCollectionVersion from 'components/Sidebar/Collections/Collection/ChangeCollectionVersion';
import { addTab } from 'providers/ReduxStore/slices/tabs';
import StyledWrapper from './StyledWrapper';
import Migration from '../Migration';
Expand All @@ -18,6 +19,9 @@ const Info = ({ collection }) => {
const { loading: itemsLoadingCount, total: totalItems } = getItemsLoadStats(collection);
const [showShareCollectionModal, toggleShowShareCollectionModal] = useState(false);
const [showGenerateDocumentationModal, setShowGenerateDocumentationModal] = useState(false);
const [showChangeVersionModal, setShowChangeVersionModal] = useState(false);

const collectionVersion = getCollectionVersion(collection);
Comment thread
sachin-bruno marked this conversation as resolved.
Resolved

const globalEnvironments = useSelector((state) => state.globalEnvironments.globalEnvironments);

Expand Down Expand Up @@ -45,6 +49,22 @@ const Info = ({ collection }) => {
</div>
</div>

<div className="flex items-start group cursor-pointer" onClick={() => setShowChangeVersionModal(true)} data-testid="info-version-row">
<div className="icon-box version flex-shrink-0 p-3 rounded-lg">
<IconTag className="w-5 h-5" stroke={1.5} />
</div>
<div className="ml-4 h-full flex flex-col justify-start">
<div className="font-medium h-fit my-auto">Version</div>
<div className="flex items-center gap-2">
{collectionVersion
? <span className="text-muted" data-testid="info-version-value">{collectionVersion}</span>
: <span className="text-muted italic" data-testid="info-version-value">Not Set</span>}
<span className="group-hover:underline text-link" data-testid="info-version-change">change</span>
</div>
</div>
</div>
{showChangeVersionModal && <ChangeCollectionVersion collectionUid={collection.uid} onClose={() => setShowChangeVersionModal(false)} />}

Comment thread
sachin-bruno marked this conversation as resolved.
Resolved
{/* Environments Row */}
<div className="flex items-start">
<div className="icon-box environments flex-shrink-0 p-3 rounded-lg">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import styled from 'styled-components';

export const ModalTitle = styled.div`
color: ${(props) => props.theme.colors.text.subtext2};
font-weight: 600;
font-size: ${(props) => props.theme.font.size.base};
line-height: 18px;
`;

const StyledWrapper = styled.div`
max-width: 100%;
.subheader {
margin-bottom: 0.5rem;
color: ${(props) => props.theme.colors.text.muted};
font-weight: 400;
font-size: ${(props) => props.theme.font.size.base};
line-height: 18px;

.collection-name {
color: ${(props) => props.theme.text};
font-weight: 600;
}
}

.version-card {
width: 100%;
border: 1px solid ${(props) => props.theme.border.border1};
border-radius: ${(props) => props.theme.border.radius.md};
overflow: hidden;

.version-row {
display: flex;
align-items: flex-start;
gap: 1rem;
padding: 1rem;
}

.version-col {
flex: 1;
min-width: 0;
display: flex;
flex-direction: column;
gap: 0.5rem;
}

.col-label {
color: ${(props) => props.theme.text};
font-weight: 500;
font-size: ${(props) => props.theme.font.size.base};
line-height: 20px;
}

.current-value {
color: ${(props) => props.theme.text};
font-weight: 400;
font-size: ${(props) => props.theme.font.size.sm};
line-height: 20px;
overflow-wrap: anywhere;

.unset {
font-family: inherit;
font-style: italic;
}
}

.arrow {
align-self: center;
color: ${(props) => props.theme.colors.text.muted};
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;
}
}
}
}

.preview {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 0.25rem;
padding: 0.625rem 1rem;
border-top: 1px solid ${(props) => props.theme.border.border1};
background-color: ${(props) => props.theme.background.mantle};
color: ${(props) => props.theme.text};
font-weight: 400;
font-size: ${(props) => props.theme.font.size.sm};
line-height: 20px;

strong {
font-weight: 700;
}

.old {
color: ${(props) => props.theme.colors.text.danger};
font-weight: 700;
word-break: break-all;
}

.new {
font-family: monospace;
color: ${(props) => props.theme.colors.text.green};
font-weight: 700;
word-break: break-all;
}

.preview-arrow {
color: ${(props) => props.theme.colors.text.muted};
flex-shrink: 0;
}
}
`;

export default StyledWrapper;
Comment thread
bijin-bruno marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { IconArrowRight, IconCopy, IconCheck, IconAlertTriangle } from '@tabler/icons';

import Modal from 'components/Modal';
import Portal from 'components/Portal';
import { findCollectionByUid, getCollectionVersion, isOpenCollectionFormat } from 'utils/collections/index';
import { saveCollectionVersion } from 'providers/ReduxStore/slices/collections/actions';
import StyledWrapper, { ModalTitle } from './StyledWrapper';

const CollectionNotFound = ({ onClose }) => (
<Portal>
<Modal size="sm" title="Change Collection Version" confirmText="Close" handleConfirm={onClose} hideCancel>
<StyledWrapper className="w-[480px]">
<div className="flex items-center gap-2 text-warning">
<IconAlertTriangle size={16} className="shrink-0" />
<span>Collection not found. It may have been deleted or is no longer available.</span>
</div>
</StyledWrapper>
</Modal>
</Portal>
);

const ChangeCollectionVersion = ({ collectionUid, onClose }) => {
const dispatch = useDispatch();
const inputRef = useRef(null);
const collection = useSelector((state) => findCollectionByUid(state.collections.collections, collectionUid));

const currentVersion = getCollectionVersion(collection);
const isYml = isOpenCollectionFormat(collection);
const targetKey = isYml ? 'info.version' : 'collectionVersion';
const targetFile = isYml ? 'opencollection.yml' : 'bruno.json';
const [newVersion, setNewVersion] = useState(currentVersion);
const [isSaving, setIsSaving] = useState(false);
const [copied, setCopied] = useState(false);

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

const trimmedVersion = newVersion.trim();
const canSubmit = useMemo(
() => trimmedVersion.length > 0 && trimmedVersion !== currentVersion,
[trimmedVersion, currentVersion]
);

const handleConfirm = () => {
if (!canSubmit || isSaving) return;
setIsSaving(true);
dispatch(saveCollectionVersion(collectionUid, trimmedVersion))
.then(() => onClose())
.catch(() => setIsSaving(false));
Comment thread
sachin-bruno marked this conversation as resolved.
Resolved
};

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} />;
}

return (
<Portal>
<Modal
size="md"
customHeader={<ModalTitle>Change Collection Version</ModalTitle>}
confirmText={isSaving ? 'Updating...' : 'Update Version'}
cancelText="Cancel"
handleConfirm={handleConfirm}
handleCancel={onClose}
confirmDisabled={!canSubmit || isSaving}
dataTestId="change-version"
>
<StyledWrapper className="w-[560px]">
<div className="subheader" data-testid="change-version-collection">
Collection: <span className="collection-name">{collection.name}</span>
</div>

<div className="version-card">
<div className="version-row">
<div className="version-col">
<div className="col-label">Current Version</div>
<div className="current-value" data-testid="change-version-current">
{currentVersion || <span className="unset">Not Set</span>}
</div>
</div>

<IconArrowRight size={18} className="arrow" stroke={1.5} />

<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>
</div>
</div>

<p className="preview m-0" data-testid="change-version-preview">
Updates <strong>{targetKey}</strong> in {targetFile} from{' '}
<span className="old">{currentVersion || '(none)'}</span>
<IconArrowRight size={13} className="preview-arrow" stroke={1.5} />
<span className="new">{trimmedVersion || '…'}</span>
</p>
</div>
</StyledWrapper>
</Modal>
</Portal>
);
};

export default ChangeCollectionVersion;
Loading
Loading