microsoft-graph-toolkit icon indicating copy to clipboard operation
microsoft-graph-toolkit copied to clipboard

In all components raise an event after the component loaded its data

Open waldekmastykarz opened this issue 3 years ago • 2 comments

Proposal: In all components raise an event after the component loaded its data

Description

After the component loaded its data, raise an event so that developers can manipulate the retrieved data (sort, filter, etc.) before rendering it.

Rationale

Exposing an event after the data has been loaded with the retrieved data would allow developers to manipulate the data (sorting, filtering, etc.) before rendering. Right now, to do this, developers would need to manually retrieve the data using the Graph client and set it on the component, which unnecessarily complicates the task. Currently we have a specific event for this in mgt-get, but it would be useful in all other components as well.

Preferred Solution

Ideally, we'd extend the loadingCompleted event raised by the BaseComponent with the data retrieved by the component. The challenge is that each component stores its data in a different property. We could work around this by extending the loadState method so that it resolves its Promise with the retrieved data. Changing the return type of loadState from Promise<void> to Promise<any> shouldn't break anyone, but if I'm missing something, then we could consider an alternative approach of introducing a new protected property on the BaseComponent named data. Then, each component in its loadState implementation would assign its retrieved data to the BaseComponent.data property.

Alternatively, we could introduce a new event such as dataChange in mgt-get. The challenge with this approach would be maintaining consistency across all components and increased code maintenance effort as each component would have to implement this event separately.

Additional Context

Happy to help implement this if you're okay with the proposal.

waldekmastykarz avatar Jun 24 '21 11:06 waldekmastykarz