Skip to content

Commit

Permalink
fix(ui,cdsctl): take care of not imported workflow for instance (#5085)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Mar 26, 2020
1 parent 35467e9 commit fc05887
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cli/cdsctl/template_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ func templateBulkRun(v cli.Values) error {
// filter as code workflow
wtisFiltered := make([]sdk.WorkflowTemplateInstance, 0, len(wtis))
for i := range wtis {
if wtis[i].Workflow.FromRepository == "" {
if wtis[i].Workflow == nil || wtis[i].Workflow.FromRepository == "" {
wtisFiltered = append(wtisFiltered, wtis[i])
}
}
Expand Down
10 changes: 8 additions & 2 deletions sdk/exportentities/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ func GetFormatFromContentType(ct string) (Format, error) {
func Unmarshal(btes []byte, f Format, i interface{}) error {
switch f {
case FormatJSON:
return sdk.WithStack(json.Unmarshal(btes, i))
if err := json.Unmarshal(btes, i); err != nil {
return sdk.NewErrorWithStack(err, sdk.NewErrorFrom(sdk.ErrWrongRequest, "cannot unmarshal given data as json"))
}
return nil
case FormatYAML:
return sdk.WithStack(yaml.Unmarshal(btes, i))
if err := yaml.Unmarshal(btes, i); err != nil {
return sdk.NewErrorWithStack(err, sdk.NewErrorFrom(sdk.ErrWrongRequest, "cannot unmarshal given data as yaml"))
}
return nil
}
return sdk.NewErrorFrom(sdk.ErrWrongRequest, "format is not supported")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Output,
ViewChild
} from '@angular/core';
import {ModalTemplate, SuiActiveModal, SuiModalService, TemplateModalConfig} from '@richardlt/ng2-semantic-ui';
import { ModalTemplate, SuiActiveModal, SuiModalService, TemplateModalConfig } from '@richardlt/ng2-semantic-ui';
import {
InstanceStatus,
InstanceStatusUtil,
Expand All @@ -19,11 +19,11 @@ import {
WorkflowTemplateBulkOperation,
WorkflowTemplateInstance
} from 'app/model/workflow-template.model';
import {WorkflowTemplateService} from 'app/service/workflow-template/workflow-template.service';
import {AutoUnsubscribe} from 'app/shared/decorator/autoUnsubscribe';
import {Column, ColumnType, Select} from 'app/shared/table/data-table.component';
import {Observable, Subscription} from 'rxjs';
import {finalize} from 'rxjs/internal/operators/finalize';
import { WorkflowTemplateService } from 'app/service/workflow-template/workflow-template.service';
import { AutoUnsubscribe } from 'app/shared/decorator/autoUnsubscribe';
import { Column, ColumnType, Select } from 'app/shared/table/data-table.component';
import { Observable, Subscription } from 'rxjs';
import { finalize } from 'rxjs/internal/operators/finalize';

@Component({
selector: 'app-workflow-template-bulk-modal',
Expand All @@ -33,7 +33,7 @@ import {finalize} from 'rxjs/internal/operators/finalize';
})
@AutoUnsubscribe()
export class WorkflowTemplateBulkModalComponent {
@ViewChild('workflowTemplateBulkModal', {static: false}) workflowTemplateBulkModal: ModalTemplate<boolean, boolean, void>;
@ViewChild('workflowTemplateBulkModal', { static: false }) workflowTemplateBulkModal: ModalTemplate<boolean, boolean, void>;
modal: SuiActiveModal<boolean, boolean, void>;
open: boolean;

Expand Down Expand Up @@ -154,7 +154,7 @@ export class WorkflowTemplateBulkModalComponent {
this.loadingInstances = false;
this._cd.markForCheck();
}))
.subscribe(is => this.instances = is.filter(i => !i.workflow.from_repository)
.subscribe(is => this.instances = is.filter(i => !i.workflow || !i.workflow.from_repository)
.sort((a, b) => a.key() < b.key() ? -1 : 1));

this.selectedInstanceKeys = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export class WorkflowTemplateEditComponent implements OnInit {
let status = i.status(this.workflowTemplate);

let labels = [];
if (i.workflow.from_repository) {
if (i.workflow && i.workflow.from_repository) {
labels.push({ color: 'blue', title: 'as code' });
}

Expand All @@ -171,12 +171,11 @@ export class WorkflowTemplateEditComponent implements OnInit {
}
}, <Column<WorkflowTemplateInstance>>{
type: ColumnType.BUTTON,
hidden: (i: WorkflowTemplateInstance) => !!i.workflow.from_repository,
hidden: (i: WorkflowTemplateInstance) => i.workflow && !!i.workflow.from_repository,
name: 'common_action',
class: 'two right aligned',
selector: (i: WorkflowTemplateInstance) => {
return {
hidden: !!i.workflow.from_repository,
title: 'common_update',
class: 'primary small',
click: () => {
Expand Down

0 comments on commit fc05887

Please sign in to comment.