Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [M3-8023] - Refactor Image Upload and Add Tags #10484

Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8a1f473
save progress
bnussman May 16, 2024
df44d35
save progress
bnussman May 16, 2024
995bc14
save progress
bnussman May 16, 2024
e62a9b2
save progress
bnussman May 16, 2024
350003d
upload flow works πŸŽ‰
bnussman May 17, 2024
15c2396
save progress
bnussman May 17, 2024
2e435b1
save progress
bnussman May 17, 2024
646066d
clean up
bnussman May 17, 2024
d5fb153
fix tsc errors
bnussman May 17, 2024
1848229
more progress
bnussman May 17, 2024
49de1c1
re-add redux and analytics
bnussman May 17, 2024
8226ef9
fix e2e tests by clicking submit button
bnussman May 17, 2024
f8d9f3a
add comments
bnussman May 17, 2024
9da1c50
fixes
bnussman May 17, 2024
15b924d
Merge branch 'develop' into M3-8023-image-upload-refactor-and-tags
bnussman May 17, 2024
7011671
add tags
bnussman May 17, 2024
1170b30
Added changeset: Tags to image upload tab
bnussman May 17, 2024
f259223
re-add nicer error messages so UX does not get worse
bnussman May 20, 2024
c2a4cb9
fix small state bug
bnussman May 20, 2024
aff8901
move react query logic
bnussman May 20, 2024
31dbd2f
clean up imports
bnussman May 20, 2024
0f67345
scroll errors into view and disable fields when upload is happening
bnussman May 21, 2024
1dc7d59
all feedback from @mjac0bs except CLI modal changes
bnussman May 22, 2024
56e46ac
clean up the image upload CLI dialog
bnussman May 22, 2024
6a08a0e
Merge branch 'develop' into M3-8023-image-upload-refactor-and-tags
bnussman May 22, 2024
7da9075
Merge branch 'develop' into M3-8023-image-upload-refactor-and-tags
bnussman May 22, 2024
040c0f4
migrate to `Upload Using Command Line`
bnussman May 23, 2024
c991849
Merge branch 'develop' into M3-8023-image-upload-refactor-and-tags
bnussman May 23, 2024
2e1c4f1
move helper text upon UX request
bnussman May 28, 2024
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
7 changes: 6 additions & 1 deletion packages/api-v4/src/images/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import Request, {
setXFilter,
} from '../request';
import { Filter, Params, ResourcePage as Page } from '../types';
import { CreateImagePayload, Image, ImageUploadPayload, UploadImageResponse } from './types';
import {
bnussman-akamai marked this conversation as resolved.
Show resolved Hide resolved
CreateImagePayload,
Image,
ImageUploadPayload,
UploadImageResponse,
} from './types';

/**
* Get information about a single Image.
Expand Down
5 changes: 5 additions & 0 deletions packages/manager/.changeset/pr-10484-added-1715972836354.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Added
---

Tags to image upload tab ([#10484](https://github.com/linode/manager/pull/10484))
abailly-akamai marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ const uploadImage = (label: string) => {
mimeType: 'application/x-gzip',
});
});

cy.intercept('POST', apiMatcher('images/upload')).as('imageUpload');

ui.button.findByAttribute('type', 'submit')
.should('be.enabled')
.should('be.visible')
.click();
};

authenticate();
Expand Down
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved logic out of ImageUpload and into here to clean up ImageUpload as much as possible

bnussman-akamai marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
import { styled } from '@mui/material/styles';
import * as React from 'react';
import { useFormContext } from 'react-hook-form';

import { CopyTooltip } from 'src/components/CopyTooltip/CopyTooltip';
import { Dialog } from 'src/components/Dialog/Dialog';
import { sendCLIClickEvent } from 'src/utilities/analytics/customEventAnalytics';
import { wrapInQuotes } from 'src/utilities/stringUtils';

import type { ImageUploadPayload } from '@linode/api-v4';

export interface ImageUploadSuccessDialogProps {
analyticsKey?: string;
command: string;
isOpen: boolean;
onClose: () => void;
}

export const LinodeCLIModal = React.memo(
bnussman-akamai marked this conversation as resolved.
Show resolved Hide resolved
(props: ImageUploadSuccessDialogProps) => {
const { analyticsKey, command, isOpen, onClose } = props;
const { analyticsKey, isOpen, onClose } = props;

const form = useFormContext<ImageUploadPayload>();

const { label, description, region } = form.getValues();

const cliLabel = formatForCLI(label, 'label');
const cliDescription = formatForCLI(description ?? '', 'description');
const cliRegion = formatForCLI(region, 'region');

const command = `linode-cli image-upload --label ${cliLabel} --description ${cliDescription} --region ${cliRegion} FILE`;
mjac0bs marked this conversation as resolved.
Show resolved Hide resolved

return (
<StyledLinodeCLIModal
Expand Down Expand Up @@ -83,3 +96,7 @@ const StyledCopyTooltip = styled(CopyTooltip, {
},
display: 'flex',
}));

const formatForCLI = (value: string, fallback: string) => {
return value ? wrapInQuotes(value) : `[${fallback.toUpperCase()}]`;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ import type { Meta, StoryObj } from '@storybook/react';
*/
export const _ImageUploader: StoryObj<typeof ImageUploader> = {
args: {
description: 'My Ubuntu Image for Production',
dropzoneDisabled: false,
label: 'file upload',
region: 'us-east-1',
isUploading: false,
progress: undefined,
},
render: (args) => {
return <ImageUploader {...args} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,33 @@ import { renderWithTheme } from 'src/utilities/testHelpers';
import { ImageUploader } from './ImageUploader';

const props = {
apiError: undefined,
dropzoneDisabled: false,
label: 'Upload files here',
onSuccess: vi.fn(),
region: 'us-east-1',
setCancelFn: vi.fn(),
setErrors: vi.fn(),
isUploading: false,
progress: undefined,
};

describe('File Uploader', () => {
it('properly renders the File Uploader', () => {
const screen = renderWithTheme(<ImageUploader {...props} />);

const browseFiles = screen.getByTestId('upload-button');
const browseFiles = screen.getByText('Browse Files').closest('button');
expect(browseFiles).toBeVisible();
expect(browseFiles).toHaveAttribute('aria-disabled', 'false');
expect(browseFiles).toBeEnabled();
const text = screen.getByText(
'You can browse your device to upload an image file or drop it here.'
);
expect(text).toBeVisible();
});

it('disables the dropzone', () => {
const screen = renderWithTheme(
<ImageUploader {...props} dropzoneDisabled={true} />
);
const screen = renderWithTheme(<ImageUploader {...props} disabled />);

const browseFiles = screen.getByTestId('upload-button');
const browseFiles = screen.getByText('Browse Files').closest('button');
expect(browseFiles).toBeVisible();
expect(browseFiles).toBeDisabled();
expect(browseFiles).toHaveAttribute('aria-disabled', 'true');

const text = screen.getByText(
'To upload an image, complete the required fields.'
'You can browse your device to upload an image file or drop it here.'
);
expect(text).toBeVisible();
});
Expand Down
Loading
Loading