Skip to content
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

Quiz Creation Select Resources - Keyword search #11887

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</KGridItem>
</KGrid>

<div v-if="!isTopicIdSet && bookmarks.length && !showBookmarks">
<div v-if="!searchQuery && !isTopicIdSet && bookmarks.length && !showBookmarks">

<p>{{ selectFromBookmarks$() }}</p>

Expand Down Expand Up @@ -56,6 +56,12 @@
:channelsLink="channelsLink"
:topicsLink="topicsLink"
/>

<LessonsSearchBox
v-if="!showBookmarks"
@clear="clearSearchTerm"
@searchterm="handleSearchTermChange"
/>
<ContentCardList
:contentList="contentList"
:showSelectAll="true"
Expand Down Expand Up @@ -99,9 +105,9 @@
</div>
</div>

</template>
</template>


<script>

import uniqWith from 'lodash/uniqWith';
Expand All @@ -116,6 +122,7 @@
import BookmarkIcon from '../LessonResourceSelectionPage/LessonContentCard/BookmarkIcon.vue';
import useQuizResources from '../../../composables/useQuizResources';
import { injectQuizCreation } from '../../../composables/useQuizCreation';
import LessonsSearchBox from '../LessonResourceSelectionPage/SearchTools/LessonsSearchBox.vue';
import ContentCardList from './../LessonResourceSelectionPage/ContentCardList.vue';
import ResourceSelectionBreadcrumbs from './../LessonResourceSelectionPage/SearchTools/ResourceSelectionBreadcrumbs.vue';

Expand All @@ -124,6 +131,7 @@
components: {
ContentCardList,
BookmarkIcon,
LessonsSearchBox,
ResourceSelectionBreadcrumbs,
},
mixins: [commonCoreStrings],
Expand All @@ -135,6 +143,7 @@
// or the actual exercises that are bookmarked and can be selected
// to be added to Quiz Section.
const showBookmarks = computed(() => route.value.query.showBookmarks);
const searchQuery = computed(() => route.value.query.search);
const { updateSection, activeResourcePool, selectAllQuestions } = injectQuizCreation();

const {
Expand All @@ -149,7 +158,7 @@

// TODO let's not use text for this
const viewMoreButtonState = computed(() => {
if (hasMore.value) {
if (hasMore.value || moreSearchResults.value) {
return ViewMoreButtonStates.HAS_MORE;
} else {
return ViewMoreButtonStates.NO_MORE;
Expand Down Expand Up @@ -196,6 +205,27 @@
return workingResourceIds.includes(content.id);
}

function fetchSearchResults() {
const getParams = {
max_results: 25,
keywords: searchQuery.value,
kind: ContentNodeKinds.EXERCISE,
};
return ContentNodeResource.fetchCollection({ getParams }).then(response => {
searchResults.value = response.results;
moreSearchResults.value = response.more;
});
}

function fetchMoreSearchResults() {
return ContentNodeResource.fetchCollection({
getParams: moreSearchResults.value,
}).then(response => {
searchResults.value = searchResults.value.concat(response.results);
moreSearchResults.value = response.more;
});
}

const {
hasCheckbox,
topic,
Expand All @@ -213,32 +243,42 @@

const channels = ref([]);
const bookmarks = ref([]);
const searchResults = ref([]);
const moreSearchResults = ref(null);

// Load up the channels

if (!topicId.value) {
const channelBookmarkPromises = [
ChannelResource.fetchCollection({
params: { has_exercises: true, available: true },
}).then(response => {
setResources(
response.map(chnl => {
return {
...chnl,
id: chnl.root,
title: chnl.name,
kind: ContentNodeKinds.CHANNEL,
is_leaf: false,
};
})
);
}),
ContentNodeResource.fetchBookmarks({ params: { limit: 25, available: true } }).then(
data => {
bookmarks.value = data.results ? data.results : [];
}
),
];

if (searchQuery.value) {
channelBookmarkPromises.push(fetchSearchResults());
} else {
channelBookmarkPromises.push(
ChannelResource.fetchCollection({
params: { has_exercises: true, available: true },
}).then(response => {
setResources(
response.map(chnl => {
return {
...chnl,
id: chnl.root,
title: chnl.name,
kind: ContentNodeKinds.CHANNEL,
is_leaf: false,
};
})
);
})
);
}

Promise.all(channelBookmarkPromises).then(() => {
// When we don't have a topicId we're setting the value of useQuizResources.resources
// to the value of the channels (treating those channels as the topics) -- we then
Expand Down Expand Up @@ -272,6 +312,10 @@
.map(item => ({ ...item, is_leaf: true }));
}

if (searchQuery.value) {
return searchResults.value;
}

return resources.value;
});

Expand All @@ -283,6 +327,12 @@
}
});

watch(searchQuery, () => {
if (searchQuery.value) {
fetchSearchResults();
}
});

return {
topic,
topicId,
Expand All @@ -292,7 +342,8 @@
loading,
hasMore,
loadingMore,
fetchMoreQuizResources,
searchQuery,
fetchMoreQuizResources: searchQuery ? fetchMoreSearchResults : fetchMoreQuizResources,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless the component is being torn down and recreated when the searchQuery updates (which I think we are trying to avoid happen), this value will not recompute.

You may want to instead make the fetchMoreQuizResources function behave conditionally on the searchQuery instead.

Also, it should be searchQuery.value I believe that we conditionalize on?

resetWorkingResourcePool,
contentPresentInWorkingResourcePool,
//contentList,
Expand Down Expand Up @@ -447,12 +498,22 @@
}
return '';
},
handleSearchTermChange(searchTerm) {
this.$router.push({
query: { search: searchTerm },
});
},
clearSearchTerm() {
this.$router.push({
query: { search: null },
});
},
},
};

</script>
</script>


<style scoped lang="scss">

@import '~kolibri-design-system/lib/styles/definitions';
Expand Down Expand Up @@ -536,4 +597,4 @@
margin-top: 2em;
}

</style>
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@
},
methods: {
handleClosePanel() {
if (this.workingResourcePool.length > this.activeResourcePool.length) {
if (
this.workingResourcePool &&
Copy link
Member Author

@AlexVelezLl AlexVelezLl Feb 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason there was a case where workingResourcePool was undefined here and it didn't let me move forward

this.workingResourcePool.length > this.activeResourcePool.length
) {
this.showConfirmationModal = true;
} else {
this.$router.replace(this.closePanelRoute);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,16 @@
name: 'LessonsSearchBox',
mixins: [commonCoreStrings],
data() {
const { params, query } = this.$route;
return {
searchTerm: this.$route.params.searchTerm || '',
searchTerm: params.searchTerm || query.search || '',
};
},
computed: {
searchTermHasChanged() {
return this.searchTerm !== this.$route.params.searchTerm;
const { params, query } = this.$route;
const newSearchTerm = params.searchTerm || query.search;
return this.searchTerm !== newSearchTerm;
},
inputPlaceHolderStyle() {
return {
Expand All @@ -85,6 +88,7 @@
clearSearchTerm() {
this.searchTerm = '';
this.$refs.searchinput.focus();
this.$emit('clear');
},
search() {
if (this.searchTerm !== '' && this.searchTermHasChanged) {
Expand Down