Skip to content

Commit

Permalink
chore: Editing code while Console is opened changes the MS URL
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpmule committed Oct 26, 2023
1 parent 025e58c commit 7acc8e6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
56 changes: 54 additions & 2 deletions src/ApiRequestEditorElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,14 @@ export class ApiRequestEditorElement extends AmfHelperMixin(
this._selectedChanged();
this._updateServers();
this.readUrlData();
this.dispatchEvent(
new CustomEvent(`api-request-panel-selection-changed`, {
composed: true,
detail: {
value: this.selected,
},
})
);
}

get httpMethod() {
Expand Down Expand Up @@ -509,14 +517,18 @@ export class ApiRequestEditorElement extends AmfHelperMixin(
*/
__amfChanged(amf) {
const { urlFactory } = this;
let operationChanged = undefined;
if (urlFactory.amf) {
operationChanged = urlFactory.operation
}
if (urlFactory) {
if (!this.persistCache) {
urlFactory.clearCache();
}
urlFactory.amf = amf;
this.readUrlData();
}
this._selectedChanged();
this._selectedChanged(operationChanged);
this._updateServers();
}

Expand Down Expand Up @@ -589,9 +601,49 @@ export class ApiRequestEditorElement extends AmfHelperMixin(
});
}

_selectedChanged() {
_computeSelected(amf, operationChanged) {
if (operationChanged && amf && amf[0]) {
const opKey = this._getAmfKey(this.ns.aml.vocabularies.apiContract.supportedOperation);
const lexicalKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.lexical);
const lexicalValueKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.value);
const sourceKey = this._getAmfKey(this.ns.aml.vocabularies.docSourceMaps.sources);

const sourcesOld = this._getValueArray(operationChanged, sourceKey);
const lexicalsOld = this._getValueArray(sourcesOld[0], lexicalKey)
const lexicalValueOld = this._getValue(lexicalsOld[0], lexicalValueKey)

const encodes = this._computeEncodes(amf);
const endpoints = this._computeEndpoints(encodes);

let newOperationSelected = null
endpoints.forEach((endpoint) => {
const supportedOperation = this._ensureArray(endpoint[opKey]);
if (!supportedOperation) {
newOperationSelected = undefined
}
newOperationSelected = supportedOperation.find((operation) => {
const sources = this._getValueArray(operation, sourceKey);
const lexicals = this._getValueArray(sources[0], lexicalKey)
const lexicalValue = this._getValue(lexicals[0], lexicalValueKey)
return lexicalValue === lexicalValueOld
});

});
if (!newOperationSelected) {
return this.selected;
}

return newOperationSelected['@id'];
}
}


_selectedChanged(operationChanged) {
this.clearRequest()
const { amf, selected } = this;
if (operationChanged) {
this.selected = this._computeSelected(amf, operationChanged);
}
if (!amf || !selected) {
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ApiRequestPanelElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ export class ApiRequestPanelElement extends EventsTargetMixin(LitElement) {
this.allowCustomBaseUri = false;
this.persistCache = false;

/**
/**
* @type {TransportRequest}
*/
this.request = undefined;
/**
/**
* @type {ArcResponse|ErrorResponse}
*/
this.response = undefined;
Expand Down Expand Up @@ -434,8 +434,8 @@ export class ApiRequestPanelElement extends EventsTargetMixin(LitElement) {

/**
* Propagate `api-response` detail object.
*
* Until API Console v 6.x it was using a different response view. The current version
*
* Until API Console v 6.x it was using a different response view. The current version
* uses new response view based on ARC response view which uses different data structure.
* This function transforms the response to the one of the corresponding data types used in ARC.
* However, this keeps compatibility with previous versions of the transport library so it is
Expand Down

0 comments on commit 7acc8e6

Please sign in to comment.