Skip to content

Commit 8cd6df8

Browse files
leiyredamianpumar
andauthored
Assign field to a span question (#5717)
This PR includes a new component for assigning a field to the span question in the dataset creation configuration Closes #5715 --------- Co-authored-by: Damián Pumar <[email protected]>
1 parent 7733ad5 commit 8cd6df8

File tree

15 files changed

+333
-121
lines changed

15 files changed

+333
-121
lines changed

argilla-frontend/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ These are the section headers that we use:
2424

2525
### Fixed
2626

27+
- Assign field to span question on dataset creation. ([#5717](https://github.com/argilla-io/argilla/pull/5717))
2728
- Fixed visible_options when updating question setting. ([#5716](https://github.com/argilla-io/argilla/pull/5716))
2829
- Fixed highlighting on same record ([#5693](https://github.com/argilla-io/argilla/pull/5693))
2930

argilla-frontend/components/features/annotation/container/questions/form/span/EntityLabelSelection.component.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ export default {
7373
props: {
7474
maxOptionsToShowBeforeCollapse: {
7575
type: Number,
76-
required: true,
7776
},
7877
options: {
7978
type: Array,
@@ -165,21 +164,24 @@ export default {
165164
},
166165
remainingVisibleOptions() {
167166
return this.filteredOptions
168-
.slice(this.maxOptionsToShowBeforeCollapse)
167+
.slice(this.maxVisibleOptions)
169168
.filter((option) => option.isSelected);
170169
},
171170
visibleOptions() {
172171
if (this.isExpanded) return this.filteredOptions;
173172
174173
return this.filteredOptions
175-
.slice(0, this.maxOptionsToShowBeforeCollapse)
174+
.slice(0, this.maxVisibleOptions)
176175
.concat(this.remainingVisibleOptions);
177176
},
177+
maxVisibleOptions() {
178+
return this.maxOptionsToShowBeforeCollapse ?? this.options.length + 1;
179+
},
178180
numberToShowInTheCollapseButton() {
179181
return this.filteredOptions.length - this.visibleOptions.length;
180182
},
181183
showCollapseButton() {
182-
return this.filteredOptions.length > this.maxOptionsToShowBeforeCollapse;
184+
return this.filteredOptions.length > this.maxVisibleOptions;
183185
},
184186
showSearch() {
185187
return (
@@ -284,7 +286,7 @@ export default {
284286
expandLabelsOnTab(index) {
285287
if (!this.showCollapseButton) return;
286288
287-
if (index === this.maxOptionsToShowBeforeCollapse - 1) {
289+
if (index === this.maxVisibleOptions - 1) {
288290
this.isExpanded = true;
289291
}
290292
},

argilla-frontend/components/features/annotation/settings/Validation.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class="--error-message"
77
v-for="error in validations"
88
:key="error"
9-
v-html="error"
9+
v-html="$t(error)"
1010
/>
1111
</template>
1212
</div>

argilla-frontend/components/features/dataset-creation/configuration/DatasetConfigurationForm.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,10 @@
9090
<DatasetConfigurationQuestion
9191
v-for="question in dataset.selectedSubset.questions"
9292
:key="question.name"
93+
:selectedSubset="dataset.selectedSubset"
9394
:question="question"
94-
:columns="dataset.selectedSubset.columns"
9595
:remove-is-allowed="true"
9696
:available-types="availableQuestionTypes"
97-
@remove="dataset.selectedSubset.removeQuestion(question.name)"
9897
@change-type="onTypeIsChanged(question.name, $event)"
9998
@is-focused="isFocused = $event"
10099
/>
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<template>
2+
<BaseDropdown
3+
class="column-selector"
4+
:visible="dropdownIsVisible"
5+
@visibility="onVisibility"
6+
>
7+
<template slot="dropdown-header">
8+
<svgicon name="assign" height="12" />
9+
{{ $t("datasetCreation.applyToaAField") }}
10+
<span
11+
v-if="options.length"
12+
class="column-selector__chip"
13+
v-text="value"
14+
/>
15+
</template>
16+
<template slot="dropdown-content">
17+
<span class="column-selector__options__intro" v-text="$t('field')" />
18+
<ul class="column-selector__options">
19+
<li
20+
:class="
21+
option === value
22+
? 'column-selector__option--selected'
23+
: 'column-selector__option'
24+
"
25+
v-for="(option, index) in filteredOptions"
26+
:key="index"
27+
@click="selectOption(option)"
28+
>
29+
{{ option?.name ?? option }}
30+
</li>
31+
</ul>
32+
</template>
33+
</BaseDropdown>
34+
</template>
35+
36+
<script>
37+
import "assets/icons/assign";
38+
export default {
39+
props: {
40+
value: {
41+
type: [Object, String],
42+
required: true,
43+
},
44+
options: {
45+
type: Array,
46+
required: true,
47+
},
48+
},
49+
model: {
50+
prop: "value",
51+
event: "onValueChange",
52+
},
53+
data() {
54+
return {
55+
dropdownIsVisible: false,
56+
};
57+
},
58+
computed: {
59+
filteredOptions() {
60+
return this.options.filter(
61+
(option) => JSON.stringify(option) !== JSON.stringify(this.value)
62+
);
63+
},
64+
optionNames() {
65+
return this.options.map((option) => option.name);
66+
},
67+
},
68+
methods: {
69+
onVisibility(value) {
70+
this.dropdownIsVisible = value;
71+
},
72+
selectOption(option) {
73+
this.$emit("onValueChange", option.name);
74+
75+
this.dropdownIsVisible = false;
76+
},
77+
},
78+
};
79+
</script>
80+
<style lang="scss" scoped>
81+
.column-selector {
82+
user-select: none;
83+
font-weight: 400;
84+
85+
:deep(.dropdown__header) {
86+
display: flex;
87+
gap: $base-space;
88+
flex-wrap: wrap;
89+
min-height: $base-space * 4;
90+
border: none;
91+
color: var(--fg-cuaternary);
92+
&:hover {
93+
background: none;
94+
}
95+
}
96+
97+
:deep(.dropdown__content) {
98+
bottom: 0;
99+
top: auto;
100+
right: auto;
101+
min-width: 140px;
102+
}
103+
104+
&__options {
105+
min-width: 100%;
106+
list-style: none;
107+
padding: calc($base-space / 2);
108+
margin: 0;
109+
max-height: 120px;
110+
overflow-y: auto;
111+
&__intro {
112+
display: block;
113+
padding: 2px;
114+
font-weight: 300;
115+
}
116+
}
117+
&__chip {
118+
padding: calc($base-space / 2) $base-space;
119+
border-radius: $border-radius-m;
120+
background: var(--bg-accent-grey-1);
121+
color: var(--fg-cuaternary);
122+
@include font-size(12px);
123+
}
124+
&__option {
125+
padding: calc($base-space / 2);
126+
border-radius: $border-radius;
127+
transition: all 0.2s ease-in;
128+
width: max-content;
129+
min-width: 100%;
130+
cursor: pointer;
131+
&:hover {
132+
background: var(--bg-opacity-4);
133+
transition: all 0.2s ease-out;
134+
}
135+
&--selected {
136+
background: var(--bg-opacity-4);
137+
@extend .column-selector__option;
138+
}
139+
}
140+
.svg-icon {
141+
flex-shrink: 0;
142+
}
143+
}
144+
</style>

argilla-frontend/components/features/dataset-creation/configuration/questions/DatasetConfigurationLabels.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
33
<div
4-
:class="{ '--error': errors.length }"
4+
:class="{ '--error': errors.options?.length }"
55
class="dataset-config-label__input-container"
66
>
77
<input
@@ -14,7 +14,7 @@
1414
class="dataset-config-label__input"
1515
/>
1616
</div>
17-
<Validation v-if="errors.length" :validations="translatedValidations" />
17+
<Validation v-if="errors.options?.length" :validations="errors.options" />
1818
<label
1919
v-else
2020
class="dataset-config-label__label"
@@ -29,7 +29,7 @@
2929
export default {
3030
data() {
3131
return {
32-
errors: [],
32+
errors: {},
3333
isDirty: false,
3434
};
3535
},
@@ -47,11 +47,6 @@ export default {
4747
optionsJoinedByCommas() {
4848
return this.question.options.map((item) => item.text).join(",");
4949
},
50-
translatedValidations() {
51-
return this.errors.map((validation) => {
52-
return this.$t(validation);
53-
});
54-
},
5550
},
5651
methods: {
5752
validateOptions() {

argilla-frontend/components/features/dataset-creation/configuration/questions/DatasetConfigurationQuestion.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<DatasetConfigurationSpan
2626
v-else-if="question.settings.type.isSpanType"
2727
:question="question"
28+
:textFields="selectedSubset.textFields"
2829
@is-focused="$emit('is-focused', $event)"
2930
/>
3031
<DatasetConfigurationRating
@@ -42,7 +43,7 @@
4243
<DatasetConfigurationColumnSelector
4344
v-if="showColumnSelector"
4445
class="config-card__type"
45-
:options="columns"
46+
:options="selectedSubset.columns"
4647
v-model="question.column"
4748
/>
4849
<BaseCheckbox
@@ -63,8 +64,8 @@ export default {
6364
type: Object,
6465
required: true,
6566
},
66-
columns: {
67-
type: Array,
67+
selectedSubset: {
68+
type: Object,
6869
required: true,
6970
},
7071
removeIsAllowed: {
@@ -90,7 +91,7 @@ export default {
9091
},
9192
methods: {
9293
remove() {
93-
this.$emit("remove");
94+
this.selectedSubset.removeQuestion(this.question.name);
9495
},
9596
},
9697
};

argilla-frontend/components/features/dataset-creation/configuration/questions/DatasetConfigurationRating.vue

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
33
<div
4-
:class="{ '--error': errors.length }"
4+
:class="{ '--error': errors.options?.length }"
55
class="dataset-config-rating__input-container"
66
>
77
<input
@@ -21,15 +21,15 @@
2121
class="dataset-config-rating__input"
2222
/>
2323
</div>
24-
<Validation v-if="errors.length" :validations="translatedValidations" />
24+
<Validation v-if="errors.options?.length" :validations="errors.options" />
2525
</div>
2626
</template>
2727

2828
<script>
2929
export default {
3030
data() {
3131
return {
32-
errors: [],
32+
errors: {},
3333
isDirty: false,
3434
};
3535
},
@@ -43,13 +43,6 @@ export default {
4343
default: "",
4444
},
4545
},
46-
computed: {
47-
translatedValidations() {
48-
return this.errors.map((validation) => {
49-
return this.$t(validation);
50-
});
51-
},
52-
},
5346
methods: {
5447
validateOptions() {
5548
this.errors = this.question.validate();

0 commit comments

Comments
 (0)