Skip to content

Commit

Permalink
chore: display relations with end_date only
Browse files Browse the repository at this point in the history
  • Loading branch information
katharinawuensche committed Aug 6, 2024
1 parent 26eeabe commit 5d1a676
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 66 deletions.
13 changes: 2 additions & 11 deletions pages/detail/event/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DetailPage from "@/components/detail-page.vue";
import Timeline from "@/components/timeline/timeline.vue";
import Loader from "@/components/ui/loader.vue";
import { loadAndGroupRelations } from "@/lib/group-relations.ts";
import type { TimelineObject } from "@/types/timeline";
import { getFlattenedRelations } from "@/utils/timeline-utils";
const t = useTranslations();
const route = useRoute();
Expand Down Expand Up @@ -45,16 +45,7 @@ const chipNames = computed(() => {
});
const flattenedRelations = computed(() => {
if (!data.value.relations.data) return [];
const res = Object.entries(data.value.relations.data)
.map(([key, val]) =>
val.map((entry) => {
return { ...entry, class: key };
}),
)
.flat()
.filter((r): r is TimelineObject => Boolean(r.start_date))
.sort((r) => new Date(String(r.start_date)).valueOf());
return res;
return getFlattenedRelations(data.value.relations.data);
});
</script>

Expand Down
13 changes: 2 additions & 11 deletions pages/detail/function/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Timeline from "@/components/timeline/timeline.vue";
import VerticalTimeline from "@/components/timeline/vertical-timeline.vue";
import Loader from "@/components/ui/loader.vue";
import { loadAndGroupRelations } from "@/lib/group-relations.ts";
import type { TimelineObject } from "@/types/timeline";
import { getFlattenedRelations } from "@/utils/timeline-utils";
const t = useTranslations();
const route = useRoute();
Expand Down Expand Up @@ -48,16 +48,7 @@ const chipNames = computed(() => {
});
const flattenedRelations = computed(() => {
if (!data.value.relations.data) return [];
const res = Object.entries(data.value.relations.data)
.map(([key, val]) =>
val.map((entry) => {
return { ...entry, class: key };
}),
)
.flat()
.filter((r): r is TimelineObject => Boolean(r.start_date))
.sort((r) => new Date(String(r.start_date)).valueOf());
return res;
return getFlattenedRelations(data.value.relations.data);
});
const showVerticalTimeline = ref(false);
function closeVerticalTimeline() {
Expand Down
13 changes: 2 additions & 11 deletions pages/detail/institution/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DetailPage from "@/components/detail-page.vue";
import Timeline from "@/components/timeline/timeline.vue";
import Loader from "@/components/ui/loader.vue";
import { loadAndGroupRelations } from "@/lib/group-relations.ts";
import type { TimelineObject } from "@/types/timeline";
import { getFlattenedRelations } from "@/utils/timeline-utils";
const t = useTranslations();
const route = useRoute();
Expand Down Expand Up @@ -46,16 +46,7 @@ const chipNames = computed(() => {
});
const flattenedRelations = computed(() => {
if (!data.value.relations.data) return [];
const res = Object.entries(data.value.relations.data)
.map(([key, val]) =>
val.map((entry) => {
return { ...entry, class: key };
}),
)
.flat()
.filter((r): r is TimelineObject => Boolean(r.start_date))
.sort((r) => new Date(String(r.start_date)).valueOf());
return res;
return getFlattenedRelations(data.value.relations.data);
});
</script>

Expand Down
12 changes: 2 additions & 10 deletions pages/detail/person/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Timeline from "@/components/timeline/timeline.vue";
import VerticalTimeline from "@/components/timeline/vertical-timeline.vue";
import Loader from "@/components/ui/loader.vue";
import { loadAndGroupRelations } from "@/lib/group-relations.ts";
import type { TimelineObject } from "@/types/timeline";
import { getFlattenedRelations } from "@/utils/timeline-utils";
const t = useTranslations();
const localePath = useLocalePath();
Expand Down Expand Up @@ -51,15 +51,7 @@ const functionNames = computed(() => {
});
const flattenedRelations = computed(() => {
if (!data.value.relations.data) return [];
const res = Object.entries(data.value.relations.data)
.map(([key, val]) =>
val.map((entry) => {
return { ...entry, class: key };
}),
)
.flat()
.filter((r): r is TimelineObject => Boolean(r.start_date));
return res;
return getFlattenedRelations(data.value.relations.data);
});
const sameAs = computed(() => {
Expand Down
13 changes: 2 additions & 11 deletions pages/detail/place/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Map from "@/components/map.vue";
import Timeline from "@/components/timeline/timeline.vue";
import Loader from "@/components/ui/loader.vue";
import { loadAndGroupRelations } from "@/lib/group-relations.ts";
import type { TimelineObject } from "@/types/timeline";
import { getFlattenedRelations } from "@/utils/timeline-utils";
const t = useTranslations();
const route = useRoute();
Expand Down Expand Up @@ -47,16 +47,7 @@ const chipNames = computed(() => {
});
const flattenedRelations = computed(() => {
if (!data.value.relations.data) return [];
const res = Object.entries(data.value.relations.data)
.map(([key, val]) =>
val.map((entry) => {
return { ...entry, class: key };
}),
)
.flat()
.filter((r): r is TimelineObject => Boolean(r.start_date))
.sort((r) => new Date(String(r.start_date)).valueOf());
return res;
return getFlattenedRelations(data.value.relations.data);
});
</script>

Expand Down
15 changes: 3 additions & 12 deletions pages/detail/salary/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DetailPage from "@/components/detail-page.vue";
import Timeline from "@/components/timeline/timeline.vue";
import Loader from "@/components/ui/loader.vue";
import { loadAndGroupRelations } from "@/lib/group-relations.ts";
import type { TimelineObject } from "@/types/timeline";
import { getFlattenedRelations } from "@/utils/timeline-utils";
const t = useTranslations();
const route = useRoute();
Expand Down Expand Up @@ -34,17 +34,8 @@ const data = ref({
});
const flattenedRelations = computed(() => {
if (data.value.relations.isLoading) return [];
const res = Object.entries(data.value.relations.data ?? {})
.map(([key, val]) =>
val.map((entry) => {
return { ...entry, class: key };
}),
)
.flat()
.filter((r): r is TimelineObject => Boolean(r.start_date))
.sort((r) => new Date(String(r.start_date)).valueOf());
return res;
if (!data.value.relations.data) return [];
return getFlattenedRelations(data.value.relations.data);
});
</script>

Expand Down
26 changes: 26 additions & 0 deletions utils/timeline-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { TempTriple } from "@/types/resulttypes";
import type { TimelineObject } from "@/types/timeline";

//type guard to filter grouped relations
Expand All @@ -22,3 +23,28 @@ export function groupTimelineRelations(filteredRelations: Array<TimelineObject>)
isValidTimelineObject(arr),
);
}

export function getFlattenedRelations(relations: Record<string, Array<TempTriple>>) {
const res = Object.entries(relations)
.map(([key, val]) =>
val.map((entry) => {
return {
...entry,
class: key,
};
}),
)
.flat()
.filter((r): r is TimelineObject => Boolean(r.start_date) || Boolean(r.end_date))
.map((entry) => {
let start_date_written = entry.start_date_written;
if (!start_date_written || start_date_written === "")
start_date_written = entry.end_date_written;
return {
...entry,
start_date: entry.start_date ?? entry.end_date,
start_date_written: start_date_written,
};
});
return res;
}

0 comments on commit 5d1a676

Please sign in to comment.