I can share how I've solved this, although I'll caution I'm not sure it's the best way.
I'm using a similar pattern to how you started with the DataSource:
{<DataSourceComponent widgetId={this.props.id} useDataSource={this.props.useDataSources[0]}
onDataSourceCreated={this.onDs}
onDataSourceInfoChange={this.dataChanged}
queryCount>
{this.layerHandler}
</DataSourceComponent>}
onDataSourceInfoChange will be triggered when interacting with the data. I believe any widget you've setup within the Builder that listens for Selection change within the framework should trigger this. So a selection drawn in the map widget, or you could manually perform the selection on the datasource in your first widget code. Eg.
this.state.datasource.selectRecordById(oid) //from the selecting widget, not the recieving widget
From the widget you want to react to the selection change....(the widget with the 1st datasource code above) ..... in my case I'm calling into dataChanged - See the 2 test cases I have here:
dataChanged = (info: IMDataSourceInfo) =>{
console.log("imdatasource status", info)
if (this.state.datasource){
if (this.state.datasource.getStatus() == "LOADED"){
let r = this.state.datasource.getSelectedRecords()
console.log("SELECTED RECORDS:", r)
}
}
if (info.selectedIds){
console.log("info ids: ", info.selectedIds)
this.selectedSite([info.selectedIds[0]])
}
}
My selected records in the first branch always comes up with an empty array. (I point this out as I would have expected the datasource to have the selection here, but it doesn't. Thus why I'm cautioning this might not be the best way). However, within the second branch info.selectedIds - when there is a selection, I can get the OID of the feature from that.
Once you have the OID, simply carry on with what you're doing. In my case, I need to get more attributes from the selected feature:
selectedSite = (oid_facname) =>{
const oid = oid_facname[0];
//const fac_name = oid_facname[1];
//const fac_id = oid_facname[2];
if (this.state.datasource && this.state.datasource.getStatus() == "LOADED"){
if (oid){
this.state.datasource.selectRecordById(oid)
const fac_name = this.state.datasource.getRecords()[0].feature.attributes['facility_name_location']
Alternatively, you could broadcast the OID or attributes of your selected feature and have the 2nd widget listen for that. Check the widget communication help to see this pattern. I only offer this up as another idea, I don't know if it'd be suitable for your widgets....