-
Notifications
You must be signed in to change notification settings - Fork 164
Context Clearing #1379
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
Context Clearing #1379
Changes from 14 commits
d9541d1
77e2b61
a2c348e
60456c3
768f50d
acac1a0
a4106fe
4e2bc61
c66f420
cdeea6a
1ad0c4a
a732bcc
9c79048
04507e0
e21ec30
90c8fab
c63e1d4
b953954
bc5c98c
c572444
90a06e3
ac73c5c
6d22fb3
a7e5c4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,13 +1,17 @@ | ||||||||||||||||||||||||||||||||
| import { ContextHandler, DisplayMetadata, Listener, Channel } from '@finos/fdc3-standard'; | ||||||||||||||||||||||||||||||||
| import { ContextHandler, DisplayMetadata, Listener, Channel, EventHandler } from '@finos/fdc3-standard'; | ||||||||||||||||||||||||||||||||
| import { Context } from '@finos/fdc3-context'; | ||||||||||||||||||||||||||||||||
| import { Messaging } from '../Messaging'; | ||||||||||||||||||||||||||||||||
| import { DefaultContextListener } from '../listeners/DefaultContextListener'; | ||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||
| BroadcastRequest, | ||||||||||||||||||||||||||||||||
| BroadcastResponse, | ||||||||||||||||||||||||||||||||
| ClearContextRequest, | ||||||||||||||||||||||||||||||||
| ClearContextResponse, | ||||||||||||||||||||||||||||||||
| GetCurrentContextRequest, | ||||||||||||||||||||||||||||||||
| GetCurrentContextResponse, | ||||||||||||||||||||||||||||||||
| } from '@finos/fdc3-schema/generated/api/BrowserTypes'; | ||||||||||||||||||||||||||||||||
| import { RegisterableListener } from '../listeners/RegisterableListener'; | ||||||||||||||||||||||||||||||||
| import { EventListener } from '../listeners/EventListener'; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| export class DefaultChannel implements Channel { | ||||||||||||||||||||||||||||||||
| protected readonly messaging: Messaging; | ||||||||||||||||||||||||||||||||
|
|
@@ -98,4 +102,30 @@ export class DefaultChannel implements Channel { | |||||||||||||||||||||||||||||||
| await listener.register(); | ||||||||||||||||||||||||||||||||
| return listener; | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
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. we're going to need some cucumber tests for this otherwise you'll see the coverage dip! |
||||||||||||||||||||||||||||||||
| async clearContext(contextType?: string): Promise<void> { | ||||||||||||||||||||||||||||||||
| // first, ensure channel state is up-to-date | ||||||||||||||||||||||||||||||||
| const request: ClearContextRequest = { | ||||||||||||||||||||||||||||||||
| meta: this.messaging.createMeta(), | ||||||||||||||||||||||||||||||||
| payload: { | ||||||||||||||||||||||||||||||||
|
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. Also, there will need to be support for this event added to the |
||||||||||||||||||||||||||||||||
| channelId: this.id, | ||||||||||||||||||||||||||||||||
| contextType: contextType ?? null, | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| type: 'clearContextRequest', | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
| await this.messaging.exchange<ClearContextResponse>(request, 'clearContextResponse', this.messageExchangeTimeout); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| async addEventListener(type: string | null, handler: EventHandler): Promise<Listener> { | ||||||||||||||||||||||||||||||||
| let listener: RegisterableListener; | ||||||||||||||||||||||||||||||||
| switch (type) { | ||||||||||||||||||||||||||||||||
| case 'contextCleared': | ||||||||||||||||||||||||||||||||
| listener = new EventListener(this.messaging, 'contextCleared', handler); | ||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
| break; | |
| break; | |
| case null: | |
| listener = new EventListener(this.messaging, 'allEvents', handler); // Register for all events | |
| break; |
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.
Copilot has a point there. It looks like this is also wrong where we listener for the channelChanged event:
FDC3/packages/fdc3-agent-proxy/src/DesktopAgentProxy.ts
Lines 77 to 85 in d4a261a
| addEventListener(type: FDC3EventTypes | null, handler: EventHandler): Promise<Listener> { | |
| switch (type) { | |
| case 'userChannelChanged': | |
| return this.channels.addChannelChangedEventHandler(handler); | |
| default: | |
| Logger.warn(`Tried to add a listener for an unknown event type: ${type}`); | |
| return Promise.reject(new Error('UnknownEventType')); | |
| } | |
| } |
Co-pilot's suggestion to fix isn't right however. Rather EventListener will probbably ned to be adjusted to be able to take multiple types:
| constructor(messaging: Messaging, type: string, handler: EventHandler) { |
As we need to know the specific messages it should respond to (from a set that is wider than the scope of the listener).
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "$id": "https://fdc3.finos.org/schemas/next/api/clearContextRequest.schema.json", | ||
| "type": "object", | ||
| "title": "Clear Context Request", | ||
| "description": "A request to clear context on a channel.", | ||
| "allOf": [ | ||
| { | ||
| "$ref": "appRequest.schema.json" | ||
| }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "$ref": "#/$defs/ClearContextRequestType" | ||
| }, | ||
| "payload": { | ||
| "$ref": "#/$defs/ClearContextRequestPayload" | ||
| }, | ||
| "meta": true | ||
| }, | ||
| "additionalProperties": false | ||
| } | ||
| ], | ||
| "$defs": { | ||
| "ClearContextRequestType": { | ||
| "title": "Clear Context Request Message Type", | ||
| "const": "clearContextRequest" | ||
| }, | ||
| "ClearContextRequestPayload": { | ||
| "title": "Clear Context Request Payload", | ||
| "type": "object", | ||
| "properties": { | ||
| "channelId": { | ||
| "title": "Channel Id", | ||
| "description": "The id of the channel to clear the context on.", | ||
| "type": "string" | ||
| }, | ||
| "contextType": { | ||
| "title": "Context type", | ||
| "description": "The type of context to clear for OR `null` indicating that all context types on the channel should be cleared.", | ||
| "oneOf": [ | ||
| { | ||
| "type": "string" | ||
| }, | ||
| { | ||
| "type": "null" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| "required": ["channelId", "contextType"], | ||
| "additionalProperties": false | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/draft-07/schema#", | ||
| "$id": "https://fdc3.finos.org/schemas/next/api/clearContextResponse.schema.json", | ||
| "type": "object", | ||
| "title": "Clear Context Response", | ||
| "description": "A response to a request to clear context on a channel.", | ||
| "allOf": [ | ||
| { | ||
| "$ref": "agentResponse.schema.json" | ||
| }, | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "type": { | ||
| "$ref": "#/$defs/ClearContextResponseType" | ||
| }, | ||
| "payload": true, | ||
| "meta": true | ||
| }, | ||
| "additionalProperties": false | ||
| } | ||
| ], | ||
| "$defs": { | ||
| "ClearContextResponseType": { | ||
| "title": "Clear Context Response Message Type", | ||
| "const": "clearContextResponse" | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.