Skip to content
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

Reset context #301

Closed
Tracked by #802 ...
pgn-vole opened this issue Jan 22, 2021 · 13 comments
Closed
Tracked by #802 ...

Reset context #301

pgn-vole opened this issue Jan 22, 2021 · 13 comments
Labels
api FDC3 API Working Group channels feeds & transactions Channels, Feeds & Transactions Discussion Group

Comments

@pgn-vole
Copy link

pgn-vole commented Jan 22, 2021

Question Area

[ ] App Directory
[ X] API
[ ] Context Data
[ ] Intents
[ ] Use Cases
[ ] Other

Question

Reseting context to an initial value doesn't seem to be covered in the API. A typical use case is when context is used as filter and the user disable filters. Any applications listening to that context should, I believe, be aware of that filtering beeing disabled.

console.log(fdc3.getCurrentContext()) // `null`, nothing whas been broadcasted yet

//User select an instrument
fdc3.broadcast({  type: 'fdc3.instrument', id: {  ric: 'VOD.L' }})

//User unselect instrument
?

In the above use case, how can an application reponsible of controlling the filters, reset the instrument context to null ?

@rikoe
Copy link
Contributor

rikoe commented Jan 28, 2021

@pgn-vole can't you just broadcast null?

@kriswest
Copy link
Contributor

kriswest commented Jan 28, 2021 via email

@pgn-vole
Copy link
Author

pgn-vole commented Jan 29, 2021

@pgn-vole can't you just broadcast null?

The signature of addContextListener doesnt't allow the context to be null so at the moment, unless by diverging from the specification, we can't do that.

Morever by simply dispatching a null context we miss one use case: How can a consumer of a specific context type capture that the context has been nulified?
Example of that use case:

fdc3.addContextListener('fd3.instrument', () => {
  // I wish to reset the UI when an instrument is unselected
})

I thought of 2 solutions:

Solution 1

Like @kriswest suggestion, one could broadcast an instrument property with "null" properties:

publisher:

fdc3.broadcast({
  type: 'fdc3.instrument',
  id: null,
})

consumer:

fdc3.addContextListener('fd3.instrument', (context) => {
   if (context.id === null) {
     //reset the UI
   }
})

That's an easy solution, which works with current API spec. The context shape specification would have to be modified to allow the id propertyt to be null though.

Solution 2

An alternative solution would be to broadcast a null context by extending the signature of broadcast and addContextListener.

addContextListener: Would allow the context argument to be null
broadcast: Would allow to hint the type via a parameter instead of relying on the type property.

publisher:

fdc3.broadcast('fdc3.instrument',null)

consumer:

fdc3.addContextListener('fd3.instrument', (context) => {
   if (context === null) {
     //reset the UI
   }
})

@rikoe rikoe added this to the 2.0 milestone Mar 25, 2021
@rikoe rikoe added the api FDC3 API Working Group label Mar 25, 2021
@kriswest
Copy link
Contributor

As per comments on #361 we might be better served to create a NullContext context for this. We wouldn't have to change any API signatures, it has other potential uses and you can filter for it as a context type (so you can choose to process it or ignore it).

@pgn-vole
Copy link
Author

It should do the job and is backward compatible so sounds goo to me!

@rikoe
Copy link
Contributor

rikoe commented Apr 23, 2021

So what would this look like? { "type": "fdc3.nullContext" } or { "type": "fdc3.empty" } or something like that?

If so, I think we should raise a PR for this and get it added to the standardised context types. @pgn-vole would you be willing to do that? (Especially taking care of adding to the docs and published json schemas.)

@rikoe rikoe modified the milestones: 2.0-candidates, 2.0 Apr 23, 2021
@pgn-vole
Copy link
Author

pgn-vole commented Apr 23, 2021

Happy to take ownership.

{ "type": "fdc3.nullContext" } looks good to me.
However I think that we need to add be able to anotate which type of context was nullified because channels can hold multiple contexts of various types .

Given a scenario:

  • 2 contexts are assigned to a channel : fdc3.instrument and fdc3.contact
  • a intrument picker wish to reset the currently viewed instrument by dispatching a null context.
  • a "contact context" consumer wants to ignore the reset of the instrument context because it it is only interested by contacts.

To support that scenario we could augment the null context model to add a context type that has to be nullified:

{
  "type": "fdc3.nullContext,
  "name": "<contextType>" 
}

Example usage:

Instrument context consumer

