Skip to content

Commit

Permalink
better handling of undo operations resulting in changes to the curren…
Browse files Browse the repository at this point in the history
…t selection
  • Loading branch information
EricWittmann committed Jun 12, 2017
1 parent b28fd2d commit 85323ae
Showing 1 changed file with 54 additions and 11 deletions.
65 changes: 54 additions & 11 deletions front-end/app/studio/pages/apis/{apiId}/editor/editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,29 +153,22 @@ export class ApiEditorComponent {
protected validateSelection(): void {
if (this.selectedType === "path") {
let pathItem: Oas20PathItem = this.selectedItem as Oas20PathItem;
if (!(this.selectedItem && this.document().paths && this.document().paths.pathItem(pathItem.path()))) {
if (!this.isValidPathItem(pathItem)) {
this.selectMain();
} else {
}
} else if (this.selectedType === "operation") {
let operation: Oas20Operation = this.selectedItem as Oas20Operation;
let pathItem: Oas20PathItem = operation.parent() as Oas20PathItem;
if (!(this.selectedItem && this.document().paths && this.document().paths.pathItem(pathItem.path()))) {
if (!this.isValidOperation(operation)) {
this.selectMain();
} else {
let pathItem: Oas20PathItem = this.document().paths.pathItem(this.selectedItem);
if (!pathItem[operation.method()]) {
this.selectPath(pathItem);
}
}
} else if (this.selectedType === "definition") {
let definition: Oas20DefinitionSchema = this.selectedItem as Oas20DefinitionSchema;
if (!(this.selectedItem && this.document().definitions && this.document().definitions.definition(definition.definitionName()))) {
if (!this.isValidDefinition(definition)) {
this.selectMain();
}
} else if (this.selectedType === "response") {
let response: Oas20ResponseDefinition = this.selectedItem as Oas20ResponseDefinition;
if (!(this.selectedItem && this.document().responses && this.document().responses.response(response.name()))) {
if (!this.isValidResponse(response)) {
this.selectMain();
}
} else if (this.selectedType === "problem") {
Expand All @@ -185,6 +178,56 @@ export class ApiEditorComponent {
}
}

protected isValidPathItem(pathItem: Oas20PathItem): boolean {
if (ObjectUtils.isNullOrUndefined(pathItem)) {
return false;
}
if (ObjectUtils.isNullOrUndefined(this.document().paths)) {
return false;
}
let pi: any = this.document().paths.pathItem(pathItem.path());
return pi === pathItem;
}

protected isValidOperation(operation: Oas20Operation): boolean {
let pathItem: Oas20PathItem = operation.parent() as Oas20PathItem;

if (ObjectUtils.isNullOrUndefined(operation)) {
return false;
}

if (!this.isValidPathItem(pathItem)) {
return false;
}

let pi: any = this.document().paths.pathItem(pathItem.path());
let op: any = pi[operation.method()];

return op === operation;
}

protected isValidDefinition(definition: Oas20DefinitionSchema): boolean {
if (ObjectUtils.isNullOrUndefined(definition)) {
return false;
}
if (ObjectUtils.isNullOrUndefined(this.document().definitions)) {
return false;
}
let def: any = this.document().definitions.definition(definition.definitionName());
return def === definition;
}

protected isValidResponse(response: Oas20ResponseDefinition): boolean {
if (ObjectUtils.isNullOrUndefined(response)) {
return false;
}
if (ObjectUtils.isNullOrUndefined(this.document().responses)) {
return false;
}
let resp: any = this.document().responses.response(response.name());
return resp === response;
}

/**
* Called when the user selects the main/default element from the master area.
*/
Expand Down

0 comments on commit 85323ae

Please sign in to comment.