From 64284a0e8a2c3c4eb60e6cca257b6291c72f5f5e Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Fri, 29 Nov 2024 14:26:38 +0100 Subject: [PATCH 1/2] enhanced test page and fixed bug with no match --- pages/collection-preferences/simple.page.tsx | 82 +++++++++++++------ .../content-display/index.tsx | 2 +- src/collection-preferences/interfaces.ts | 9 +- 3 files changed, 68 insertions(+), 25 deletions(-) diff --git a/pages/collection-preferences/simple.page.tsx b/pages/collection-preferences/simple.page.tsx index 8a5d4bbd7b..62d818c652 100644 --- a/pages/collection-preferences/simple.page.tsx +++ b/pages/collection-preferences/simple.page.tsx @@ -2,8 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import * as React from 'react'; +import { Box, SpaceBetween } from '~components'; import CollectionPreferences from '~components/collection-preferences'; +import { contentDisplayPreferenceI18nStrings } from '../common/i18n-strings'; import ScreenshotArea from '../utils/screenshot-area'; import { baseProperties, @@ -20,29 +22,63 @@ export default function CollectionPreferencesPermutations() { <>

CollectionPreferences page for screenshot tests

- - - - + + + + Table prefs with visible content + + + + + + Custom prefs only + + + + + + Single column with custom prefs + + + + + + Single column visible content + + + + + + Single column content display with groups + ); diff --git a/src/collection-preferences/content-display/index.tsx b/src/collection-preferences/content-display/index.tsx index 1949803a79..c37a56e2d6 100644 --- a/src/collection-preferences/content-display/index.tsx +++ b/src/collection-preferences/content-display/index.tsx @@ -143,7 +143,7 @@ export default function ContentDisplayPreference({ )} {/* No match */} - {sortedAndFilteredOptions.length === 0 && ( + {enableColumnFiltering && sortedAndFilteredOptions.length === 0 && (
diff --git a/src/collection-preferences/interfaces.ts b/src/collection-preferences/interfaces.ts index 246a75b3cf..d1231229e2 100644 --- a/src/collection-preferences/interfaces.ts +++ b/src/collection-preferences/interfaces.ts @@ -218,7 +218,7 @@ export namespace CollectionPreferencesProps { export interface ContentDisplayPreference { title?: string; description?: string; - options: ReadonlyArray; + options: ReadonlyArray; liveAnnouncementDndStarted?: (position: number, total: number) => string; liveAnnouncementDndItemReordered?: (initialPosition: number, currentPosition: number, total: number) => string; liveAnnouncementDndItemCommitted?: (initialPosition: number, finalPosition: number, total: number) => string; @@ -229,6 +229,13 @@ export namespace CollectionPreferencesProps { i18nStrings?: ContentDisplayPreferenceI18nStrings; } + export interface ContentDisplayOptionOrGroup { + id: string; + label: string; + alwaysVisible?: boolean; + options?: ReadonlyArray; + } + export interface ContentDisplayOption { id: string; label: string; From c9abe80ba796f0730b02b6e1f10d69377e00ba07 Mon Sep 17 00:00:00 2001 From: Andrei Zhaleznichenka Date: Fri, 29 Nov 2024 15:46:32 +0100 Subject: [PATCH 2/2] poc with nested options --- .../reorder-content.page.tsx | 147 ++++++++++++++---- pages/collection-preferences/simple.page.tsx | 16 -- .../content-display-option.scss | 6 + .../content-display-option.tsx | 11 +- .../content-display/draggable-option.tsx | 6 +- .../content-display/index.tsx | 89 +++++++---- .../content-display/utils.ts | 84 ++++++++-- src/collection-preferences/interfaces.ts | 6 +- 8 files changed, 258 insertions(+), 107 deletions(-) diff --git a/pages/collection-preferences/reorder-content.page.tsx b/pages/collection-preferences/reorder-content.page.tsx index 0a10cb2e9a..d821f78d0c 100644 --- a/pages/collection-preferences/reorder-content.page.tsx +++ b/pages/collection-preferences/reorder-content.page.tsx @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import React from 'react'; -import CollectionPreferences from '~components/collection-preferences'; +import { Box, CollectionPreferences, SpaceBetween } from '~components'; import { contentDisplayPreferenceI18nStrings } from '../common/i18n-strings'; import ScreenshotArea from '../utils/screenshot-area'; @@ -43,39 +43,126 @@ const longOptionsList = Array(50) .fill(1) .map((item, index) => ({ id: `id_${index}`, label: `Item ${index + 1}` })); +const optionListWithGroups = [ + { + id: 'id', + label: 'Item ID', + alwaysVisible: true, + }, + { id: 'name', label: 'Item name' }, + { + id: 'prices', + label: 'Prices', + options: [ + { + id: 'price-de', + label: 'Price DE', + }, + { + id: 'price-pl', + label: 'Price PL', + }, + { + id: 'price-uk', + label: 'Price UK', + }, + { + id: 'price-fr', + label: 'Price FR', + }, + { + id: 'price-it', + label: 'Price IT', + }, + ], + }, + { + id: 'attributes', + label: 'Attributes', + options: [ + { + id: 'size', + label: 'Size', + }, + { + id: 'weight', + label: 'Weight', + }, + { + id: 'battery', + label: 'Battery', + }, + { + id: 'power', + label: 'Power', + }, + { + id: 'condition', + label: 'Condition', + }, + ], + }, +]; + export default function App() { return (

CollectionPreferences page with content reordering

- - + + + + + No groups and no column filter + + + + + + No groups with column filter + + + + + + With groups with column filter +
); } diff --git a/pages/collection-preferences/simple.page.tsx b/pages/collection-preferences/simple.page.tsx index 62d818c652..c45693eefd 100644 --- a/pages/collection-preferences/simple.page.tsx +++ b/pages/collection-preferences/simple.page.tsx @@ -5,7 +5,6 @@ import * as React from 'react'; import { Box, SpaceBetween } from '~components'; import CollectionPreferences from '~components/collection-preferences'; -import { contentDisplayPreferenceI18nStrings } from '../common/i18n-strings'; import ScreenshotArea from '../utils/screenshot-area'; import { baseProperties, @@ -64,21 +63,6 @@ export default function CollectionPreferencesPermutations() { Single column visible content - - - - - Single column content display with groups - ); diff --git a/src/collection-preferences/content-display/content-display-option.scss b/src/collection-preferences/content-display/content-display-option.scss index 9ed1ed9e00..9da0766907 100644 --- a/src/collection-preferences/content-display/content-display-option.scss +++ b/src/collection-preferences/content-display/content-display-option.scss @@ -32,6 +32,9 @@ $border-radius: awsui.$border-radius-item; border-end-start-radius: $border-radius; border-end-end-radius: $border-radius; } +.content-display-option-nested { + padding-inline-start: awsui.$space-l; +} .content-display-option { list-style: none; @@ -62,6 +65,9 @@ $border-radius: awsui.$border-radius-item; @include styles.text-wrapping; padding-inline-end: awsui.$space-l; } +.content-display-option-group { + font-weight: bold; +} .drag-overlay { box-shadow: awsui.$shadow-container-active; diff --git a/src/collection-preferences/content-display/content-display-option.tsx b/src/collection-preferences/content-display/content-display-option.tsx index 0bbb10e7d3..b9284873c0 100644 --- a/src/collection-preferences/content-display/content-display-option.tsx +++ b/src/collection-preferences/content-display/content-display-option.tsx @@ -1,11 +1,12 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import React, { ForwardedRef, forwardRef } from 'react'; +import clsx from 'clsx'; import DragHandle, { DragHandleProps } from '../../internal/components/drag-handle'; import { useUniqueId } from '../../internal/hooks/use-unique-id'; import InternalToggle from '../../toggle/internal'; -import { OptionWithVisibility } from './utils'; +import { FlatOption } from './utils'; import styles from '../styles.css.js'; @@ -15,8 +16,8 @@ export const getClassName = (suffix?: string) => styles[[componentPrefix, suffix export interface ContentDisplayOptionProps { dragHandleAriaLabel?: string; listeners?: DragHandleProps['listeners']; - onToggle?: (option: OptionWithVisibility) => void; - option: OptionWithVisibility; + onToggle?: (option: FlatOption) => void; + option: FlatOption; disabled?: boolean; } @@ -33,10 +34,10 @@ const ContentDisplayOption = forwardRef( }; return ( -
+
-