Skip to content

Commit 92b4738

Browse files
committed
Create TagInput component and replace Buefy Taginput
1 parent a8740b2 commit 92b4738

File tree

10 files changed

+228
-90
lines changed

10 files changed

+228
-90
lines changed

.github/config/.finnishwords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ löydy
216216
löytää
217217
löytävät
218218
löytynyt
219+
luettelo
219220
luku
220221
lukuoikeus
221222
luo
@@ -496,6 +497,7 @@ tulisi
496497
tuloksia
497498
tunniste
498499
tunnisteet
500+
tunnisteista
499501
tunnisteita
500502
tunnukselle
501503
tunnuksen

swift_browser_ui_frontend/src/common/conv.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export function makeGetObjectsMetaURL(project, container, objects) {
228228
}
229229

230230
export const taginputConfirmKeys = [",", ";", ":", ".", " ", "Tab", "Enter"];
231+
export const taginputConfirmKeyCodes = [9, 13, 186, 188];
231232

232233
export function truncate(value, length) {
233234
if (!value) {

swift_browser_ui_frontend/src/common/globalFunctions.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import store from "@/common/store";
2+
import { taginputConfirmKeyCodes } from "@/common/conv";
23

34
export function toggleCreateFolderModal(folderName) {
45
store.commit("toggleCreateFolderModal", true);
@@ -69,5 +70,22 @@ export async function getAccessDetails (
6970
: [];
7071
}
7172

73+
export function addNewTag (event, currentTags, onBlur) {
74+
if (taginputConfirmKeyCodes.includes(event.keyCode) || onBlur) {
75+
event.preventDefault();
76+
const newTag = event.target.value.trim();
77+
event.target.value = "";
78+
if (newTag !== "" && !currentTags.includes(newTag)) {
79+
currentTags.push(newTag);
80+
}
81+
}
82+
return currentTags;
83+
}
84+
85+
export function deleteTag (event, tag, currentTags) {
86+
event.preventDefault();
87+
return currentTags.filter(el => el !== tag);
88+
}
89+
7290

7391

swift_browser_ui_frontend/src/common/lang.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,9 @@ let default_translations = {
487487
list_of_shareids: "list of share ids",
488488
folder_tabs: "different types of folder",
489489
searchbox: "search for folders",
490+
tagsList: "list of tags",
490491
edit_tag: "modify current tags",
492+
delete_tag: "delete tag",
491493
footer: "copyright information",
492494
},
493495
},
@@ -962,7 +964,9 @@ let default_translations = {
962964
list_of_shareids: "lista jaa tunnuksista",
963965
folder_tabs: "erityyppisiä kansioita",
964966
searchbox: "etsi kansioita",
967+
tagsList: "luettelo tunnisteista",
965968
edit_tag: "muokata nykyisiä tunnisteita",
969+
delete_tag: "poista tunniste",
966970
footer: "tekijänoikeustiedot",
967971
},
968972
},

swift_browser_ui_frontend/src/components/CopyFolderModal.vue

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,15 @@
2828
:loading="loadingFoldername"
2929
/>
3030
</b-field>
31-
<b-field
32-
custom-class="has-text-dark"
33-
:label="$t('message.tagName')"
34-
label-for="copy-folder-taginput"
35-
>
36-
<b-taginput
37-
id="copy-folder-taginput"
38-
v-model="tags"
39-
ellipsis
40-
maxlength="20"
41-
has-counter
42-
rounded
43-
type="is-primary"
44-
:placeholder="$t('message.tagPlaceholder')"
45-
:confirm-keys="taginputConfirmKeys"
46-
:on-paste-separators="taginputConfirmKeys"
47-
/>
48-
</b-field>
31+
<label label-for="copy-folder-taginput">
32+
{{ $t('message.tagName') }}
33+
</label>
34+
<TagInput
35+
id="copy-folder-taginput"
36+
:tags="tags"
37+
@addTag="addingTag"
38+
@deleteTag="deletingTag"
39+
/>
4940
</c-card-content>
5041
</div>
5142
<c-card-actions justify="space-between">
@@ -73,24 +64,28 @@
7364
import { debounce, delay } from "lodash";
7465
import {
7566
swiftCopyContainer,
76-
taginputConfirmKeys,
7767
updateContainerMeta,
7868
} from "@/common/api";
7969
80-
import { modifyBrowserPageStyles } from "@/common/globalFunctions";
70+
import {
71+
addNewTag,
72+
deleteTag,
73+
modifyBrowserPageStyles,
74+
} from "@/common/globalFunctions";
8175
import escapeRegExp from "lodash/escapeRegExp";
8276
import { useObservable } from "@vueuse/rxjs";
8377
import { liveQuery } from "dexie";
78+
import TagInput from "@/components/TagInput.vue";
8479
8580
export default {
8681
name: "CopyFolderModal",
82+
components: { TagInput },
8783
data() {
8884
return {
8985
folderExists: false,
9086
folderName: "",
9187
loadingFoldername: true,
9288
tags: [],
93-
taginputConfirmKeys,
9489
folders: [],
9590
};
9691
},
@@ -256,6 +251,12 @@ export default {
256251
);
257252
});
258253
},
254+
addingTag: function (e, onBlur) {
255+
this.tags = addNewTag(e, this.tags, onBlur);
256+
},
257+
deletingTag: function (e, tag) {
258+
this.tags = deleteTag(e, tag, this.tags);
259+
},
259260
},
260261
};
261262
</script>
@@ -296,11 +297,16 @@ c-card-content {
296297
padding: 0;
297298
}
298299
300+
label {
301+
font-weight: bold;
302+
margin-bottom: -1rem;
303+
}
304+
299305
c-card-actions {
300306
padding: 0;
301307
}
302308
303309
c-card-actions > c-button {
304310
margin: 0;
305311
}
306-
</style>
312+
</style>

