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
@@ -1,25 +1,8 @@
import React, { memo } from 'react';
import { ResolutionButton } from '../ReviewStep/StyledWrapper';
import { RESOLUTION_TYPES, RESOLUTION_LABELS, RESOLUTION_SHORT_LABELS } from '../utils';

const RESOLUTION_OPTIONS = [
{
value: RESOLUTION_TYPES.COPY,
label: RESOLUTION_LABELS[RESOLUTION_TYPES.COPY],
shortLabel: RESOLUTION_SHORT_LABELS[RESOLUTION_TYPES.COPY],
testId: 'env-import-copy-btn'
},
{
value: RESOLUTION_TYPES.REPLACE,
label: RESOLUTION_LABELS[RESOLUTION_TYPES.REPLACE],
shortLabel: RESOLUTION_SHORT_LABELS[RESOLUTION_TYPES.REPLACE],
testId: 'env-import-replace-btn'
}
];
import { RESOLUTION_OPTIONS } from '../utils';

const EnvironmentRow = ({ env, isSelected, resolution, toggleItemSelection, setItemResolution, showResolutions }) => {
const sourceFile = env.filePath || env.fileName;

return (
<div className="env-item" data-testid="env-import-item">
<label className="env-item-label">
Expand All @@ -31,12 +14,12 @@ const EnvironmentRow = ({ env, isSelected, resolution, toggleItemSelection, setI
data-testid="env-import-item-checkbox"
/>
<div className="env-item-content">
<div className="env-name" title={sourceFile}>{env.name}</div>
<div className="env-name" title={env.name}>{env.name}</div>
</div>
</label>
{showResolutions && (
<div className="env-actions">
{RESOLUTION_OPTIONS.map(({ value, label, shortLabel, testId }) => {
{RESOLUTION_OPTIONS.map(({ value, label, title, testId }) => {
const selected = resolution === value;

return (
Expand All @@ -45,10 +28,10 @@ const EnvironmentRow = ({ env, isSelected, resolution, toggleItemSelection, setI
$selected={selected}
aria-pressed={selected}
onClick={() => setItemResolution(env.id, value)}
title={label}
title={title}
data-testid={testId}
>
{shortLabel}
{label}
</ResolutionButton>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const InvalidEnvironmentGroup = ({ invalid, isExpanded, toggleExpanded }) => {
{invalid.map((item, idx) => (
<div key={`${item.fileName}-${idx}`} className="env-import-invalid-item" data-testid="env-import-invalid-item">
<div className="env-item-content">
<div className="env-name">{item.fileName}</div>
<div className="env-name" title={item.fileName}>{item.fileName}</div>
<div className="env-error">{item.error}</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export const StyledWrapper = styled.div`
.modal-content {
display: flex;
flex-direction: column;
width: 498px;
max-width: 100%;
height: 450px;
max-height: calc(100vh - 180px);
overflow: hidden;
Expand Down Expand Up @@ -229,13 +231,19 @@ export const StyledWrapper = styled.div`
font-weight: 400;
font-size: ${(props) => props.theme.font.size.base};
line-height: 1.5;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.env-error {
font-size: ${(props) => props.theme.font.size.xs};
font-weight: 400;
color: ${(props) => props.theme.colors.text.danger};
margin-top: 2px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}

.env-actions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const useEnvironmentImport = (type, collection, onClose, onEnvironmentCre
const isDuplicate = environment.status === ENV_STATUS.DUPLICATE;

if (isDuplicate) {
const resolution = itemResolutions.get(environment.id) || RESOLUTION_TYPES.COPY;
const resolution = itemResolutions.get(environment.id) || RESOLUTION_TYPES.CREATE_NEW;
const normalizedName = normalizeEnvName(environment.name);
if (resolution === RESOLUTION_TYPES.REPLACE && !replacedNames.has(normalizedName)) {
const existingEnv = getExistingEnv(environment.name);
Expand Down Expand Up @@ -125,7 +125,7 @@ export const useEnvironmentImport = (type, collection, onClose, onEnvironmentCre
const initialResolutions = new Map();
validItems
.filter((item) => item.status === ENV_STATUS.DUPLICATE)
.forEach((item) => initialResolutions.set(item.id, RESOLUTION_TYPES.COPY));
.forEach((item) => initialResolutions.set(item.id, RESOLUTION_TYPES.CREATE_NEW));
setResolutions(initialResolutions);

setStep(IMPORT_STEPS.REVIEW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@ export const detectEnvironmentFormat = (data) => {
};

export const RESOLUTION_TYPES = {
CUSTOM: 'custom',
COPY: 'copy',
CREATE_NEW: 'create_new',
REPLACE: 'replace'
};

export const RESOLUTION_SHORT_LABELS = {
[RESOLUTION_TYPES.COPY]: 'Clone',
[RESOLUTION_TYPES.REPLACE]: 'Replace'
};

export const RESOLUTION_LABELS = {
[RESOLUTION_TYPES.CUSTOM]: 'Custom',
[RESOLUTION_TYPES.COPY]: 'Import as clone',
[RESOLUTION_TYPES.REPLACE]: 'Replace existing'
};
export const RESOLUTION_OPTIONS = [
{ value: RESOLUTION_TYPES.CREATE_NEW, label: 'New', title: 'Import as a new environment', testId: 'env-import-create-new-btn' },
{ value: RESOLUTION_TYPES.REPLACE, label: 'Replace', title: 'Replace existing', testId: 'env-import-replace-btn' }
];
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ test.describe('Import environment - name conflict handling', () => {
await test.step('Copy is the default resolution and can be switched to Replace', async () => {
const item = environment.importReviewItem('Production');
await expect(item).toBeVisible();
await expect(environment.importCopyButton('Production')).toHaveAttribute('aria-pressed', 'true');
await expect(environment.importCreateNewButton('Production')).toHaveAttribute('aria-pressed', 'true');
await expect(environment.importReplaceButton('Production')).toHaveAttribute('aria-pressed', 'false');

await environment.importReplaceButton('Production').click();

await expect(environment.importReplaceButton('Production')).toHaveAttribute('aria-pressed', 'true');
await expect(environment.importCopyButton('Production')).toHaveAttribute('aria-pressed', 'false');
await expect(environment.importCreateNewButton('Production')).toHaveAttribute('aria-pressed', 'false');
});

await modal.closeButton().click();
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/page/environments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export const buildEnvironmentLocators = (page: Page) => ({
importSelectedCount: () => page.getByTestId('env-import-selected-count'),
importReviewItem: (name: string) => page.getByTestId('env-import-item').filter({ has: page.getByText(name, { exact: true }) }),
importItemCheckbox: (name: string) => buildEnvironmentLocators(page).importReviewItem(name).getByTestId('env-import-item-checkbox'),
importCopyButton: (name: string) => buildEnvironmentLocators(page).importReviewItem(name).getByTestId('env-import-copy-btn'),
importCreateNewButton: (name: string) => buildEnvironmentLocators(page).importReviewItem(name).getByTestId('env-import-create-new-btn'),
importReplaceButton: (name: string) => buildEnvironmentLocators(page).importReviewItem(name).getByTestId('env-import-replace-btn'),
importReviewItemNames: () => page.getByTestId('env-import-item').locator('.env-name'),
importInvalidGroup: () => page.getByTestId('env-import-invalid-group'),
Expand Down
Loading