Skip to content

Commit 72cd656

Browse files
authored
[Remove Vuetify from Studio] replace textbox in Channels > New collection
* refactor: removed vuetify from collection input and validation * test(channelSetModal): updated failing workflows * fix(ChannelSetModal): removed error snackbar
1 parent b1f0a46 commit 72cd656

File tree

2 files changed

+51
-43
lines changed

2 files changed

+51
-43
lines changed

contentcuration/contentcuration/frontend/channelList/views/ChannelSet/ChannelSetModal.vue

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@
3838
lg10
3939
xl8
4040
>
41-
<VForm ref="channelsetform">
42-
<VTextField
41+
<form>
42+
<KTextbox
4343
v-model="name"
44-
:rules="nameRules"
4544
:label="$tr('titleLabel')"
4645
maxlength="200"
47-
counter
48-
box
46+
:invalid="errors.name"
47+
:invalidText="$tr('titleRequiredText')"
48+
showInvalidText
4949
data-test="input-name"
5050
/>
51-
</VForm>
51+
</form>
5252

5353
<div v-if="channelSet.secret_token">
5454
<p>{{ $tr('tokenPrompt') }}</p>
@@ -202,12 +202,19 @@
202202
import ChannelItem from './ChannelItem';
203203
import ChannelSelectionList from './ChannelSelectionList';
204204
import { ChannelListTypes, ErrorTypes } from 'shared/constants';
205-
import { constantsTranslationMixin, routerMixin } from 'shared/mixins';
205+
import { generateFormMixin, constantsTranslationMixin, routerMixin } from 'shared/mixins';
206206
import CopyToken from 'shared/views/CopyToken';
207207
import FullscreenModal from 'shared/views/FullscreenModal';
208208
import Tabs from 'shared/views/Tabs';
209209
import LoadingText from 'shared/views/LoadingText';
210210
211+
const formMixin = generateFormMixin({
212+
name: {
213+
required: true,
214+
validator: v => v && v.trim().length > 0,
215+
},
216+
});
217+
211218
export default {
212219
name: 'ChannelSetModal',
213220
components: {
@@ -218,7 +225,7 @@
218225
Tabs,
219226
LoadingText,
220227
},
221-
mixins: [constantsTranslationMixin, routerMixin],
228+
mixins: [formMixin, constantsTranslationMixin, routerMixin],
222229
props: {
223230
channelSetId: {
224231
type: String,
@@ -242,9 +249,6 @@
242249
isNew() {
243250
return this.$route.path === '/collections/new';
244251
},
245-
nameRules() {
246-
return [name => (name && name.trim().length ? true : this.$tr('titleRequiredText'))];
247-
},
248252
name: {
249253
get() {
250254
return Object.prototype.hasOwnProperty.call(this.diffTracker, 'name')
@@ -371,44 +375,48 @@
371375
this.saving = true;
372376
this.showUnsavedDialog = false;
373377
374-
if (this.$refs.channelsetform.validate()) {
375-
let promise;
378+
const formData = this.clean();
379+
if (!this.validate(formData)) {
380+
this.saving = false;
381+
return;
382+
}
376383
377-
if (this.isNew) {
378-
const channelSetData = { ...this.diffTracker };
379-
promise = this.commitChannelSet(channelSetData)
380-
.then(newCollection => {
381-
if (!newCollection || !newCollection.id) {
382-
this.saving = false;
383-
return;
384-
}
384+
let promise;
385385
386-
const newCollectionId = newCollection.id;
386+
if (this.isNew) {
387+
const channelSetData = { ...this.diffTracker, ...formData };
388+
promise = this.commitChannelSet(channelSetData)
389+
.then(newCollection => {
390+
if (!newCollection || !newCollection.id) {
391+
this.saving = false;
392+
return;
393+
}
387394
388-
this.$router.replace({
389-
name: 'CHANNEL_SET_DETAILS',
390-
params: { channelSetId: newCollectionId },
391-
});
395+
const newCollectionId = newCollection.id;
392396
393-
return newCollection;
394-
})
395-
.catch(() => {
396-
this.saving = false;
397+
this.$router.replace({
398+
name: 'CHANNEL_SET_DETAILS',
399+
params: { channelSetId: newCollectionId },
397400
});
398-
} else {
399-
promise = this.saveChannels().then(() => {
400-
return this.updateChannelSet({ id: this.channelSetId, ...this.diffTracker });
401-
});
402-
}
403401
404-
promise
405-
.then(() => {
406-
this.close();
402+
return newCollection;
407403
})
408-
.finally(() => {
404+
.catch(() => {
409405
this.saving = false;
410406
});
407+
} else {
408+
promise = this.saveChannels().then(() => {
409+
return this.updateChannelSet({ id: this.channelSetId, ...this.diffTracker });
410+
});
411411
}
412+
413+
promise
414+
.then(() => {
415+
this.close();
416+
})
417+
.finally(() => {
418+
this.saving = false;
419+
});
412420
},
413421
414422
cancelChanges() {

contentcuration/contentcuration/frontend/channelList/views/ChannelSet/__tests__/channelSetModal.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ describe('ChannelSetModal', () => {
219219
it('should prompt user if there are unsaved changes', async () => {
220220
expect(getUnsavedDialog(wrapper).exists()).toBeFalsy();
221221

222-
await getCollectionNameInput(wrapper).setValue('My collection');
222+
await wrapper.setData({ name: 'My collection' });
223223
await getCloseButton(wrapper).trigger('click');
224224

225225
expect(getUnsavedDialog(wrapper).exists()).toBeTruthy();
@@ -228,23 +228,23 @@ describe('ChannelSetModal', () => {
228228

229229
describe('clicking save button', () => {
230230
it("shouldn't update a channel set when a collection name is missing", async () => {
231-
await getCollectionNameInput(wrapper).setValue('');
231+
await wrapper.setData({ name: '' });
232232
await getSaveButton(wrapper).trigger('click');
233233
await flushPromises();
234234

235235
expect(updateChannelSet).not.toHaveBeenCalled();
236236
});
237237

238238
it("shouldn't update a channel set when a collection name is made of empty characters", async () => {
239-
await getCollectionNameInput(wrapper).setValue(' ');
239+
await wrapper.setData({ name: ' ' });
240240
await getSaveButton(wrapper).trigger('click');
241241
await flushPromises();
242242

243243
expect(updateChannelSet).not.toHaveBeenCalled();
244244
});
245245

246246
it('should update a channel set when a collection name is valid', async () => {
247-
await getCollectionNameInput(wrapper).setValue('My collection');
247+
await wrapper.setData({ name: 'My collection' });
248248
await getSaveButton(wrapper).trigger('click');
249249
await flushPromises();
250250

0 commit comments

Comments
 (0)