fdc3.addContextListener((context) => {
  if (context.type === 'fdc3.nullContext' && context.name === 'fdc3.instrument') { 
    resetInstrumentView()
  }
})
fdc3.addContextListener((context) => {
  if (context.type === 'fdc3.nullContext') {
    updateInstrumentView(context)
  }
})

Contact context consumer

fdc3.addContextListener('fdc3.nullContext', (context) => {
  if (context.name === 'fdc3.contact') { 
    resetContactView()
  }
})
fdc3.addContextListener('fdc3.contact', (context) => {
  updateContactView(context)
})

Without that anotation, given the above scenario, the instrument and contact context consumers would not be able to know whether they should reset their UI.

@kriswest
Copy link
Contributor

Good point @pgn-vole, if you had added a typed context listener, e.g.:

const contactListener = fdc3.addContextListener('fdc3.contact', contact => { ... });

then you would not receive the NullContext at all.

Can you refine your use-case description to confirm the need for a per-type reset (e.g. of a filter)? We should be careful to stick to real-world use-cases with examples so that we don't complicate the standard needlessly. Hence, do you anticipate resets of just a particular type in a real-world scenario, rather than just a reset of the channel as a whole?

If we end up confirming that a per-type reset is needed, then I'd rather not use the name field to indicate type. Rather, it should be a field that can support referencing multiple types (if you can reset one, why not more than one), OR (to support typed listeners) we should consider using an Object of the type you wish to reset with a particular id value (it has to be an object in the context schema, but we could modify the context schema to allow it to also be a NullContext or other value to indicate the reset.

Thoughts?

I'll submit a PR shortly for #361 that will define a NullContext schema that you could reference.

@kriswest
Copy link
Contributor

See #375 for the Null context type

@kriswest kriswest added the channels feeds & transactions Channels, Feeds & Transactions Discussion Group label Jun 4, 2021
@kriswest
Copy link
Contributor

kriswest commented Jul 13, 2021

A Standards Working Group vote is needed on this issue; there are two options to choose from, or the issue can be closed.

Options

  1. (🎉) Use the fdc3.nothing type to reset the last context on the channel AND allow an additional field to specify a particular type to reset, e.g. {type: 'fdc3.nothing', subType: 'fdc3.contact'}
  2. (🚀) use the fdc3.nothing type to reset the last context on the channel AND allow context types to be transmitted with an a null id to reset that type. Hence, context schema changes such that:
      "id": {
        "type": "object",
        "additionalProperties": { "type": "string" }
      }
    changes to:
      "id": {
         "type": ["object","null"]
         "additionalProperties": { "type": "string" }
       }
  3. (👎 ) Close issue and do not allow context on a channel to be reset

Please vote with 🎉 for option 1, 🚀 for option 2. and 👎 to close the issue. The vote will be kept open until a few days after the next SWG meeting (Thursday 22nd July 2021).

@pgn-vole
Copy link
Author

Thanks for the proposal Kris. To revert to your question about real world use case - this is about filters. At the moment there is no obvious way for UIs to sync up their states upon reset of a particular context type (i.e clear up Client filter while keeping Instruments one enabled).

Considering that they are opening in modify the shape of FDC3 Contexts, I would suggest a "2.b" option which in my view is a mix of both world:

  • Allow context types to be transmitted with an a null id to reset that type. Hence, context schema changes such that:
  "id": {
     "type": ["object","null"]
     "additionalProperties": { "type": "string" }
   }

This would allow to not touch the context listener method signature while allowing contexts, of specific type, to be reset without the need to introduce a dedicated context type for that single purpose.

@rikoe rikoe modified the milestones: 2.0, 2.0-candidates Jul 21, 2021
@kriswest kriswest added the needs-vote Please vote on this issue label Jul 22, 2021
@kriswest kriswest removed this from the 2.0-candidates milestone Sep 23, 2021
@kriswest
Copy link
Contributor

After the last SWG meeting (#459), and based on the informal votes received, it was decided to remove this issue from the FDC3 2.0 milestone - but not to close it to allow discussion to continue or a PR to be submitted for consideration.

@kriswest
Copy link
Contributor

kriswest commented Dec 5, 2022

Given the workarounds available and the lack of an appetite to add API functionality to enable this use case by other means, the decions was taken at meeting #867 to close this issue. See the meeting minutes for further info:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api FDC3 API Working Group channels feeds & transactions Channels, Feeds & Transactions Discussion Group
Projects
None yet
Development

No branches or pull requests

3 participants