• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CenterForOpenScience / ember-osf-web / 11295496694

11 Oct 2024 03:57PM UTC coverage: 63.576% (-0.1%) from 63.697%
11295496694

Pull #2352

github

web-flow
Merge 060157a08 into 5a9af29d2
Pull Request #2352: [ENG-5879] Hide Categories Section on Registrations

2666 of 4558 branches covered (58.49%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

15 existing lines in 3 files now uncovered.

6461 of 9798 relevant lines covered (65.94%)

204.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/osf-components/addon/components/editable-field/category-manager/component.ts
1
import { tagName } from '@ember-decorators/component';
2
import Component from '@ember/component';
3
import { action, computed } from '@ember/object';
4
import { alias } from '@ember/object/computed';
5
import { inject as service } from '@ember/service';
6
import { waitFor } from '@ember/test-waiters';
7
import { task } from 'ember-concurrency';
8
import Intl from 'ember-intl/services/intl';
9
import Toast from 'ember-toastr/services/toast';
10

11
import { layout } from 'ember-osf-web/decorators/component';
12
import Node, { NodeCategory } from 'ember-osf-web/models/node';
13
import captureException, { getApiErrorMessage } from 'ember-osf-web/utils/capture-exception';
14
import template from './template';
15

16
export interface CategoryManager {
17
    save: () => void;
18
    selectedCategory: NodeCategory;
19
    category: NodeCategory;
20
    inEditMode: boolean;
21
}
22

23
@tagName('')
24
@layout(template)
25
export default class CategoryManagerComponent extends Component {
26
    // required
27
    node!: Node;
28

29
    // private
30
    @service intl!: Intl;
31
    @service toast!: Toast;
32

UNCOV
33
    inEditMode = false;
×
UNCOV
34
    fieldIsEmpty = false;
×
35
    selectedCategory!: NodeCategory;
36

37
    @alias('node.userHasWritePermission') userCanEdit!: boolean;
38
    @alias('node.category') category!: NodeCategory;
39

40
    @computed('fieldIsEmpty', 'userCanEdit')
41
    get shouldShowField() {
UNCOV
42
        return this.userCanEdit || !this.fieldIsEmpty;
×
43
    }
44

45
    @task
46
    @waitFor
47
    async save() {
UNCOV
48
        this.node.set('category', this.selectedCategory);
×
UNCOV
49
        try {
×
UNCOV
50
            await this.node.save();
×
51
        } catch (e) {
52
            this.node.rollbackAttributes();
×
53
            const errorMessage = this.intl.t('registries.registration_metadata.edit_category.error');
×
54
            captureException(e, { errorMessage });
×
55
            this.toast.error(getApiErrorMessage(e), errorMessage);
×
56
            throw e;
×
57
        }
UNCOV
58
        this.set('inEditMode', false);
×
UNCOV
59
        this.toast.success(this.intl.t('registries.registration_metadata.edit_category.success'));
×
60
    }
61

62
    didReceiveAttrs() {
UNCOV
63
        if (this.node) {
×
UNCOV
64
            this.setProperties({ selectedCategory: this.node.category });
×
65
        }
66
    }
67

68
    @action
69
    startEditing() {
UNCOV
70
        this.set('inEditMode', true);
×
71
    }
72

73
    @action
74
    onSelect(category: NodeCategory) {
UNCOV
75
        this.set('selectedCategory', category);
×
76
    }
77

78
    @action
79
    cancel() {
80
        this.set('selectedCategory', this.node.category);
×
81
        this.set('inEditMode', false);
×
82
    }
83
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc