Skip to content

Commit

Permalink
feat: allow to remove done items (#4126)
Browse files Browse the repository at this point in the history
* add remove done items

* i18n en add

* bug fix

* add i18n

* Modify the description

* Modify the description

* Modify the description

* remove remove_done_check_items setting

* fix the static checks

* fix the static checks

---------

Co-authored-by: mozhu <lcl_em@163.com>
  • Loading branch information
liaochuan and mozhu authored Nov 17, 2024
1 parent 80785de commit f00751a
Show file tree
Hide file tree
Showing 26 changed files with 243 additions and 79 deletions.
47 changes: 46 additions & 1 deletion web/src/components/MemoActionMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,22 @@ import {
Edit3Icon,
MoreVerticalIcon,
TrashIcon,
SquareCheckIcon,
} from "lucide-react";
import toast from "react-hot-toast";
import { useLocation } from "react-router-dom";
import { markdownServiceClient } from "@/grpcweb";
import useNavigateTo from "@/hooks/useNavigateTo";
import { useMemoStore } from "@/store/v1";
import { RowStatus } from "@/types/proto/api/v1/common";
import { NodeType } from "@/types/proto/api/v1/markdown_service";
import { Memo } from "@/types/proto/api/v1/memo_service";
import { useTranslate } from "@/utils/i18n";

interface Props {
memo: Memo;
className?: string;
hiddenActions?: ("edit" | "archive" | "delete" | "share" | "pin")[];
hiddenActions?: ("edit" | "archive" | "delete" | "share" | "pin" | "remove_completed_task_list")[];
onEdit?: () => void;
}

Expand Down Expand Up @@ -113,6 +116,42 @@ const MemoActionMenu = (props: Props) => {
}
};

const handleRemoveCompletedTaskListItemsClick = async () => {
const confirmed = window.confirm(t("memo.remove-completed-task-list-items-confirm"));
if (confirmed) {
const newNodes = JSON.parse(JSON.stringify(memo.nodes));
for (let i = 0; i < newNodes.length; i++) {
if (newNodes[i].type === NodeType.LIST && newNodes[i].listNode?.children?.length > 0) {
let childrenLength = newNodes[i].listNode.children.length;
for (let j = 0; j < childrenLength; j++) {
if (
newNodes[i].listNode.children[j].type === NodeType.TASK_LIST_ITEM &&
newNodes[i].listNode.children[j].taskListItemNode?.complete
) {
// Remove completed taskList item and next line breaks
newNodes[i].listNode.children.splice(j, 1);
if (newNodes[i].listNode.children[j]?.type === NodeType.LINE_BREAK) {
newNodes[i].listNode.children.splice(j, 1);
childrenLength--;
}
childrenLength--;
j--;
}
}
}
}
const { markdown } = await markdownServiceClient.restoreMarkdownNodes({ nodes: newNodes });
await memoStore.updateMemo(
{
name: memo.name,
content: markdown,
},
["content"],
);
toast.success(t("message.remove-completed-task-list-items-successfully"));
}
};

return (
<Dropdown>
<MenuButton slots={{ root: "div" }}>
Expand Down Expand Up @@ -143,6 +182,12 @@ const MemoActionMenu = (props: Props) => {
{memo.rowStatus === RowStatus.ARCHIVED ? <ArchiveRestoreIcon className="w-4 h-auto" /> : <ArchiveIcon className="w-4 h-auto" />}
{memo.rowStatus === RowStatus.ARCHIVED ? t("common.restore") : t("common.archive")}
</MenuItem>
{!hiddenActions?.includes("remove_completed_task_list") && (
<MenuItem color="danger" onClick={handleRemoveCompletedTaskListItemsClick}>
<SquareCheckIcon className="w-4 h-auto" />
{t("memo.remove-completed-task-list-items")}
</MenuItem>
)}
<MenuItem color="danger" onClick={handleDeleteMemoClick}>
<TrashIcon className="w-4 h-auto" />
{t("common.delete")}
Expand Down
38 changes: 32 additions & 6 deletions web/src/components/MemoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import useAsyncEffect from "@/hooks/useAsyncEffect";
import useCurrentUser from "@/hooks/useCurrentUser";
import useNavigateTo from "@/hooks/useNavigateTo";
import { useUserStore, useWorkspaceSettingStore, useMemoStore } from "@/store/v1";
import { NodeType } from "@/types/proto/api/v1/markdown_service";
import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
import { Memo, Visibility } from "@/types/proto/api/v1/memo_service";
import { WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service";
Expand Down Expand Up @@ -115,6 +116,36 @@ const MemoView: React.FC<Props> = (props: Props) => {
<relative-time datetime={memo.displayTime?.toISOString()} format={relativeTimeFormat}></relative-time>
);

const handleHiddenActions = () => {
const hiddenActions: ("edit" | "archive" | "delete" | "share" | "pin" | "remove_completed_task_list")[] = [];
if (!props.showPinned) {
hiddenActions.push("pin");
}
// check if the content has done tasks
let hasCompletedTaskList = false;
const newNodes = JSON.parse(JSON.stringify(memo.nodes));
for (let i = 0; i < newNodes.length; i++) {
if (hasCompletedTaskList) {
break;
}
if (newNodes[i].type === NodeType.LIST && newNodes[i].listNode?.children?.length > 0) {
for (let j = 0; j < newNodes[i].listNode.children.length; j++) {
if (
newNodes[i].listNode.children[j].type === NodeType.TASK_LIST_ITEM &&
newNodes[i].listNode.children[j].taskListItemNode?.complete
) {
hasCompletedTaskList = true;
break;
}
}
}
}
if (!hasCompletedTaskList) {
hiddenActions.push("remove_completed_task_list");
}
return hiddenActions;
};

return (
<div
className={clsx(
Expand Down Expand Up @@ -199,12 +230,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
</Tooltip>
)}
{!readonly && (
<MemoActionMenu
className="-ml-1"
memo={memo}
hiddenActions={props.showPinned ? [] : ["pin"]}
onEdit={() => setShowEditor(true)}
/>
<MemoActionMenu className="-ml-1" memo={memo} hiddenActions={handleHiddenActions()} onEdit={() => setShowEditor(true)} />
)}
</div>
</div>
Expand Down
4 changes: 3 additions & 1 deletion web/src/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@
"private": "خاص",
"protected": "مساحة عمل",
"public": "عام"
}
},
"remove-completed-task-list-items": "إزالة المنجز",
"remove-completed-task-list-items-confirm": "هل أنت متأكد أنك تريد إزالة جميع المهام المنجزة؟ (هذه العملية لا يمكن التراجع عنها)"
},
"resource": {
"clear": "مسح",
Expand Down
10 changes: 7 additions & 3 deletions web/src/locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@
"private": "Nur für dich sichtbar",
"protected": "Mitglieder",
"public": "Öffentlich"
}
},
"remove-completed-task-list-items": "Erledigt entfernen",
"remove-completed-task-list-items-confirm": "Sind Sie sicher, dass Sie alle abgeschlossenen Aufgaben entfernen möchten? (Diese Aktion kann nicht rückgängig gemacht werden)"
},
"message": {
"change-memo-created-time": "Erstellungszeitpunkt ändern",
Expand All @@ -112,7 +114,8 @@
"restored-successfully": "Erfolgreich wiederhergestellt",
"succeed-copy-link": "Link erfolgreich kopiert",
"update-succeed": "Update erfolgreich",
"user-not-found": "Nutzer nicht gefunden"
"user-not-found": "Nutzer nicht gefunden",
"remove-completed-task-list-items-successfully": "Erfolgreich entfernt!"
},
"resource": {
"clear": "Löschen",
Expand Down Expand Up @@ -263,7 +266,8 @@
"enable-password-login-warning": "Dadurch wird die Passwortanmeldung für alle Benutzer aktiviert. Fahre nur fort, wenn du möchtest, dass sich Benutzer sowohl mit SSO als auch mit einem Passwort anmelden können",
"max-upload-size": "Maximale Uploadgröße (MiB)",
"max-upload-size-hint": "Empfohlene Wert ist 32 MiB.",
"server-name": "Servername"
"server-name": "Servername",
"removed-completed-task-list-items": "Entfernen abgeschlossen aktivieren"
}
},
"tag": {
Expand Down
10 changes: 7 additions & 3 deletions web/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
},
"links": "Links",
"to-do": "To-do",
"code": "Code"
"code": "Code",
"remove-completed-task-list-items": "Remove done",
"remove-completed-task-list-items-confirm": "Are you sure you want to remove all completed to-dos? THIS ACTION IS IRREVERSIBLE"
},
"message": {
"archived-successfully": "Archived successfully",
Expand All @@ -135,7 +137,8 @@
"restored-successfully": "Restored successfully",
"succeed-copy-link": "Link copied successfully.",
"update-succeed": "Update succeeded",
"user-not-found": "User not found"
"user-not-found": "User not found",
"remove-completed-task-list-items-successfully": "The removal was successful"
},
"reference": {
"add-references": "Add references",
Expand Down Expand Up @@ -299,7 +302,8 @@
"enable-password-login-warning": "This will enable password login for all users. Continue only if you want to users to be able to log in using both SSO and password",
"max-upload-size": "Maximum upload size (MiB)",
"max-upload-size-hint": "Recommended value is 32 MiB.",
"server-name": "Server Name"
"server-name": "Server Name",
"removed-completed-task-list-items": "Enable removal of completed task list items"
},
"memo-related": "Memo",
"access-token-section":{
Expand Down
10 changes: 7 additions & 3 deletions web/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@
"private": "Solo visible para ti",
"protected": "Espacio de trabajo",
"public": "Todo el mundo lo puede ver"
}
},
"remove-completed-task-list-items": "Eliminar completado",
"remove-completed-task-list-items-confirm": "¿Estás seguro de que quieres eliminar todas las tareas completadas? (Esta acción es irreversible)"
},
"message": {
"change-memo-created-time": "Cambiar la hora de creación del memo",
Expand All @@ -120,7 +122,8 @@
"restored-successfully": "Restaurado con éxito",
"succeed-copy-link": "Enlace copiado correctamente.",
"update-succeed": "Actualización exitosa",
"user-not-found": "Usuario no encontrado"
"user-not-found": "Usuario no encontrado",
"remove-completed-task-list-items-successfully": "¡Eliminado con éxito!"
},
"resource": {
"clear": "Limpiar",
Expand Down Expand Up @@ -265,7 +268,8 @@
"enable-password-login-warning": "Esto habilitará el inicio de sesión con contraseña para todos los usuarios. Continúa sólo si deseas que los usuarios puedan iniciar sesión mediante SSO y contraseña",
"max-upload-size": "Tamaño máximo de subida (MiB)",
"max-upload-size-hint": "El valor recomendado es de 32 MiB.",
"server-name": "Nombre del servidor"
"server-name": "Nombre del servidor",
"removed-completed-task-list-items": "Habilitar eliminar completado"
}
},
"tag": {
Expand Down
10 changes: 7 additions & 3 deletions web/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@
"private": "Privé",
"protected": "Accès aux membres",
"public": "Public"
}
},
"remove-completed-task-list-items": "Supprimer terminé",
"remove-completed-task-list-items-confirm": "Êtes-vous sûr de vouloir supprimer toutes les tâches terminées ? (Cette action est irréversible)"
},
"message": {
"archived-successfully": "Archivé avec succès",
Expand All @@ -135,7 +137,8 @@
"restored-successfully": "Restauré avec succès",
"succeed-copy-link": "Succeed to copy link to clipboard.",
"update-succeed": "Mise à jour effectuée",
"user-not-found": "Utilisateur introuvable"
"user-not-found": "Utilisateur introuvable",
"remove-completed-task-list-items-successfully": "Supprimé avec succès !"
},
"reference": {
"add-references": "Ajouter des références",
Expand Down Expand Up @@ -297,7 +300,8 @@
"enable-password-login-warning": "Ceci activera la connexion par mot de passe pour tous les utilisateurs. Ne continuez que si vous souhaitez que les utilisateurs puissent se connecter à la fois par SSO et par mot de passe",
"max-upload-size": "Taille maximale du téléversement (MiB)",
"max-upload-size-hint": "La valeur recommandée est 32 MiB.",
"server-name": "Nom du serveur"
"server-name": "Nom du serveur",
"removed-completed-task-list-items": "Activer la suppression terminée"
}
},
"tag": {
Expand Down
7 changes: 5 additions & 2 deletions web/src/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@
"private": "निजी",
"protected": "सदस्यों को दिखाई देता है",
"public": "सभी के लिए सार्वजनिक"
}
},
"remove-completed-task-list-items": "हटाएँ किया गया",
"remove-completed-task-list-items-confirm": "क्या आप सुनिश्चित हैं कि आप सभी पूरे कामों को हटाना चाहते हैं? (यह क्रिया वापस ले जाने योग्य नहीं है)"
},
"message": {
"change-memo-created-time": "मेमो बनाने का समय बदलें",
Expand All @@ -105,7 +107,8 @@
"restored-successfully": "सफलतापूर्वक पुनर्स्थापित किया गया",
"succeed-copy-link": "लिंक सफलतापूर्वक कॉपी किया गया।",
"update-succeed": "अपडेट सफल हुआ",
"user-not-found": "उपयोगकर्ता नहीं मिला"
"user-not-found": "उपयोगकर्ता नहीं मिला",
"remove-completed-task-list-items-successfully": "सफलतापूर्वक हटा दिया!"
},
"resource": {
"clear": "साफ़ करें",
Expand Down
10 changes: 7 additions & 3 deletions web/src/locales/hr.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
"private": "Privatno",
"protected": "Vidljivo članovima",
"public": "Javno"
}
},
"remove-completed-task-list-items": "Ukloni obavljen",
"remove-completed-task-list-items-confirm": "Jeste li sigurni da želite ukloniti sve obavljene zadatke? (Ova akcija je nevraćiva)"
},
"message": {
"change-memo-created-time": "Promijeni vrijeme stvaranja memoa",
Expand All @@ -117,7 +119,8 @@
"restored-successfully": "Uspješno vraćeno",
"succeed-copy-link": "Link je uspješno kopiran.",
"update-succeed": "Obnavljanje aplikacije je uspjelo!🎉",
"user-not-found": "Korisnik nije nađen"
"user-not-found": "Korisnik nije nađen",
"remove-completed-task-list-items-successfully": "Uspješno uklonjeno!"
},
"resource": {
"clear": "Očisti",
Expand Down Expand Up @@ -267,7 +270,8 @@
"enable-password-login-warning": "Ovo će omogućiti prijavu lozinkom za sve korisnike.",
"max-upload-size": "Maximalna veličina uploada (MiB)",
"max-upload-size-hint": "Preporučena vrijednost je 32 MiB.",
"server-name": "Ime servera"
"server-name": "Ime servera",
"removed-completed-task-list-items": "Omogući uklanjanje obavljenog"
}
},
"tag": {
Expand Down
10 changes: 7 additions & 3 deletions web/src/locales/hu.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@
"private": "Privát",
"protected": "Munkatér",
"public": "Nyilvános"
}
},
"remove-completed-task-list-items": "Töröld el a kész",
"remove-completed-task-list-items-confirm": "Biztos, hogy törölni akarod az összes kész feladatot? (Ez az akció visszavonhatatlan)"
},
"message": {
"archived-successfully": "Sikeres archiválás",
Expand All @@ -130,7 +132,8 @@
"restored-successfully": "Sikeres visszaállítás",
"succeed-copy-link": "Hivatkozás sikeresen másolva.",
"update-succeed": "Sikeres frissítés",
"user-not-found": "Felhasználó nem található"
"user-not-found": "Felhasználó nem található",
"remove-completed-task-list-items-successfully": "Sikeresen eltávolítva!"
},
"reference": {
"add-references": "Referenciák hozzáadása",
Expand Down Expand Up @@ -287,7 +290,8 @@
"enable-password-login-warning": "Ez engedélyezi a jelszavas bejelentkezést minden felhasználó számára. Csak akkor folytasd, ha szeretnéd, ha a felhasználók SSO és jelszó használatával is be tudjanak jelentkezni",
"max-upload-size": "Maximális feltöltési méret (MiB)",
"max-upload-size-hint": "Az ajánlott érték 32 MiB.",
"server-name": "Szerver neve"
"server-name": "Szerver neve",
"removed-completed-task-list-items": "Kikapcsold a kész törölését"
}
},
"tag": {
Expand Down
10 changes: 7 additions & 3 deletions web/src/locales/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@
"private": "Privato",
"protected": "Visibile ai membri",
"public": "Pubblico"
}
},
"remove-completed-task-list-items": "Rimuovi completato",
"remove-completed-task-list-items-confirm": "Sei sicuro di voler rimuovere tutte le cose completate? (Questa azione è irreversibile)"
},
"message": {
"change-memo-created-time": "Cambia data creazione",
Expand All @@ -106,7 +108,8 @@
"restored-successfully": "Ripristinato con successo",
"succeed-copy-link": "Link copiato.",
"update-succeed": "Aggiornato con successo",
"user-not-found": "Utente non trovato"
"user-not-found": "Utente non trovato",
"remove-completed-task-list-items-successfully": "Rimosso con successo!"
},
"resource": {
"clear": "Cancella",
Expand Down Expand Up @@ -253,7 +256,8 @@
"enable-password-login-warning": "Ciò consentirà l'accesso tramite password per tutti gli utenti. Continua solo se desideri che gli utenti possano accedere utilizzando sia SSO che password❗",
"max-upload-size": "Dimensione massima caricamento (MiB)",
"max-upload-size-hint": "Valore consigliato di 32 MiB.",
"server-name": "Nome server"
"server-name": "Nome server",
"removed-completed-task-list-items": "Abilita rimuovi completato"
}
},
"tag": {
Expand Down
Loading

0 comments on commit f00751a

Please sign in to comment.