-
Notifications
You must be signed in to change notification settings - Fork 98
Canvas #1635
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
Open
nmsimons
wants to merge
2
commits into
main
Choose a base branch
from
canvas
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+31,237
−0
Open
Canvas #1635
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,10 @@ | ||
| root = true | ||
|
|
||
| [*] | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
|
|
||
| [*.{js,json,yml}] | ||
| charset = utf-8 | ||
| indent_style = space | ||
| indent_size = 2 |
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,5 @@ | ||
| # .env.defaults should not contain private information. Create a .env file locally to override these values. | ||
| AZURE_TENANT_ID=<tenant-id> | ||
| AZURE_ORDERER=<orderer-url> | ||
| AZURE_FUNCTION_TOKEN_PROVIDER_URL=<token-provider-url> | ||
| FLUID_CLIENT=azure |
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,36 @@ | ||
| /*! | ||
| * Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
| * Licensed under the MIT License. | ||
| */ | ||
|
|
||
| module.exports = { | ||
| "env": { | ||
| "browser": true, | ||
| "es2021": true | ||
| }, | ||
| "extends": [ | ||
| "eslint:recommended", | ||
| "plugin:react/recommended", | ||
| "plugin:@typescript-eslint/recommended" | ||
| ], | ||
| "parser": "@typescript-eslint/parser", | ||
| "parserOptions": { | ||
| "ecmaFeatures": { | ||
| "jsx": true | ||
| }, | ||
| "ecmaVersion": "latest", | ||
| "sourceType": "module" | ||
| }, | ||
| "plugins": [ | ||
| "react", | ||
| "@typescript-eslint" | ||
| ], | ||
| "settings": { | ||
| "react": { | ||
| "version": "detect", | ||
| }, | ||
| }, | ||
| "rules": { | ||
| "no-undef": "off", | ||
| } | ||
| } |
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,4 @@ | ||
| /.yarn/** linguist-vendored | ||
| /.yarn/releases/* binary | ||
| /.yarn/plugins/**/* binary | ||
| /.pnp.* binary linguist-generated |
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,106 @@ | ||
| # Dependencies | ||
| node_modules/ | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| pnpm-debug.log* | ||
|
|
||
| # Other package manager files (using npm) | ||
| yarn.lock | ||
| pnpm-lock.yaml | ||
| .yarn/ | ||
| .pnpm/ | ||
| .pnp.* | ||
|
|
||
| # Build outputs | ||
| dist/ | ||
| build/ | ||
| *.tsbuildinfo | ||
|
|
||
| # Environment variables | ||
| .env | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| # IDE and editor files | ||
| # Keep .vscode/settings.json for project-specific VS Code settings | ||
| # but ignore personal VS Code configurations | ||
| .vscode/launch.json | ||
| .vscode/tasks.json | ||
| .vscode/.ropeproject | ||
| .vscode/extensions.json | ||
| .idea/ | ||
| *.swp | ||
| *.swo | ||
| *~ | ||
|
|
||
| # OS generated files | ||
| .DS_Store | ||
| .DS_Store? | ||
| ._* | ||
| .Spotlight-V100 | ||
| .Trashes | ||
| ehthumbs.db | ||
| Thumbs.db | ||
|
|
||
| # Logs | ||
| logs/ | ||
| *.log | ||
|
|
||
| # Runtime data | ||
| pids/ | ||
| *.pid | ||
| *.seed | ||
| *.pid.lock | ||
|
|
||
| # Coverage directory used by tools like istanbul | ||
| coverage/ | ||
| *.lcov | ||
|
|
||
| # nyc test coverage | ||
| .nyc_output | ||
|
|
||
| # Dependency directories | ||
| jspm_packages/ | ||
|
|
||
| # Optional npm cache directory | ||
| .npm | ||
|
|
||
| # Optional eslint cache | ||
| .eslintcache | ||
|
|
||
| # Microbundle cache | ||
| .rpt2_cache/ | ||
| .rts2_cache_cjs/ | ||
| .rts2_cache_es/ | ||
| .rts2_cache_umd/ | ||
|
|
||
| # Optional REPL history | ||
| .node_repl_history | ||
|
|
||
| # Output of 'npm pack' | ||
| *.tgz | ||
|
|
||
| # Yarn Integrity file | ||
| .yarn-integrity | ||
|
|
||
| # parcel-bundler cache (https://parceljs.org/) | ||
| .cache | ||
| .parcel-cache | ||
|
|
||
| # Vite | ||
| .vite/ | ||
|
|
||
| # Playwright | ||
| test-results/ | ||
| playwright-report/ | ||
| playwright/.cache/ | ||
|
|
||
| # Azure Functions | ||
| local.settings.json | ||
| .azure/ | ||
|
|
||
| # Nix | ||
| shell.nix |
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 @@ | ||
| node-linker=hoisted |
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 @@ | ||
| v20 |
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,13 @@ | ||
| /*! | ||
| * Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
| * Licensed under the MIT License. | ||
| */ | ||
|
|
||
| module.exports = { | ||
| semi: true, | ||
| trailingComma: "es5", | ||
| singleQuote: false, | ||
| printWidth: 100, | ||
| tabWidth: 4, | ||
| useTabs: true, | ||
| }; |
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,5 @@ | ||
| { | ||
| "editor.defaultFormatter": "esbenp.prettier-vscode", | ||
| "editor.formatOnSave": true, | ||
| "cSpell.words": ["insertable"], | ||
| } |
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,9 @@ | ||
| # Microsoft Open Source Code of Conduct | ||
|
|
||
| This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). | ||
|
|
||
| Resources: | ||
|
|
||
| - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) | ||
| - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) | ||
| - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns |
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like a dev doc - maybe move this and similar ones into a docs folder or delete? I think they'll be confusing to people reading the example. |
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,124 @@ | ||
| # Event Subscription Consolidation Summary | ||
|
|
||
| ## Problem Identified | ||
|
|
||
| The codebase had repetitive event subscription patterns scattered throughout multiple React components, particularly: | ||
|
|
||
| 1. **Selection state management**: Components repeatedly subscribed to selection events with similar patterns | ||
| 2. **Button state management**: Multiple buttons used identical logic to enable/disable based on selections | ||
| 3. **DOM event listeners**: Repetitive patterns for adding/removing event listeners with cleanup | ||
| 4. **Fluid Framework events**: Similar subscription patterns for tree commits and presence updates | ||
|
|
||
| ## Solution Implemented | ||
|
|
||
| ### Created Unified Event Subscription Utility (`src/utils/eventSubscriptions.ts`) | ||
|
|
||
| **Key Features:** | ||
|
|
||
| - **Type-safe event handling** with proper cleanup management | ||
| - **Selection-based state synchronization** helpers | ||
| - **Automatic subscription/unsubscription** lifecycle management | ||
| - **Performance optimized** with minimal re-renders using useRef patterns | ||
| - **Flexible and reusable** across different component types | ||
|
|
||
| **Main Utilities Created:** | ||
|
|
||
| 1. **`useEventSubscription`** - Generic event subscription with automatic cleanup | ||
| 2. **`useSelectionSync`** - Selection state synchronization for UI updates | ||
| 3. **`useSelectionBasedButtonState`** - Button disabled state based on selection criteria | ||
| 4. **`useTableButtonState`** - Specialized utility for table button components | ||
| 5. **`useMultiTypeSelectionSync`** - Manages multiple selection types (row, column, cell) | ||
| 6. **`useDOMEventListener`** - DOM event listeners with cleanup | ||
| 7. **`useMultipleDOMEventListeners`** - Multiple DOM event listeners at once | ||
|
|
||
| ## Implementation Examples | ||
|
|
||
| ### Before (Repetitive Pattern): | ||
|
|
||
| ```tsx | ||
| const [disabled, setDisabled] = React.useState(getSelected(selection, "row").length === 0); | ||
| useEffect(() => { | ||
| const unsubscribe = selection.events.on("localUpdated", () => { | ||
| if (getSelected(selection, "row").length === 0) { | ||
| setDisabled(true); | ||
| } else { | ||
| setDisabled(false); | ||
| } | ||
| }); | ||
| return unsubscribe; | ||
| }, []); | ||
| ``` | ||
|
|
||
| ### After (Unified Utility): | ||
|
|
||
| ```tsx | ||
| const [disabled, setDisabled] = React.useState(true); | ||
| useTableButtonState(selection, ["row"], setDisabled); | ||
| ``` | ||
|
|
||
| ## Components Updated | ||
|
|
||
| ### 1. Table Button Components (`tablebuttonux.tsx`) | ||
|
|
||
| - **MoveSelectedRowsButton**: Consolidated repetitive selection subscription logic | ||
| - **MoveSelectedColumnsButton**: Multi-type selection logic simplified | ||
| - **DeleteSelectedRowsButton**: Button state management unified | ||
|
|
||
| ### 2. Main UX Component (`ux.tsx`) | ||
|
|
||
| - **Item selection sync**: Replaced manual subscription with `useSelectionSync` | ||
| - **Table selection sync**: Used `useMultiTypeSelectionSync` for row/column state management | ||
|
|
||
| ## Benefits Achieved | ||
|
|
||
| ### 1. **Code Reduction** | ||
|
|
||
| - Eliminated ~15-20 lines of repetitive code per component | ||
| - Consolidated 6+ similar patterns into reusable utilities | ||
|
|
||
| ### 2. **Consistency** | ||
|
|
||
| - Standardized event subscription patterns across codebase | ||
| - Consistent cleanup and lifecycle management | ||
|
|
||
| ### 3. **Type Safety** | ||
|
|
||
| - Proper TypeScript integration with selection managers | ||
| - Compile-time verification of event handling | ||
|
|
||
| ### 4. **Performance** | ||
|
|
||
| - Optimized with useRef to prevent unnecessary re-renders | ||
| - Automatic cleanup prevents memory leaks | ||
|
|
||
| ### 5. **Maintainability** | ||
|
|
||
| - Single source of truth for event subscription logic | ||
| - Easy to update subscription patterns in one place | ||
| - Clear separation of concerns | ||
|
|
||
| ## Architecture Improvement | ||
|
|
||
| The event subscription utilities follow the same successful pattern as the previous `ContentHandler` consolidation: | ||
|
|
||
| 1. **Identified repetitive patterns** across multiple components | ||
| 2. **Created centralized utilities** with proper abstraction | ||
| 3. **Maintained type safety** and performance | ||
| 4. **Provided clear migration path** from old to new patterns | ||
|
|
||
| ## Testing & Validation | ||
|
|
||
| - ✅ **Build Success**: All TypeScript compilation passes | ||
| - ✅ **No Runtime Errors**: Proper cleanup and subscription management | ||
| - ✅ **Type Safety**: Full TypeScript support maintained | ||
| - ✅ **Backwards Compatible**: Existing functionality preserved | ||
|
|
||
| ## Next Steps | ||
|
|
||
| The event subscription utilities can be further extended to consolidate: | ||
|
|
||
| 1. **Presence manager subscriptions** (user updates, attendee changes) | ||
| 2. **Canvas/pointer event patterns** (drag, resize operations) | ||
| 3. **Container event subscriptions** (save, dispose, connection state) | ||
|
|
||
| This consolidation significantly improves code maintainability and provides a solid foundation for future event-driven features. |
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,21 @@ | ||
| Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
|
|
||
| MIT License | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think we use these any more.