Skip to content

Commit

Permalink
Introducing filtering out logic for groups for content types on js, d…
Browse files Browse the repository at this point in the history
…ata filter util
  • Loading branch information
tutaru99 committed Jun 5, 2024
1 parent 50415bb commit 5efb2c9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
1 change: 0 additions & 1 deletion components/view-components/PracticalInformation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const props = defineProps({
data: {
type: Object,
required: true,
default: null,
},
userProfilePage: {
Expand Down
9 changes: 5 additions & 4 deletions components/views/exerciseView.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<script setup lang="ts">
import { filterGroups } from '~/utils/dataFilter';
const props = defineProps({
data: {
type: Object,
Expand All @@ -12,7 +14,7 @@ useHead({
});
const practicalInfoData = computed(() => {
return [
const data = [
{
group: [
{
Expand All @@ -21,7 +23,6 @@ const practicalInfoData = computed(() => {
},
],
},
{
group: [
{
Expand Down Expand Up @@ -51,7 +52,6 @@ const practicalInfoData = computed(() => {
},
],
},
{
group: [
{
Expand All @@ -66,7 +66,6 @@ const practicalInfoData = computed(() => {
},
],
},
{
group: [
{
Expand All @@ -78,6 +77,8 @@ const practicalInfoData = computed(() => {
],
},
];
return filterGroups(data);
});
</script>

Expand Down
20 changes: 20 additions & 0 deletions utils/dataFilter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const isValidContent = (content: any) => {
if (Array.isArray(content)) {
return content.some((item) => item !== null && item !== '');
}
return content !== null && content !== '' && typeof content !== 'undefined';
};

// WIP - needs more testing / work against other content types
export const filterGroups = (data: any[]) => {
return data
.map((group) => ({
group: group.group.filter((item: any) => {
if (item.type === 'sustainability_goals') {
return isValidContent(item.content);
}
return isValidContent(item.content) || isValidContent(item.description);
}),
}))
.filter((group) => group.group.length > 0);
};

0 comments on commit 5efb2c9

Please sign in to comment.