S3 resource selector 컴포넌트
S3 resource selector는 S3 버킷에서 객체를 읽거나, 접두어(prefix)와 함께 S3 버킷에 객체를 쓰는 기능을 제공하는 컴포넌트입니다. 사용자가 Amazon S3 리소스 URI를 선택할 수 있도록 도우며, 리소스 URI 입력, 객체 버전 선택, 리소스 탐색 모달 등 Amazon S3의 통합 논리와 검증 규칙을 제공합니다. 이 컴포넌트는 Amazon S3에서 리소스를 읽는 Read 모드와 쓰는 Write 모드, 두 가지 모드로 작동합니다.
출처: 문서
본문
S3 resource selector는 S3 버킷에서 객체를 읽거나, 접두어(prefix)와 함께 S3 버킷에 객체를 쓰는 기능을 제공하는 컴포넌트입니다.
개발 지침 (Development guidelines)
상태 관리 (State management)
S3 resource selector 컴포넌트는 제어됩니다(controlled). resource 속성과 onChange 리스너를 설정하여 그 값과 검증 결과를 애플리케이션의 상태에 저장하세요. Cloudscape 컴포넌트의 상태 관리에 대해 더 알아보세요.
S3 API 통합 (S3 API integration)
S3 API 응답을 처리할 때 공통 접두어(common prefixes)(디렉터리)와 contents(파일)를 단일 목록으로 병합하세요. 공통 접두어의 경우 같은 이름의 파일과 디렉터리가 있을 때 모호함을 피하기 위해 이름의 후행 슬래시를 보존하세요.
테스트 유틸리티 클래스가 처음이라면 소개 글에서 더 자세히 배울 수 있습니다.
단위 테스트 예시 (Unit testing examples)
s3 resource-selector 선택하기
import { render } from '@testing-library/react';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import S3ResourceSelector from '@cloudscape-design/components/s3-resource-selector';
describe('<S3ResourceSelector />', () => {
it('renders the s3-resource-selector component', () => {
const { container } = render(<S3ResourceSelector />);
const wrapper = createWrapper(container);
expect(wrapper.findS3ResourceSelector()).toBeTruthy();
});
it('selects all s3-resource-selector components', () => {
const { container } = render(<>
<S3ResourceSelector />
<S3ResourceSelector />
<S3ResourceSelector />
</>);
const wrapper = createWrapper(container);
const components = wrapper.findAllS3ResourceSelectors();
expect(components).toHaveLength(3)
});
});
셀렉터 모달로 리소스 선택하기
import Box from '@cloudscape-design/components/box';
import S3ResourceSelector, { S3ResourceSelectorProps } from '@cloudscape-design/components/s3-resource-selector';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import TextContent from '@cloudscape-design/components/text-content';
import { render, waitFor } from '@testing-library/react';
import { useState } from 'react';
const buckets = [
{
Name: 'bucket-fugiat',
CreationDate: 'December 27, 2019, 22:16:38 (UTC+01:00)',
Region: 'Middle East (Bahrain) me-south-1',
},
{
Name: 'bucket-ut',
CreationDate: 'July 06, 2019, 12:41:19 (UTC+02:00)',
Region: 'US East (N. Virginia) us-east-1',
},
];
const objects = [
{
Key: 'black-hole-5ns.zip',
LastModified: 'August 03, 2019, 19:26:58 (UTC+02:00)',
Size: 66477663816,
IsFolder: false,
},
{
Key: 'electron-8h.zip',
LastModified: 'November 06, 2019, 14:00:40 (UTC+01:00)',
Size: 96909820974,
IsFolder: false,
},
];
const versions = [
{
VersionId: 'f2ef887e-af4c-4003-ad16-153d1419c024',
LastModified: 'April 30, 2019, 05:21:44 (UTC+02:00)',
Size: 29013625564809,
},
{
VersionId: '82e5f938-fe82-4977-a39a-44a549e630c1',
LastModified: 'April 10, 2019, 21:21:10 (UTC+02:00)',
Size: 25016305995260,
},
];
function Component() {
const [resource, setResource] = useState<S3ResourceSelectorProps['resource']>({
uri: '',
});
return (
<Box>
<TextContent>Selected resource URI: {resource.uri}</TextContent>
<TextContent>Selected resource version: {resource.versionId}</TextContent>
<S3ResourceSelector
onChange={({ detail }) => setResource(detail.resource)}
resource={resource}
fetchBuckets={() => Promise.resolve(buckets)}
fetchObjects={() => Promise.resolve(objects)}
fetchVersions={() => Promise.resolve(versions)}
selectableItemsTypes={['objects', 'versions']}
/>
</Box>
);
}
describe('<S3ResourceSelector />', () => {
it('selects the resource using the s3 selector modal', async () => {
const { container } = render(<Component />);
const wrapper = createWrapper(container);
// 1. Open the browse modal
const s3Selector = wrapper.findS3ResourceSelector()!;
s3Selector.findInContext()!.findBrowseButton().click();
const modalContent = await waitFor(() => {
return s3Selector.findModal()!.findContent();
});
// 2. Pick the `bucket-fugiat` bucket from the list.
const s3Bucket = await waitFor(() => {
const link = modalContent.findTable()!.findBodyCell(1, 2)!.findLink()!;
expect(link.getElement().textContent).toBe('bucket-fugiat');
return link;
});
s3Bucket.click();
// 3. From the selected bucket, pick the `electron-8h.zip` object.
const s3Object = await waitFor(() => {
const link = modalContent.findTable()!.findBodyCell(2, 2)!.findLink()!;
expect(link.getElement().textContent).toBe('electron-8h.zip');
return link;
});
s3Object.click();
// 4. From the selected object, pick the second version.
const s3Version = await waitFor(() => {
const selectionArea = modalContent.findTable()!.findRowSelectionArea(2)!;
expect(selectionArea).toBeTruthy();
return selectionArea;
});
s3Version.click();
// 5. Submit and wait for modal to close.
s3Selector.findModal()!.findSubmitButton().click();
await waitFor(() => {
const modal = wrapper.findModal();
expect(modal).toBe(null);
});
// 6. Assert the selected resource.
const [resourceUri, versionId] = wrapper.findAllTextContents();
expect(resourceUri.getElement().textContent).toBe('Selected resource URI: s3://bucket-fugiat/electron-8h.zip');
expect(versionId.getElement().textContent).toBe('Selected resource version: 82e5f938-fe82-4977-a39a-44a549e630c1');
});
});
텍스트 입력으로 리소스 선택하기
import Box from '@cloudscape-design/components/box';
import S3ResourceSelector, { S3ResourceSelectorProps } from '@cloudscape-design/components/s3-resource-selector';
import createWrapper from '@cloudscape-design/components/test-utils/dom';
import TextContent from '@cloudscape-design/components/text-content';
import { render, waitFor } from '@testing-library/react';
import { useState } from 'react';
const buckets = [
{
Name: 'bucket-fugiat',
CreationDate: 'December 27, 2019, 22:16:38 (UTC+01:00)',
Region: 'Middle East (Bahrain) me-south-1',
},
];
const objects = [
{
Key: 'black-hole-5ns.zip',
LastModified: 'August 03, 2019, 19:26:58 (UTC+02:00)',
Size: 66477663816,
IsFolder: false,
},
];
const versions = [
{
VersionId: 'f2ef887e-af4c-4003-ad16-153d1419c024',
LastModified: 'April 30, 2019, 05:21:44 (UTC+02:00)',
Size: 29013625564809,
},
{
VersionId: '82e5f938-fe82-4977-a39a-44a549e630c1',
LastModified: 'April 10, 2019, 21:21:10 (UTC+02:00)',
Size: 25016305995260,
},
];
function Component() {
const [resource, setResource] = useState<S3ResourceSelectorProps['resource']>({
uri: '',
versionId: '',
});
return (
<Box>
<TextContent>Selected resource URI: {resource.uri}</TextContent>
<TextContent>Selected resource version: {resource.versionId}</TextContent>
<S3ResourceSelector
onChange={({ detail }) => setResource(detail.resource)}
resource={resource}
fetchBuckets={() => Promise.resolve(buckets)}
fetchObjects={() => Promise.resolve(objects)}
fetchVersions={() => Promise.resolve(versions)}
selectableItemsTypes={['objects', 'versions']}
/>
</Box>
);
}
describe('<S3ResourceSelector />', () => {
it('selects the resource and its version using the in-context text input', async () => {
const { container } = render(<Component />);
const wrapper = createWrapper(container);
const s3SelectorInContext = wrapper.findS3ResourceSelector()!.findInContext();
s3SelectorInContext!.findUriInput()!.setInputValue('s3://bucket-fugiat/bucket-hole-5ns.zip');
await waitFor(() => {
if (s3SelectorInContext.findVersionsSelect()!.isDisabled()) {
throw new Error('Waiting for versions to load');
}
});
s3SelectorInContext.findVersionsSelect()!.openDropdown();
s3SelectorInContext.findVersionsSelect()!.selectOptionByValue('82e5f938-fe82-4977-a39a-44a549e630c1');
const [resourceUri, versionId] = wrapper.findAllTextContents();
expect(resourceUri.getElement().textContent).toBe('Selected resource URI: s3://bucket-fugiat/bucket-hole-5ns.zip');
expect(versionId.getElement().textContent).toBe('Selected resource version: 82e5f938-fe82-4977-a39a-44a549e630c1');
});
});
단위 테스트 API (Unit testing APIs)
S3ResourceSelectorWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| findAlertSlot | ElementWrapper | null | - | - |
| findInContext | S3InContextWrapper | - | - |
| findModal | S3ModalWrapper | null | - | - |
| findTable | TableWrapper | null | - | - |
S3InContextWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| findBrowseButton | ButtonWrapper | - | - |
| findUriInput | InputWrapper | - | - |
| findVersionsSelect | SelectWrapper | null | - | - |
| findViewButton | ButtonWrapper | - | - |
S3ModalWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| findContent | ElementWrapper | - | - |
| findDismissButton | ElementWrapper | - | - |
| findFooter | ElementWrapper | null | - | - |
| findHeader | ElementWrapper | - | - |
| findSubmitButton | ButtonWrapper | - | - |
| isVisible | boolean | - | - |
통합 테스트 API (Integration testing APIs)
S3ResourceSelectorWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| findAlertSlot | ElementWrapper | - | - |
| findInContext | S3InContextWrapper | - | - |
| findModal | S3ModalWrapper | - | - |
| findTable | TableWrapper | - | - |
S3InContextWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| findBrowseButton | ButtonWrapper | - | - |
| findUriInput | InputWrapper | - | - |
| findVersionsSelect | SelectWrapper | - | - |
| findViewButton | ButtonWrapper | - | - |
S3ModalWrapper
| Name | Return type | Description | Parameters |
|---|---|---|---|
| findContent | ElementWrapper | - | - |
| findDismissButton | ElementWrapper | - | - |
| findFooter | ElementWrapper | - | - |
| findHeader | ElementWrapper | - | - |
| findSubmitButton | ButtonWrapper | - | - |
주요 Amazon S3 개념 (Key Amazon S3 concepts)
Amazon Simple Storage Service(Amazon S3)는 객체 스토리지 서비스입니다. Amazon S3의 기본 저장 단위는 버킷으로 구성된 객체입니다. 자세한 내용은 Amazon S3 문서를 참조하세요.
일반 지침 (General guidelines)
권장 사항 (Do)
- S3 resource selector에 포함된 alert 컴포넌트를 사용해 서버 오류를 잡아 표시하세요.
금지 사항 (Don't)
- modal이나 popover에서 S3 resource selector를 사용하지 마세요.
- S3 resource selector 패턴을 일반 파일 리소스 선택기로 사용하지 마세요. 대신 file upload 패턴을 사용하세요.
기능 (Features)
S3 resource selector 컴포넌트의 주요 기능은 사용자가 Amazon S3 리소스 URI(Uniform Resource Identifier)를 선택할 수 있도록 도와, 서비스가 그 리소스에 읽기 또는 쓰기 작업을 수행할 수 있게 하는 것입니다. 이 컴포넌트는 Amazon S3의 상호작용, 기능, 검증 규칙을 포함한 통합 로직을 제공합니다.
모드 (Modes)
S3 resource selector는 Amazon S3에서 리소스를 읽거나 Amazon S3에 리소스를 쓰는 두 가지 모드 중 하나로 작동합니다. 일부 기능은 특정 모드에서만 사용할 수 있습니다.
-
읽기 (Read)
서비스가 Amazon S3에서 리소스를 읽기 위해 객체 또는 버킷 URI를 선택하는 데 사용합니다.
-
예:
- 파싱과 분석을 위해 로그 파일 객체가 있는 버킷에서 읽기.
- 파일의 오디오를 전사하기 위해 비디오 파일 객체에서 읽기.
-
-
쓰기 (Write)
서비스가 Amazon S3에 리소스를 쓰기 위해 객체 또는 버킷 URI를 선택하는 데 사용합니다.
-
예:
- 이벤트의 로그 파일을 Amazon S3 버킷에 쓰기.
- 트랜스코딩 후 비디오 파일을 Amazon S3 버킷에 쓰기.
-
내장 기능 (Built-in functions)
-
리소스 URI 입력 (Resource URI input)
사용자가 리소스의 URI를 입력하거나 붙여넣을 수 있게 도와주는 입력입니다. 사용자가 리소스 탐색 모달로 리소스를 선택하면 URI 필드에 해당 리소스 URI가 자동으로 채워집니다.
- URI 리소스 필드는 인라인으로 검증되며 제공된 URI를 Amazon S3의 리소스 명명 규칙과 대조 확인합니다.
- 특정 검증 텍스트 문자열에 대해서는 S3 resource selector의 작성 지침을 따르세요.
-
객체 버전 선택 - 선택사항 (Object version selection - Optional)
Select는 사용자가 객체의 사용 가능한 버전을 선택하는 방법입니다.
-
Read 모드에서는 버전 select를 포함하는 것을 강력히 권장합니다. 사용자가 올바른 객체 버전을 선택하는 데 도움이 되기 때문입니다. 사용자가 버전을 선택하지 않으면 객체의 가장 최근 버전이 사용됩니다.
-
Write 모드에서는 Amazon S3가 특정 버전에 쓰는 기능을 제공하지 않으므로 버전 select가 포함되지 않습니다. 버킷에서 버전 관리가 활성화되어 있으면 기존 객체에 쓰는 것은 해당 객체의 새 버전을 만듭니다.
-
S3 resource selector의 빈 상태에서 버전 select는 비활성화된 상태로 표시됩니다.
- 버전 select는 사용자가 리소스 URI 필드에 객체의 URI를 입력했거나 탐색 모달로 객체를 선택했을 때 활성화됩니다.
- 버킷은 버전 관리되지 않습니다(버킷 안의 객체만 버전 관리됨). 사용자가 버킷을 선택하면 버전 select는 비활성 상태로 유지됩니다.
-
-
리소스 탐색 모달 (Browsing resources modal)
사용자가 버킷, 객체, 버전을 탐색해 특정 리소스에 대한 URI를 찾는 방법인 Amazon S3 리소스 목록이 있는 모달입니다. 이 모달은 사용자가 Browse 버튼을 클릭할 때 시작됩니다.
- Amazon S3가 기술적으로 폴더를 지원하지는 않지만, / 구분자 접두어를 사용하는 객체 키는 S3 resource selector에서 폴더에 중첩된 것처럼 표시됩니다.
- 버킷, 객체, 버전을 포함해 사용자가 선택할 수 있는 리소스 유형을 정의할 수 있습니다.
-
선택된 객체 보기 - 선택사항 (Viewing a chosen object - Optional)
View 버튼은 사용자가 추가 메타데이터를 제공하는 Amazon S3 콘솔에서 객체의 설명 페이지를 여는 방법입니다. 이는 사용자가 올바른 객체를 선택하는 데 도움이 됩니다. View 버튼은 사용자가 객체를 선택하면 활성화됩니다.
-
검증 (Validation)
사용자가 리소스 URI를 입력하거나 붙여넣을 때 검증이 인라인으로 발생합니다. 특정 검증 규칙과 텍스트 문자열에 대해서는 오류 작성 지침을 따르세요.
상태 (States)
-
빈 상태 (Empty)
리소스 URI가 제공되지 않았거나 사용자가 리소스를 탐색해 선택하지 않았을 때의 S3 resource selector 상태입니다.
-
로딩 (Loading)
사용자가 리소스 URI를 입력하거나 붙여넣거나, 리소스를 탐색해 선택할 때 컴포넌트는 구현자가 Amazon S3 fetch 작업을 트리거할 수 있는 이벤트를 제공합니다. fetch 작업 중에 컴포넌트는 Resource URI 입력 아래에 로딩 표시기를 보여줍니다.
-
오류 (Errors)
S3 resource selector에서 발생하는 두 가지 주요 오류 유형이 있습니다:
- 검증 오류: 사용자가 Resource URI 입력에 URI를 입력하거나 붙여넣을 때 발생할 수 있습니다. 이 오류들은 Resource URI 입력 아래에 자동으로 표시됩니다.
- 서버 오류: 리소스를 가져오는 데 문제가 있을 때 발생합니다. 서버 오류를 잡아 컴포넌트에 포함된 alert에 전달하는 것은 구현자의 책임입니다.
작성 지침 (Writing guidelines)
일반 작성 지침 (General writing guidelines)
-
문장형 대소문자(sentence case)를 사용하되, 문맥에 따라 고유 명사와 브랜드 이름은 올바르게 대문자로 표기하세요.
-
현재 시제 동사와 능동태를 사용하세요.
-
글에서 please, thank you, 줄임표( ... ), 앰퍼샌드( & ), e.g., i.e., etc. 를 사용하지 마세요.
-
방향을 나타내는 언어는 피하세요.
- 예: 위(above) 대신 이전(previous), 아래(below) 대신 다음(following) 을 사용하세요.
-
기기에 독립적인 언어를 사용하세요.
- 예: 클릭(click) 대신 선택(choose) 또는 select를 사용하세요.
컴포넌트별 지침 (Component-specific guidelines)
폼 필드 레이블 (Form field labels)
-
리소스 URI와 버전 폼 필드 레이블에 이 텍스트를 사용하세요:
- Amazon S3 리소스 URI 경로 레이블에 Resource URI.
- 버전 select 레이블에 Object Version.
-
form field의 작성 지침을 따르세요.
폼 필드 제약 텍스트 (Form field constraint text)
-
인라인 폼의 필드에 이 텍스트를 사용하세요:
- Read 모드의 Resource URI 필드에 Use s3://bucket/prefix/object format.
- Write 모드의 Resource URI 필드에 Use s3://bucket/prefix format.
-
form field의 작성 지침을 따르세요.
폼 필드 플레이스홀더 - 선택사항 (Form field placeholders - optional)
-
인라인 폼의 필드에 플레이스홀더 텍스트를 사용하세요:
- Read 모드의 Resource URI 필드 플레이스홀더에 s3://bucket/prefix/object.
- Write 모드의 Resource URI 필드 플레이스홀더에 s3://bucket/prefix.
- 객체 버전 select에 Choose version.
-
form field의 작성 지침을 따르세요.
버튼 (Buttons)
-
초기 폼의 버튼에 이 텍스트를 사용하세요:
- 객체 보기 버튼에 View.
- 모달 브라우저를 여는 버튼에 Browse S3.
-
탐색 Amazon S3 모달에서 이 텍스트를 사용하세요:
- 리소스를 선택하는 버튼에 Choose.
- 선택을 취소하고 모달을 닫는 버튼에 Cancel.
-
button의 작성 지침을 따르세요.
탐색 모달 (Browse modal)
-
탐색 모달 헤더에 이 텍스트를 사용하세요: Choose \[리소스 유형\] in Amazon S3
- 예: Choose audio file in Amazon S3.
-
modal의 작성 지침을 따르세요.
탐색 테이블 (Browse table)
-
탐색 모달 테이블의 열 헤더에 이 텍스트를 사용하세요:
- 버킷 이름: Name
- 버킷 생성 날짜: Creation date
- 버킷 리전: Region
- 객체 키: Key
- 객체 마지막 수정 타임스탬프: Last modified
- 객체 또는 버전 크기: Size
- 버전 ID: Version ID
- 버전 생성 시간: Creation time
-
날짜나 시간이 있는 테이블 열에 대해서는 timestamps 지침을 따르세요.
-
table의 작성 지침을 따르세요.
컴포넌트 상태 (Component states)
빈 상태 (Empty state)
Resource URI 입력, Object version select, browse S3 resources 테이블 같은 빈 상태에 대해서는 empty states 지침을 따르세요.
로딩 (Loading)
-
리소스가 가져와지는 동안 컴포넌트는 로딩 표시기를 보여줍니다. 로딩 표시기 텍스트에는 이 텍스트를 사용하세요: Loading resource
-
탐색 S3 모달 테이블에서 리소스가 로딩 중일 때 이 텍스트를 사용하세요: Loading \[리소스 유형\]
-
예:
- Loading buckets
- Loading objects
- Loading versions.
-
오류 (Error)
-
S3 리소스 URI를 검증할 때 이 텍스트를 사용하세요:
- The path must begin with s3://
- The bucket name must start with a lowercase character or number.
- The bucket name must not contain uppercase characters.
- The bucket name must comply with DNS naming conventions.
- The bucket name length must be from 3 to 63 characters.
-
서버 오류를 표시할 때 alert 제목은 문제를 밝히고, 설명은 사용자가 문제를 해결하는 방법을 설명해야 합니다.
-
예:
- 제목: Object versions were not retrieved for the title
- 설명: You might not have permissions to retrieve object versions. Contact your account administrator to request necessary permissions
-
-
alert의 작성 지침을 따르세요.
접근성 지침 (Accessibility guidelines)
일반 접근성 지침 (General accessibility guidelines)
- 각 컴포넌트의 대체 텍스트(alternative text)와 ARIA 영역 지침을 따르세요.
- 애플리케이션의 언어 컨텍스트에 맞춰 ARIA 레이블을 정의해야 합니다.
- 역할(roles)과 랜드마크에 불필요한 마크업을 추가하지 마세요. 각 컴포넌트의 지침을 따르세요.
- 논리적이고 예측 가능한 순서로 모든 사용 가능한 콘텐츠에 키보드 기능을 제공하세요. 정보 흐름은 이해하기 쉬워야 합니다.
컴포넌트별 지침 (Component-specific guidelines)
대체 텍스트 (Alternative text)
- S3 resource selector의 각 부분에 대해 alert, breadcrumbs, modal, table, pagination의 대체 텍스트 지침을 참조하세요.