Passed
Push — trunk ( 1e6832...69518a )
by Christian
12:33 queued 13s
created

index.js ➔ debouncedOnChange   F

Complexity

Conditions 16

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
eloc 2
dl 0
loc 3
rs 2.4
c 0
b 0
f 0

How to fix   Complexity   

Complexity

Complex classes like index.js ➔ debouncedOnChange often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
import template from './sw-cms-block-config.html.twig';
2
import './sw-cms-block-config.scss';
3
4
const { Mixin, Utils } = Shopware;
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
5
6
/**
7
 * @private
8
 * @package content
9
 */
10
export default {
11
    template,
12
13
    inject: [
14
        'repositoryFactory',
15
        'cmsService',
16
    ],
17
18
    mixins: [
19
        Mixin.getByName('cms-state'),
20
    ],
21
22
    props: {
23
        block: {
24
            type: Object,
25
            required: true,
26
        },
27
    },
28
29
    computed: {
30
        uploadTag() {
31
            return `cms-block-media-config-${this.block.id}`;
32
        },
33
34
        mediaRepository() {
35
            return this.repositoryFactory.create('media');
36
        },
37
38
        cmsPageState() {
39
            return Shopware.State.get('cmsPageState');
0 ignored issues
show
Bug introduced by
The variable Shopware seems to be never declared. If this is a global, consider adding a /** global: Shopware */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
40
        },
41
42
        cmsBlocks() {
43
            return this.cmsService.getCmsBlockRegistry();
44
        },
45
46
        blockConfig() {
47
            return this.cmsBlocks[this.block.type];
48
        },
49
50
        quickactionsDisabled() {
51
            return !this.isSystemDefaultLanguage || this.blockConfig.removable === false;
52
        },
53
54
        quickactionClasses() {
55
            return {
56
                'is--disabled': this.quickactionsDisabled,
57
            };
58
        },
59
    },
60
61
    methods: {
62
        onSetBackgroundMedia([mediaItem]) {
63
            this.block.backgroundMediaId = mediaItem.id;
64
            this.block.backgroundMedia = mediaItem;
65
        },
66
67
        successfulUpload(media) {
68
            this.block.backgroundMediaId = media.targetId;
69
70
            this.mediaRepository.get(media.targetId).then((mediaItem) => {
71
                this.block.backgroundMedia = mediaItem;
72
            });
73
        },
74
75
        removeMedia() {
76
            this.block.backgroundMediaId = null;
77
            this.block.backgroundMedia = null;
78
        },
79
80
        onBlockDelete() {
81
            if (this.quickactionsDisabled) {
82
                return;
83
            }
84
85
            this.$emit('block-delete', this.block);
86
        },
87
88
        onBlockDuplicate() {
89
            if (this.quickactionsDisabled) {
90
                return;
91
            }
92
93
            this.$emit('block-duplicate', this.block);
94
        },
95
96
        onBlockNameChange: Utils.debounce(function debouncedOnChange(value) {
97
            this.block.name = value;
98
        }, 400),
99
    },
100
};
101