Skip to content

Commit

Permalink
Aktivitäten werden automatisch benannt
Browse files Browse the repository at this point in the history
- Aktivitäten wird nun automatisch ein Name vergeben. Dazu werden Informationen aus Besprechungen, zu Personen und zu Projekten sowie die die Notiz selbst herangezogen.
  • Loading branch information
cabcookie authored Feb 26, 2025
2 parents 8402a72 + 99e7960 commit ee64bdf
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 10 deletions.
2 changes: 2 additions & 0 deletions amplify/data/activity-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const activitySchema = {
owner: a
.string()
.authorization((allow) => [allow.owner().to(["read", "delete"])]),
name: a.string(),
notionId: a.integer(),
formatVersion: a.integer().default(1),
forProjects: a.hasMany("ProjectActivity", "activityId"),
Expand All @@ -79,6 +80,7 @@ const activitySchema = {
finishedOn: a.datetime(),
noteBlocks: a.hasMany("NoteBlock", "activityId"),
noteBlockIds: a.string().required().array(),
summaryRequests: a.hasMany("ActivitySummaryRequest", "activityId"),
notes: a.string(), // DEPRECATED
notesJson: a.json(), // DEPRECATED
})
Expand Down
14 changes: 13 additions & 1 deletion api/useActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ export type TempIdMapping = {
type ProjectLinkData = {
id: string;
projectsId: string;
name: string;
accounts: { name: string }[];
};

export type Activity = {
id: string;
name?: string;
notes: JSONContent;
meetingId?: string;
finishedOn: Date;
Expand All @@ -46,6 +49,7 @@ export type Activity = {

const selectionSet = [
"id",
"name",
"notes",
"formatVersion",
"notesJson",
Expand All @@ -55,6 +59,8 @@ const selectionSet = [
"updatedAt",
"forProjects.id",
"forProjects.projectsId",
"forProjects.projects.project",
"forProjects.projects.accounts.account.name",
"noteBlockIds",
"noteBlocks.id",
"noteBlocks.content",
Expand All @@ -75,6 +81,7 @@ export type NoteBlockData = ActivityData["noteBlocks"][number];

export const mapActivity = (a: ActivityData): Activity => ({
id: a.id,
name: a.name || undefined,
notes: transformNotesVersion(a),
noteBlockIds:
a.noteBlockIds?.filter((id) => a.noteBlocks.some((b) => b.id === id)) ??
Expand All @@ -84,7 +91,12 @@ export const mapActivity = (a: ActivityData): Activity => ({
updatedAt: new Date(a.updatedAt),
projectIds: a.forProjects.map(({ projectsId }) => projectsId),
projectActivityIds: a.forProjects.map(({ id }) => id),
projects: a.forProjects,
projects: a.forProjects.map((p) => ({
id: p.id,
projectsId: p.projectsId,
name: p.projects?.project,
accounts: p.projects?.accounts.map((a) => ({ name: a.account.name })),
})),
oldFormatVersion: !a.formatVersion || a.formatVersion < 3,
hasOpenTodos: a.noteBlocks.some((b) => b.todo?.status === "OPEN"),
hasClosedTodos: a.noteBlocks.some((b) => b.todo?.status === "DONE"),
Expand Down
3 changes: 3 additions & 0 deletions api/useMeetings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const meetingSelectionSet = [
"participants.personId",
"activities.id",
"activities.notes",
"activities.name",
"activities.formatVersion",
"activities.notesJson",
"activities.meetingActivitiesId",
Expand All @@ -48,6 +49,8 @@ export const meetingSelectionSet = [
"activities.updatedAt",
"activities.forProjects.id",
"activities.forProjects.projectsId",
"activities.forProjects.projects.project",
"activities.forProjects.projects.accounts.account.name",
"activities.noteBlockIds",
"activities.noteBlocks.id",
"activities.noteBlocks.content",
Expand Down
6 changes: 2 additions & 4 deletions docs/releases/next.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Meetings wurden nicht angezeigt (Version :VERSION)
# Aktivitäten werden automatisch benannt (Version :VERSION)

## Fehlerbehebungen

Es konnte passieren, dass die Verknüpfung zwischen dem Abschnitt einer Notiz und einer Aufgabe verloren ging. Das hatte zur Konsequenz, dass die Meetingliste nicht mehr angezeigt werden konnte. Wenn diese Verknüpfung verloren gegangen ist, ignorieren wir den Abschnitt jetzt und sehen ihn nicht mehr vor.
- Aktivitäten wird nun automatisch ein Name vergeben. Dazu werden Informationen aus Besprechungen, zu Personen und zu Projekten sowie die die Notiz selbst herangezogen.

## Bekannte Fehler

Expand Down
117 changes: 112 additions & 5 deletions pages/activities/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,127 @@
import useActivity from "@/api/useActivity";
import { type Schema } from "@/amplify/data/resource";
import useActivity, { Activity } from "@/api/useActivity";
import ActivityComponent from "@/components/activities/activity";
import MainLayout from "@/components/layouts/MainLayout";
import { format } from "date-fns";
import { useRouter } from "next/router";
import { generateClient as generateApiClient } from "aws-amplify/api";
import { generateClient } from "aws-amplify/data";
import { debounce } from "lodash";
import { format, isFuture, isPast } from "date-fns";
import { useEffect } from "react";
import { emptyDocument } from "@/components/ui-elements/editors/helpers/document";
import { generateText } from "@tiptap/core";
import useExtensions from "@/components/ui-elements/editors/notes-editor/useExtensions";
import { Extensions } from "@tiptap/core";

const client = generateClient<Schema>();
const apiClient = generateApiClient<Schema>({ authMode: "userPool" });

const getMeeting = async (meetingId: string) => {
const { data, errors } = await client.models.Meeting.get(
{ id: meetingId },
{
selectionSet: [
"topic",
"meetingOn",
"createdAt",
"participants.person.name",
"participants.person.accounts.startDate",
"participants.person.accounts.endDate",
"participants.person.accounts.position",
"participants.person.accounts.account.name",
],
}
);
if (errors || !data) return "";
return [
`Meeting: ${data.topic} on ${format(data.meetingOn || data.createdAt, "PPP")}`,
data.participants
.map((p) =>
[
p.person.name,
p.person.accounts
.filter(
(a) =>
!a.startDate ||
(isPast(a.startDate) && (!a.endDate || isFuture(a.endDate)))
)
.map((pos) => {
return `${[pos.position, pos.account.name].join(" at ")}`;
})
.join(", "),
].join(", ")
)
.join("\n"),
].join("\nParticipants:\n");
};

const getProjects = (activity: Activity) =>
activity.projects?.map((p) =>
[p.name, p.accounts.map((a) => a.name).join(", ")].join(" for account(s): ")
);

const getNotes = (activity: Activity, extensions: Extensions) =>
generateText(activity.notes ?? emptyDocument, extensions);

const getNameForActivity = async (content: string) => {
const { data, errors } = await apiClient.generations.chatNamer({
content,
});
if (errors || !data) {
console.error("Errors or no data", errors);
return;
}
return data.name;
};

const updateActivityName = async (activityId: string, name: string) => {
console.log({ activityId, name });
const { data, errors } = await client.models.Activity.update({
id: activityId,
name,
});
if (errors) console.error("Error updating activity name", errors);
if (!data) console.error("No data returned from update activity name");
};

const nameActivity = debounce(
async (activity: Activity, extensions: Extensions) => {
if (!activity.meetingId) return;
const meeting = await getMeeting(activity.meetingId);

const content = [
[meeting, getProjects(activity)].join("\n\nProject(s):\n"),
getNotes(activity, extensions),
].join("\n\nNotes:\n");

const name = await getNameForActivity(content);
if (!name) return;
await updateActivityName(activity.id, name);
},
30000
);

const AccountDetailPage = () => {
const router = useRouter();
const { id } = router.query;
const activityId = Array.isArray(id) ? id[0] : id;
const { activity } = useActivity(activityId);
const extensions = useExtensions();

useEffect(() => {
if (!activity) return;
if (!extensions) return;
nameActivity(activity, extensions);
}, [activity, extensions]);

return (
<MainLayout
title={`Activity${
!activity ? "" : ` on ${format(activity.finishedOn, "PPP")}`
}`}
title={
activity?.name ??
`Activity${
!activity ? "" : ` on ${format(activity.finishedOn, "PPP")}`
}`
}
recordName={`Activity${
!activity ? "" : ` on ${format(activity.finishedOn, "PPP")}`
}`}
Expand Down

0 comments on commit ee64bdf

Please sign in to comment.