This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 374
feature: Separated Add Resources to checklist #6386
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
75e04cd
Separated Add Resources to checklist
GeoffCoxMSFT 1f223f9
Merge branch 'main' into gcox/provision-add-resources
GeoffCoxMSFT d553fc0
Small PR fixes
GeoffCoxMSFT a0be3de
Missed on find to includes change
GeoffCoxMSFT 69dd30a
Handling unmount in async useEffect and timeouts
GeoffCoxMSFT d29c93d
Merge branch 'main' into gcox/provision-add-resources
GeoffCoxMSFT 53177a5
Of course useRef
GeoffCoxMSFT 9b1a623
Merge branch 'main' into gcox/provision-add-resources
GeoffCoxMSFT 6729c9c
Updating to check all optional by default
GeoffCoxMSFT 65f5aec
Merge branch 'gcox/provision-add-resources' of https://github.com/mic…
GeoffCoxMSFT 2d9d275
Don't show section headers when empty
GeoffCoxMSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
161 changes: 161 additions & 0 deletions
161
extensions/azurePublish/src/components/ChooseResourcesList.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| import * as React from 'react'; | ||
| import styled from '@emotion/styled'; | ||
| import { Stack } from 'office-ui-fabric-react/lib/Stack'; | ||
| import { Text } from 'office-ui-fabric-react/lib/Text'; | ||
| import { Checkbox } from 'office-ui-fabric-react/lib/Checkbox'; | ||
| import { FluentTheme, NeutralColors } from '@uifabric/fluent-theme'; | ||
| import { FocusZone, FocusZoneDirection } from 'office-ui-fabric-react/lib/FocusZone'; | ||
| import { List } from 'office-ui-fabric-react/lib/List'; | ||
|
|
||
| import { ResourcesItem } from '../types'; | ||
|
|
||
| // ---------- Styles ---------- // | ||
|
|
||
| const ItemCheckbox = styled(Checkbox)` | ||
| margin: 4px 10px 0 0; | ||
| padding: 5px; | ||
| `; | ||
|
|
||
| const checkBoxStyle = { | ||
| label: { | ||
| alignItems: 'flex-start', | ||
| }, | ||
| }; | ||
|
|
||
| const ItemLabel = styled(Stack)` | ||
| margin-left: 15px !important; | ||
| `; | ||
|
|
||
| const ItemHeader = styled(Stack)``; | ||
|
|
||
| const ImageIcon = styled.img` | ||
| width: 16px; | ||
| height: 16px; | ||
| margin: 4px 0 0 0; | ||
| user-select: none; | ||
| `; | ||
|
|
||
| const ImageIconPlacholder = styled.div` | ||
| width: 16px; | ||
| height: 16px; | ||
| margin: 4px 0 0 0; | ||
| user-select: none; | ||
| `; | ||
|
|
||
| const ItemText = styled(Text)` | ||
| font-size: ${FluentTheme.fonts.mediumPlus.fontSize}; | ||
| margin-left: 4px !important; | ||
GeoffCoxMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| `; | ||
|
|
||
| const ItemTier = styled(Text)` | ||
| font-size: ${FluentTheme.fonts.small.fontSize}; | ||
| margin: 4px 0 0 22px; | ||
| color: ${NeutralColors.gray130}; | ||
| `; | ||
|
|
||
| const ItemDescription = styled(Text)` | ||
| font-size: ${FluentTheme.fonts.medium.fontSize}; | ||
| margin: 4px 2px 0 22px; | ||
| color: ${NeutralColors.gray190}; | ||
| max-width: 500px; | ||
| `; | ||
|
|
||
| // ---------- ChooseResourcesList ---------- // | ||
|
|
||
| type ResourceListItem = ResourcesItem & { icon?: string }; | ||
|
|
||
| type Props = { | ||
| /** | ||
| * The resources to list in order. | ||
| */ | ||
| items: ResourceListItem[]; | ||
| /** | ||
| * The keys of the resources that should be selected. | ||
| */ | ||
| selectedKeys?: string[]; | ||
| /** | ||
| * Raised whenever the selection of keys changes. | ||
| */ | ||
| onSelectionChanged?: (selectedKeys: string[]) => void; | ||
| }; | ||
|
|
||
| /** | ||
| * Provides a selectable list control of resources. | ||
| * Displays the text, tier, description, and optional icon. | ||
| * Raises a callback of the selected keys. | ||
| * Allows for uncontrolled or controlled selected keys. | ||
| */ | ||
| export const ChooseResourcesList = (props: Props) => { | ||
| const { items, selectedKeys: controlledSelectedKeys, onSelectionChanged } = props; | ||
|
|
||
| // ----- Hooks | ||
|
|
||
| const getInitialSelectedKeys = () => { | ||
| return controlledSelectedKeys || items.filter((item) => item.required).map((item) => item.key); | ||
GeoffCoxMSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| const [selectedKeys, setSelectedKeys] = React.useState<string[]>(getInitialSelectedKeys); | ||
|
|
||
| // When the items or controlled selection changes, update selection state. | ||
| React.useEffect(() => { | ||
| setSelectedKeys(getInitialSelectedKeys()); | ||
| }, [items, controlledSelectedKeys]); | ||
|
|
||
| // ----- Handlers | ||
|
|
||
| const onCheckboxChanged = (ev: React.FormEvent<HTMLElement>, checked: boolean, item: ResourceListItem): void => { | ||
| let newSelectedKeys = undefined; | ||
| if (item.required || checked) { | ||
| if (!selectedKeys.includes(item.ke)) { | ||
| newSelectedKeys = [...selectedKeys, item.key]; | ||
| } | ||
| } else { | ||
| newSelectedKeys = selectedKeys.filter((i: string) => i !== item.key); | ||
| } | ||
|
|
||
| setSelectedKeys(newSelectedKeys); | ||
|
|
||
| if (onSelectionChanged) { | ||
| onSelectionChanged(newSelectedKeys); | ||
| } | ||
| }; | ||
|
|
||
| // ----- Render | ||
|
|
||
| const renderItemLabel = (item: ResourceListItem) => { | ||
| return ( | ||
| <ItemLabel> | ||
| <ItemHeader horizontal> | ||
| {item.icon ? <ImageIcon height="16" src={item.icon} width="16" /> : <ImageIconPlacholder />} | ||
| <ItemText>{item.text}</ItemText> | ||
| </ItemHeader> | ||
| <ItemTier>{item.tier}</ItemTier> | ||
| <ItemDescription>{item.description}</ItemDescription> | ||
| </ItemLabel> | ||
| ); | ||
| }; | ||
|
|
||
| const renderItem = (item: ResourceListItem) => { | ||
| const checked = item.required || !!selectedKeys.includes(item.key); | ||
| return ( | ||
| <ItemCheckbox | ||
| key={item.key} | ||
| data-is-focusable | ||
| checked={checked} | ||
| disabled={item.required} | ||
| styles={checkBoxStyle} | ||
| onChange={(e, c) => onCheckboxChanged(e, c, item)} | ||
| onRenderLabel={() => renderItemLabel(item)} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| return ( | ||
| <FocusZone direction={FocusZoneDirection.vertical}> | ||
| <List items={items} onRenderCell={renderItem} /> | ||
| </FocusZone> | ||
| ); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.