Skip to content

Commit

Permalink
Support for workflow version aliases (#827)
Browse files Browse the repository at this point in the history
Support workflow version aliases
  • Loading branch information
Walter Shands authored Dec 20, 2019
1 parent ee9e910 commit 7dfc899
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 6 deletions.
56 changes: 56 additions & 0 deletions cypress/integration/group2/aliases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2019 OICR
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { goToTab, isActiveTab, resetDB, setTokenUserViewPort } from '../../support/commands';

describe('Dockstore aliases', () => {
resetDB();
setTokenUserViewPort();

describe('Find workflow version by alias', () => {
it('workflow version alias', () => {
cy.server();
cy.route({
url: '*/aliases/workflow-versions/w11wv13alias',
method: 'GET',
status: 200,
response: {'fullWorkflowPath' : 'github.com/A/l', 'tagName' : 'master'}
});
cy.visit('/aliases/workflow-versions/w11wv13alias');
cy.url().should('eq', Cypress.config().baseUrl + '/workflows/github.com/A/l:master?tab=info');
});

it('invalid workflow version alias type', () => {
cy.server();
cy.visit('/aliases/foobar/fakeAlias');
cy.url().should('eq', Cypress.config().baseUrl + '/aliases/foobar/fakeAlias');
cy.contains('foobar is not a valid type');
});

it('workflow version alias incorrect', () => {
cy.server();
cy.route({
url: '*/aliases/workflow-versions/incorrectAlias',
method: 'GET',
status: 404,
response: {}
});
cy.visit('/aliases/workflow-versions/incorrectAlias');
cy.url().should('eq', Cypress.config().baseUrl + '/aliases/workflow-versions/incorrectAlias');
cy.contains('No workflow-versions with the alias incorrectAlias found');
});
});
});
13 changes: 11 additions & 2 deletions src/app/aliases/aliases.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { AliasesService } from './state/aliases.service';
import { AliasesQuery } from './state/aliases.query';
import { ActivatedRoute, Router } from '../test';
import { Observable } from 'rxjs';
import { Organization, Collection, Workflow, DockstoreTool } from '../shared/swagger';
import { Organization, Collection, Workflow, WorkflowVersionPathInfo, DockstoreTool } from '../shared/swagger';
import { Base } from '../shared/base';
import { takeUntil } from 'rxjs/operators';

Expand All @@ -17,13 +17,14 @@ export class AliasesComponent extends Base implements OnInit {
organization$: Observable<Organization | null>;
collection$: Observable<Collection | null>;
workflow$: Observable<Workflow | null>;
workflowVersionPathInfo$: Observable<WorkflowVersionPathInfo | null>;
tool$: Observable<DockstoreTool | null>;

public type: string | null;
public alias: string | null;
public validType: boolean;
// Types contains resource types that support aliases
public types = ['organizations', 'collections', 'workflows', 'tools', 'containers'];
public types = ['organizations', 'collections', 'workflows', 'tools', 'containers', 'workflow-versions'];
constructor(
private aliasesQuery: AliasesQuery,
private aliasesService: AliasesService,
Expand Down Expand Up @@ -55,6 +56,14 @@ export class AliasesComponent extends Base implements OnInit {
this.router.navigate(['/organizations', collection.organizationName, 'collections', collection.name]);
}
});
} else if (this.type === 'workflow-versions' && this.alias) {
this.aliasesService.updateWorkflowVersionPathInfoFromAlias(this.alias);
this.workflowVersionPathInfo$ = this.aliasesQuery.workflowVersionPathInfo$;
this.workflowVersionPathInfo$.pipe(takeUntil(this.ngUnsubscribe)).subscribe((workflowVersionPathInfo: WorkflowVersionPathInfo) => {
if (workflowVersionPathInfo) {
this.router.navigate(['/workflows', workflowVersionPathInfo.fullWorkflowPath + ':' + workflowVersionPathInfo.tagName]);
}
});
} else if (this.type === 'workflows' && this.alias) {
this.aliasesService.updateWorkflowFromAlias(this.alias);
this.workflow$ = this.aliasesQuery.workflow$;
Expand Down
1 change: 1 addition & 0 deletions src/app/aliases/state/aliases.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class AliasesQuery extends Query<AliasesState> {
collection$ = this.select(state => state.collection);
tool$ = this.select(state => state.tool);
workflow$ = this.select(state => state.workflow);
workflowVersionPathInfo$ = this.select(state => state.workflowVersionPathInfo);
loading$ = this.selectLoading();

constructor(protected store: AliasesStore) {
Expand Down
36 changes: 34 additions & 2 deletions src/app/aliases/state/aliases.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Injectable } from '@angular/core';
import { transaction } from '@datorama/akita';
import { finalize } from 'rxjs/operators';
import {
AliasesService as WorkflowVersionsAliasService,
Collection,
ContainersService,
DockstoreTool,
Organization,
OrganizationsService,
Workflow,
WorkflowVersionPathInfo,
WorkflowsService
} from '../../shared/swagger';
import { AliasesStore } from './aliases.store';
Expand All @@ -18,7 +20,8 @@ export class AliasesService {
private aliasesStore: AliasesStore,
private organizationsService: OrganizationsService,
private toolsService: ContainersService,
private workflowsService: WorkflowsService
private workflowsService: WorkflowsService,
private workflowVersionsService: WorkflowVersionsAliasService
) {}

clearState(): void {
Expand All @@ -28,7 +31,8 @@ export class AliasesService {
organization: null,
collection: null,
tool: null,
workflow: null
workflow: null,
workflowVersion: null
};
});
}
Expand Down Expand Up @@ -140,4 +144,32 @@ export class AliasesService {
};
});
}

@transaction()
updateWorkflowVersionPathInfoFromAlias(alias: string): void {
this.clearState();
this.aliasesStore.setLoading(true);
this.workflowVersionsService
.getWorkflowVersionPathInfoByAlias(alias)
.pipe(finalize(() => this.aliasesStore.setLoading(false)))
.subscribe(
(workflowVersionPathInfo: WorkflowVersionPathInfo) => {
this.aliasesStore.setError(false);
this.updateWorkflowVersionPathInfo(workflowVersionPathInfo);
},
() => {
this.aliasesStore.setError(true);
}
);
}

updateWorkflowVersionPathInfo(workflowVersionPathInfo: WorkflowVersionPathInfo) {
this.aliasesStore.update(state => {
return {
...state,
workflowVersionPathInfo: workflowVersionPathInfo
};
});
}

}
6 changes: 4 additions & 2 deletions src/app/aliases/state/aliases.store.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import { Injectable } from '@angular/core';
import { Store, StoreConfig } from '@datorama/akita';
import { Organization, Collection, DockstoreTool, Workflow } from '../../shared/swagger';
import {Organization, Collection, DockstoreTool, Workflow, WorkflowVersionPathInfo} from '../../shared/swagger';

export interface AliasesState {
organization: Organization | null;
collection: Collection | null;
tool: DockstoreTool | null;
workflow: Workflow | null;
workflowVersionPathInfo: WorkflowVersionPathInfo | null;
}

export function createInitialState(): AliasesState {
return {
organization: null,
collection: null,
tool: null,
workflow: null
workflow: null,
workflowVersionPathInfo: null
};
}

Expand Down

0 comments on commit 7dfc899

Please sign in to comment.