- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.8k
          Extensions: Adds @provideContext and @consumeContext decorators for a better developer experience
          #20510
        
          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
Conversation
… console when it detects wrong usage
… with our own methods
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.
Pull Request Overview
Adds new @Providecontext and @consumeContext decorators to the Backoffice context API for simpler and more type-safe context provision/consumption, and migrates Log Viewer components to use them.
- Introduces provideContext and consumeContext decorators with support for both standard (Stage 3) and legacy TypeScript decorators.
- Refactors Log Viewer UI components to use @consumeContext and simplifies observers.
- Improves UmbContextConsumer reliability and extends tests to cover decorators.
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description | 
|---|---|
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/search/log-search-view.element.ts | Replaces manual context consumption with @consumeContext and simplifies observers. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/search/components/log-viewer-search-input.element.ts | Migrates to @consumeContext and streamlines saved searches and query handling. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/search/components/log-viewer-polling-button.element.ts | Migrates to @consumeContext and normalizes polling config default. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/search/components/log-viewer-messages-list.element.ts | Migrates to @consumeContext and simplifies observers. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/search/components/log-viewer-log-level-filter-menu.element.ts | Migrates to @consumeContext and simplifies observers. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/overview/log-overview-view.element.ts | Migrates to @consumeContext and triggers initial data fetch via decorator callback. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/overview/components/log-viewer-saved-searches-overview.element.ts | Migrates to @consumeContext and centralizes initial data load. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/overview/components/log-viewer-message-templates-overview.element.ts | Migrates to @consumeContext and centralizes initial data load. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/overview/components/log-viewer-log-types-chart.element.ts | Migrates to @consumeContext and simplifies observers. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/workspace/views/overview/components/log-viewer-log-level-overview.element.ts | Migrates to @consumeContext and simplifies observers. | 
| src/Umbraco.Web.UI.Client/src/packages/log-viewer/components/log-viewer-date-range-selector.element.ts | Migrates to @consumeContext and updates bindings for date boundaries. | 
| src/Umbraco.Web.UI.Client/src/mocks/data/log-viewer.data.ts | Normalizes level strings to lowercase before counting. | 
| src/Umbraco.Web.UI.Client/src/libs/context-api/provide/index.ts | Re-exports the provideContext decorator. | 
| src/Umbraco.Web.UI.Client/src/libs/context-api/provide/context-provide.decorator.ts | Implements provideContext decorator (standard and legacy) with docs and typing. | 
| src/Umbraco.Web.UI.Client/src/libs/context-api/provide/context-provide.decorator.test.ts | Adds provideContext tests for elements and controllers. | 
| src/Umbraco.Web.UI.Client/src/libs/context-api/consume/index.ts | Re-exports the consumeContext decorator. | 
| src/Umbraco.Web.UI.Client/src/libs/context-api/consume/context-consumer.ts | Adds connection check before dispatching context requests. | 
| src/Umbraco.Web.UI.Client/src/libs/context-api/consume/context-consume.decorator.ts | Implements consumeContext decorator (standard and legacy) with docs and typing. | 
| src/Umbraco.Web.UI.Client/src/libs/context-api/consume/context-consume.decorator.test.ts | Adds consumeContext tests including non-subscribing behavior. | 
        
          
                ...src/packages/log-viewer/workspace/views/search/components/log-viewer-search-input.element.ts
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/Umbraco.Web.UI.Client/src/libs/context-api/provide/context-provide.decorator.ts
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/Umbraco.Web.UI.Client/src/libs/context-api/consume/context-consume.decorator.ts
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/Umbraco.Web.UI.Client/src/libs/context-api/provide/context-provide.decorator.ts
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                src/Umbraco.Web.UI.Client/src/libs/context-api/provide/context-provide.decorator.test.ts
              
                Outdated
          
            Show resolved
            Hide resolved
        
      Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
…ews/search/components/log-viewer-search-input.element.ts Co-authored-by: Copilot <[email protected]>
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.
LGTM! 😎
Description
This pull request adds two new decorators to the Backoffice package:
@provideContextand@consumeContext.Changes
provideContext
provideContextproperty decorator incontext-provide.decorator.ts, supporting both standard (Stage 3 TC39) and legacy TypeScript decorators. This makes it easier to provide a context instance downstream from an element or a controller.provideContextdecorator from the context API's main index for easy access.consumeContext
consumeContextproperty decorator incontext-consume.decorator.ts, supporting both standard (Stage 3 TC39) and legacy TypeScript decorators, with options for callbacks and subscription control. This greatly improves flexibility and type safety for consuming context in components and controllers.consumeContextdecorator from the context API's main index for easy access.Test Coverage Improvements
consumeContextdecorator, covering usage in components and controllers, callback invocation, context updates, and non-subscribing consumers.provideContextdecorator, verifying context provision, controller usage, immutability of provided values, and correct update behavior.Context Consumer Reliability
UmbContextConsumerby adding a connection check before dispatching context requests, preventing requests on disconnected elements, and logging warnings for such cases.Log Viewer
@consumeContextdecorator to demonstrate its usage.