/
RuleDefinition.vue
158 lines (158 loc) · 3.56 KB
/
RuleDefinition.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<template>
<div>
<div class="rule__area">
<div :class="[query ? 'active' : null, 'rule__container']">
<rule-empty-query :dataset="dataset" v-if="!query" />
<rule-labels-definition
v-else
:dataset="dataset"
:isSaved="saved"
@save-rule="saveRule"
@update-rule="updateCurrentRule"
>
</rule-labels-definition>
</div>
<div class="rule__metrics">
<rules-metrics
title="Rule Metrics"
metrics-type="all"
:dataset="dataset"
>
<template #button-bottom>
<re-button
class="rule__button button-quaternary--outline"
:disabled="isLoading"
@click="showRulesList"
>Manage rules</re-button
>
</template>
</rules-metrics>
</div>
</div>
</div>
</template>
<script>
import { TextClassificationDataset } from "@/models/TextClassification";
export default {
props: {
dataset: {
type: TextClassificationDataset,
required: true,
},
},
data: () => {
return {
saved: undefined,
};
},
async fetch() {
if (!this.rules) {
await this.dataset.refreshRules();
}
if (!this.hasMetrics) {
await this.dataset.refreshRulesMetrics();
}
if (!this.currentRule && this.query) {
const rule = this.dataset.findRuleByQuery(this.query, undefined);
await this.dataset.setCurrentLabelingRule(
rule ? rule : { query: this.query }
);
}
},
watch: {
async query(newValue) {
await this.dataset.setCurrentLabelingRule({ query: newValue });
},
},
computed: {
query() {
return this.dataset.query.text;
},
isLoading() {
return this.$fetchState.pending;
},
currentRule() {
return this.dataset.getCurrentLabelingRule();
},
hasMetrics() {
return this.overalMetrics && this.rulesMetrics;
},
rules() {
return this.dataset.labelingRules;
},
overalMetrics() {
return this.dataset.labelingRulesOveralMetrics;
},
rulesMetrics() {
return this.dataset.labelingRulesMetrics;
},
},
methods: {
async updateCurrentRule({ query, labels }) {
if (!query) {
return await this.dataset.clearCurrentLabelingRule();
}
if (labels) {
await this.dataset.setCurrentLabelingRule({
query,
labels,
});
} else {
await this.dataset.setCurrentLabelingRule({
query,
labels: [],
});
}
this.saved = false;
},
async showRulesList() {
await this.dataset.viewSettings.enableRulesSummary();
},
async saveRule(rule) {
await this.dataset.storeLabelingRule(rule);
this.saved = true;
},
},
};
</script>
<style lang="scss" scoped>
.rule {
&__area {
display: flex;
margin-bottom: 2em;
}
&__container {
padding: 20px;
background: rgba($lighter-color, 0.4);
border: 1px solid $lighter-color;
width: 100%;
border-radius: 5px;
&.active {
box-shadow: 0 1px 4px 0 rgba(185, 185, 185, 0.5);
}
}
&__button {
float: left;
align-self: flex-start;
margin-bottom: 0 !important;
margin-top: auto;
clear: both;
}
&__metrics {
min-width: 350px;
@include media(">desktopLarge") {
min-width: 33%;
}
&::v-deep {
.rule-metrics__container {
flex-wrap: wrap;
height: 100%;
}
.rule-metrics__item {
width: 49%;
display: inline-block;
}
}
}
}
</style>