-
Notifications
You must be signed in to change notification settings - Fork 222
Implements check to prevent channel having different language from its content #4666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
marcellamaki
merged 6 commits into
learningequality:unstable
from
akolson:fix-channel-lang-discrepancies
Aug 27, 2024
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a428edd
Implements check to prevent channel having different language from co…
akolson 3d4e202
remove async on mounted
akolson 7806c43
Fixes channel language update
akolson 869b4d3
Update logic
akolson e3795f1
Fixes long running and failing tests
akolson 13b434c
Fixes conflicts
akolson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,14 +49,28 @@ | |
:label="$tr('versionDescriptionLabel')" | ||
:invalid="!isDescriptionValid" | ||
:invalidText="$tr('descriptionRequiredMessage')" | ||
:showInvalidText="showInvalidText" | ||
:showInvalidText="showDescriptionInvalidText" | ||
autofocus | ||
textArea | ||
/> | ||
</KGridItem> | ||
<KGridItem :layout="{ span: 1 }"> | ||
<HelpTooltip :text="$tr('descriptionDescriptionTooltip')" bottom /> | ||
</KGridItem> | ||
|
||
<KGridItem v-show="showLanguageDropdown" :layout="{ span: 11 }"> | ||
<KSelect | ||
v-model="language" | ||
:label="$tr('languageLabel')" | ||
:invalid="showLanguageInvalidText" | ||
:invalidText="$tr('languageRequiredMessage')" | ||
:options="languages" | ||
@change="showLanguageInvalidText = !isLanguageValid" | ||
/> | ||
</KGridItem> | ||
<KGridItem v-show="showLanguageDropdown" :layout="{ span: 1 }"> | ||
<HelpTooltip :text="$tr('languageDescriptionTooltip')" bottom /> | ||
</KGridItem> | ||
</KFixedGrid> | ||
</KModal> | ||
|
||
|
@@ -71,6 +85,7 @@ | |
import { mapActions, mapGetters } from 'vuex'; | ||
import HelpTooltip from 'shared/views/HelpTooltip'; | ||
import { forceServerSync } from 'shared/data/serverSync'; | ||
import { LanguagesList } from 'shared/leUtils/Languages'; | ||
|
||
export default { | ||
name: 'PublishModal', | ||
|
@@ -88,9 +103,13 @@ | |
step: 0, | ||
publishDescription: '', | ||
size: 0, | ||
showInvalidText: false, // lazy validation | ||
showDescriptionInvalidText: false, // lazy validation | ||
showLanguageInvalidText: false, | ||
loading: false, | ||
loadingTaskId: null, | ||
language: {}, | ||
channelLanguages: [], | ||
channelLanguageExists: true, | ||
}; | ||
}, | ||
computed: { | ||
|
@@ -112,9 +131,34 @@ | |
isDescriptionValid() { | ||
return this.publishDescription && this.publishDescription.trim(); | ||
}, | ||
isLanguageValid() { | ||
return Object.keys(this.language).length > 0; | ||
}, | ||
sizeCalculationTask() { | ||
return this.loadingTaskId ? this.getAsyncTask(this.loadingTaskId) : null; | ||
}, | ||
isCheffedChannel() { | ||
return Boolean(this.currentChannel.ricecooker_version); | ||
}, | ||
isPrivateChannel() { | ||
return this.currentChannel.public; | ||
}, | ||
isFirstPublish() { | ||
return this.currentChannel.version === 0; | ||
}, | ||
defaultLanguage() { | ||
const channelLang = this.filterLanguages(l => l.id === this.currentChannel.language)[0]; | ||
return this.languages.some(lang => lang.value === channelLang.value) ? channelLang : {}; | ||
}, | ||
showLanguageDropdown() { | ||
return ( | ||
((this.isCheffedChannel || this.isPrivateChannel) && this.isFirstPublish) || | ||
!this.channelLanguageExists | ||
); | ||
}, | ||
languages() { | ||
return this.filterLanguages(l => this.channelLanguages.includes(l.id)); | ||
}, | ||
}, | ||
watch: { | ||
sizeCalculationTask(task) { | ||
|
@@ -139,26 +183,56 @@ | |
// this.loading = response.stale; | ||
// this.loadingTaskId = response.changes.length ? response.changes[0].key : null; | ||
// }); | ||
this.channelLanguageExistsInResources().then(exists => { | ||
this.channelLanguageExists = exists; | ||
if (!exists) { | ||
this.getLanguagesInChannelResources().then(languages => { | ||
this.channelLanguages = languages.length ? languages : [this.currentChannel.language]; | ||
this.language = this.defaultLanguage; | ||
}); | ||
} else { | ||
this.channelLanguages = [this.currentChannel.language]; | ||
this.language = this.defaultLanguage; | ||
} | ||
}); | ||
}, | ||
methods: { | ||
...mapActions('currentChannel', ['publishChannel']), | ||
...mapActions('channel', ['updateChannel']), | ||
...mapActions('currentChannel', [ | ||
'publishChannel', | ||
'channelLanguageExistsInResources', | ||
'getLanguagesInChannelResources', | ||
]), | ||
close() { | ||
this.publishDescription = ''; | ||
this.language = this.defaultLanguage; | ||
this.dialog = false; | ||
}, | ||
validate() { | ||
this.showInvalidText = true; | ||
return this.isDescriptionValid; | ||
this.showDescriptionInvalidText = !this.isDescriptionValid; | ||
this.showLanguageInvalidText = !this.isLanguageValid; | ||
return !this.showDescriptionInvalidText && !this.showLanguageInvalidText; | ||
}, | ||
async handlePublish() { | ||
if (this.validate()) { | ||
if (!this.areAllChangesSaved) { | ||
await forceServerSync(); | ||
} | ||
|
||
this.publishChannel(this.publishDescription).then(this.close); | ||
this.updateChannel({ | ||
id: this.currentChannel.id, | ||
language: this.language.value, | ||
}).then(() => { | ||
this.publishChannel(this.publishDescription).then(this.close); | ||
}); | ||
} | ||
}, | ||
filterLanguages(filterFn) { | ||
return LanguagesList.filter(filterFn).map(l => ({ | ||
value: l.id, | ||
label: l.native_name, | ||
})); | ||
}, | ||
}, | ||
$trs: { | ||
// Incomplete channel window | ||
|
@@ -174,8 +248,11 @@ | |
descriptionRequiredMessage: "Please describe what's new in this version before publishing", | ||
descriptionDescriptionTooltip: | ||
'This description will be shown to Kolibri admins before they update channel versions', | ||
languageDescriptionTooltip: 'The default language for a channel and its resources', | ||
cancelButton: 'Cancel', | ||
publishButton: 'Publish', | ||
languageLabel: 'Language', | ||
languageRequiredMessage: 'Please select a language for this channel', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marcellamaki a heads up on the strings added |
||
}, | ||
}; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcellamaki a heads up on the strings added