swift_browser_ui_frontend/src/components/CreateFolderModal.vue

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,16 @@
2424
data-testid="folder-name"
2525
/>
2626
</b-field>
27-
<b-field
28-
custom-class="has-text-dark"
29-
:label="$t('message.tagName')"
30-
label-for="folder-taginput"
31-
>
32-
<b-taginput
33-
id="folder-taginput"
34-
v-model="tags"
35-
aria-close-label="delete-tag"
36-
ellipsis
37-
maxlength="20"
38-
has-counter
39-
rounded
40-
type="is-primary"
41-
:placeholder="$t('message.tagPlaceholder')"
42-
:confirm-keys="taginputConfirmKeys"
43-
:on-paste-separators="taginputConfirmKeys"
44-
data-testid="folder-tag"
45-
/>
46-
</b-field>
27+
<label label-for="create-folder-taginput">
28+
{{ $t('message.tagName') }}
29+
</label>
30+
<TagInput
31+
id="create-folder-taginput"
32+
:tags="tags"
33+
data-testid="folder-tag"
34+
@addTag="addingTag"
35+
@deleteTag="deletingTag"
36+
/>
4737
<p class="info-text is-size-6">
4838
{{ $t("message.container_ops.createdFolder") }}
4939
<b>{{ active.name }}</b>.
@@ -87,12 +77,16 @@ import {
8777
} from "@/common/conv";
8878
8979
import {
80+
addNewTag,
81+
deleteTag,
9082
modifyBrowserPageStyles,
9183
getProjectNumber,
9284
} from "@/common/globalFunctions";
85+
import TagInput from "@/components/TagInput.vue";
9386
9487
export default {
9588
name: "CreateFolderModal",
89+
components: { TagInput },
9690
data() {
9791
return {
9892
folderName: "",
@@ -152,6 +146,12 @@ export default {
152146
this.create = true;
153147
modifyBrowserPageStyles();
154148
},
149+
addingTag: function (e, onBlur) {
150+
this.tags = addNewTag(e, this.tags, onBlur);
151+
},
152+
deletingTag: function (e, tag) {
153+
this.tags = deleteTag(e, tag, this.tags);
154+
},
155155
},
156156
};
157157
</script>
@@ -179,6 +179,11 @@ c-card-content {
179179
padding: 1.5rem 0 0 0;
180180
}
181181
182+
label {
183+
font-weight: bold;
184+
margin-bottom: -1rem;
185+
}
186+
182187
c-card-actions {
183188
padding: 0;
184189
}

swift_browser_ui_frontend/src/components/EditTagsModal.vue

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,11 @@
44
{{ $t('message.editTags') }}
55
</h2>
66
<c-card-content>
7-
<b-field
8-
custom-class="has-text-dark"
9-
>
10-
<b-taginput
11-
v-model="tags"
12-
:aria-label="$t('label.edit_tag')"
13-
aria-close-label="delete-tag"
14-
ellipsis
15-
maxlength="20"
16-
has-counter
17-
rounded
18-
type="is-primary"
19-
:placeholder="$t('message.tagPlaceholder')"
20-
:confirm-keys="taginputConfirmKeys"
21-
:on-paste-separators="taginputConfirmKeys"
22-
/>
23-
</b-field>
7+
<TagInput
8+
:tags="tags"
9+
@addTag="addingTag"
10+
@deleteTag="deletingTag"
11+
/>
2412
</c-card-content>
2513
<c-card-actions justify="space-between">
2614
<c-button
@@ -49,22 +37,28 @@ import {
4937
} from "@/common/api";
5038
5139
import {
52-
taginputConfirmKeys,
5340
getTagsForObjects,
5441
getTagsForContainer,
5542
} from "@/common/conv";
5643
57-
import { modifyBrowserPageStyles } from "@/common/globalFunctions";
44+
import {
45+
addNewTag,
46+
deleteTag,
47+
modifyBrowserPageStyles,
48+
} from "@/common/globalFunctions";
49+
import TagInput from "@/components/TagInput.vue";
50+
import { mdiClose } from "@mdi/js";
5851
5952
export default {
6053
name: "EditTagsModal",
54+
components: { TagInput },
6155
data() {
6256
return {
6357
container: null,
6458
object: null,
6559
tags: [],
6660
isObject: false,
67-
taginputConfirmKeys,
61+
mdiClose,
6862
};
6963
},
7064
computed: {
@@ -188,6 +182,12 @@ export default {
188182
});
189183
this.toggleEditTagsModal();
190184
},
185+
addingTag: function (e, onBlur) {
186+
this.tags = addNewTag(e, this.tags, onBlur);
187+
},
188+
deletingTag: function (e, tag) {
189+
this.tags = deleteTag(e, tag, this.tags);
190+
},
191191
},
192192
};
193193
</script>
@@ -204,6 +204,7 @@ export default {
204204
max-height: 75vh;
205205
}
206206
207+
h2 { margin: 0 !important; }
207208
208209
c-card-content {
209210
color: var(--csc-dark-grey);
@@ -214,4 +215,5 @@ c-card-actions {
214215
padding: 0;
215216
}
216217
218+
217219
</style>

0 commit comments

Comments
 (0)