@bigbinary/neeto-trash-frontend

中文文档
3.2.3发布于 2026/10/29UNLICENSEDTypeScriptESM + CJS近 30 天下载 6498

A repo acts as the source of truth for the new nano's structure, configs, data etc.

原始使用文档
文档目录6 节
  1. Contents
  2. Development with Host Application
  3. Engine
  4. Frontend package
  5. Instructions for development
  6. Instructions for Publishing

neeto-trash-nano

The neeto-trash-nano acts as the source of truth for the new nano's structure, configs, data etc.

Contents

  1. Development with Host Application
  2. Instructions for Publishing

Development with Host Application

Engine

Installation

  1. Add this line to your application's Gemfile:

     source "NEETO_GEM_SERVER_URL" do
       # ..existing gems
    
       gem 'neeto-trash-engine'
     end
    
  2. And then execute:

    bundle install
    
  3. Add this line to your application's config/routes.rb file

     mount NeetoTrashEngine::Engine, at: "/neeto_trash"
    
  4. Add required migrations in the db/migrate folder. Run the following commands to copy the migrations from the engine to the host application.

    bundle exec rails neeto_trash_engine:install:migrations
    bundle exec rails db:migrate
    

Setup generators

  1. rails g neeto_trash_engine:install

    Sets up everything a host application needs to use the engine:

    • Mounts NeetoTrashEngine::Engine at /neeto_trash in config/routes.rb.
    • Copies app/lib/neeto_trash_engine/callbacks.rb, the authorization contract the engine delegates permission/organization-scoping decisions to.
    • Copies config/initializers/neeto_trash_engine.rb, which configures the retention period, the current user resolver, and the callbacks class.
    • Adds a trash_cleanup entry to config/scheduled_jobs.yml that runs NeetoTrashEngine::CleanupJob daily. If config/scheduled_jobs.yml doesn't exist, the generator prints the entry to add manually instead of creating the file.

    Running the generator again is safe: it skips any step whose target file already exists or already contains the expected entry.

  2. rails g neeto_trash_engine:trashable Article

    Generates a migration (db/migrate/add_neeto_trash_to_articles.rb) that adds the columns a model needs to support trashing: is_trashed, trashed_at, a trashed_by reference to users, and a composite index on [:is_trashed, :trashed_at]. The table name is taken from the model when it already exists, and the trashed_by reference type matches the host application's configured primary key type (e.g. :uuid).

Usage

Models including NeetoTrashEngine::Trashable can override their deletion methods. Single deletion and retention cleanup call permanently_delete!, which defaults to destroy!. Bulk deletion calls permanently_delete_all! on the authorized scope. Its default calls destroy_all and raises when a callback stops deletion, so the bulk transaction rolls back.

An asynchronous implementation must immediately hide the record from the trash list and enqueue cleanup after the transaction commits. For models that include NeetoCommonsBackend::Deletable, use the existing methods for both deletion paths:

def permanently_delete!
  destroy_async
end

def self.permanently_delete_all!
  destroy_async_multiple(pluck(:id))
end

The bulk override hides the selected records in one update and queues one job after commit. Retention cleanup keeps its per-record lock and eligibility check.

Overrides must preserve the host model's destroy callbacks and dependent cleanup. Use destroy! or the application's existing deletion service for physical deletion. For asynchronous deletion, the background worker must perform this cleanup.

  1. Replace NeetoTrashNano with your project name

    Create a script.rb file in the project root and paste the script from the following file.

    Replace project name script

  2. Run the file using the following command:

       ruby script.rb
    

Notes ⚠️

  • Don't commit this file.
  • Project name should be given in PascalCase.

Frontend package

Installation

  1. Add the neeto-trash-frontend package to the package.json

    yarn add @bigbinary/neeto-trash-frontend
    

Instructions for development

Check the Frontend package development guide for step-by-step instructions to develop the frontend package.

Usage

  1. Mount the trash page by importing TrashList from "@bigbinary/neeto-trash-frontend" and telling it which item types your app trashes:

    import React from "react";
    
    import { TrashList } from "@bigbinary/neeto-trash-frontend";
    
    const Trash = () => <TrashList itemTypes={{ Article: { label: "Articles" } }} />;
    
    export default Trash;
    
  2. Wire the delete action in your app's menus to move items to trash instead of hard-deleting:

    import { MoveToTrashAction } from "@bigbinary/neeto-trash-frontend";
    
    <MoveToTrashAction ids={[article.id]} type="Article" onSuccess={refetchArticles} />;
    

    The package also exports TrashBanner, RestoreButton, DeletePermanentlyAction, the data hooks (useFetchTrashedItems, useMoveToTrash, useRestore, usePermanentlyDelete, useInvalidateTrashList), getDaysUntilDeletion, and QUERY_KEYS.

  3. Keep the Trash page in sync when you trash from your own endpoint.

    If you move items to trash with MoveToTrashAction / useMoveToTrash (step 2), the Trash page's list and counts refresh automatically — that hook invalidates the trash query for you, so there is nothing extra to do.

    Most apps, however, trash through their own delete endpoint instead, so the same request can run app-specific side effects (analytics, cascades) and refresh their own lists. That path never runs the package's mutation, so the Trash page stays stale until you invalidate its query yourself. Drop useInvalidateTrashList into that mutation's onSuccess:

    import { useInvalidateTrashList } from "@bigbinary/neeto-trash-frontend";
    
    const useDestroyArticle = () => {
      const queryClient = useQueryClient();
      const invalidateTrashList = useInvalidateTrashList();
    
      return useMutation({
        mutationFn: articlesApi.destroy,
        onSuccess: () => {
          queryClient.invalidateQueries({ queryKey: [ARTICLE_LIST] }); // your list
          invalidateTrashList(); // refreshes the Trash page list + counts
        },
      });
    };
    

    useInvalidateTrashList returns a callback that invalidates QUERY_KEYS.TRASHED_ITEMS, so you never hardcode the trash query key. (Restore and permanent-delete inside TrashList already invalidate it themselves — this is only needed for your own move-to-trash path.)

Instructions for Publishing

Consult the building and releasing packages guide for details on how to publish.

版本与发布记录

@bigbinary/neeto-trash-frontend 共发布 8 个版本,首次发布于 2026/07/14;过去 12 个月发布了 8 个版本。

版本发布日期距今
3.2.3latest2026/10/2910 天前
3.2.2-beta2beta2026/10/2910 天前
3.2.22026/10/2910 天前
3.2.2-beta12026/10/2910 天前
3.2.12026/10/2315 天前
3.2.1-beta12026/10/2315 天前

关于 @bigbinary/neeto-trash-frontend 的常见问题

@bigbinary/neeto-trash-frontend 是什么?

A repo acts as the source of truth for the new nano's structure, configs, data etc.

如何安装 @bigbinary/neeto-trash-frontend?

在项目目录运行 npm install @bigbinary/neeto-trash-frontend,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:qs(6.16.2)、url(0.11.4)、yup(0.32.11)、antd(5.22.1)、util(^0.12.5)、axios(1.20.0)、ramda(0.29.0)、react(18.3.1)、buffer(^6.0.3)、formik(2.4.6)、i18next(22.5.1)、zustand(4.4.2)、dompurify(3.4.17)、js-logger(1.6.1)、react-dom(18.3.1)、classnames(2.5.1)、stream-http(3.2.0)、tailwindcss(4.1.17)、lucide-react(^1.8.0)、react-helmet(^6.1.0)、os-browserify(0.3.0)、react-i18next(12.3.1)、vm-browserify(1.1.2)、@babel/runtime(7.29.7)、react-toastify(8.0.2)、tty-browserify(0.0.1)、path-browserify(^1.0.1)、https-browserify(1.0.0)、mixpanel-browser(2.45.0)、react-router-dom(5.3.3)、crypto-browserify(3.12.1)、source-map-loader(4.0.1)、stream-browserify(^3.0.0)、@bigbinary/neetoui(8.8.3)、@honeybadger-io/js(6.10.1)、@bigbinary/neeto-cist(1.0.17)、@honeybadger-io/react(6.1.25)、@tanstack/react-query(5.59.20)、@bigbinary/neeto-atoms(1.1.2)、@bigbinary/neeto-icons(1.20.89)、@bigbinary/neeto-molecules(5.9.10)、@tanstack/react-query-devtools(5.59.20)、@bigbinary/neeto-commons-frontend(4.14.5)、@bigbinary/neeto-filters-frontend(4.5.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bigbinary/neeto-trash-frontend 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bigbinary/neeto-trash-frontend 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bigbinary/neeto-trash-frontend 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.13。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bigbinary/neeto-trash-frontend 可以商用吗?

@bigbinary/neeto-trash-frontend 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@bigbinary/neeto-trash-frontend 的下载量有多少?

根据 npm 官方下载统计,@bigbinary/neeto-trash-frontend 在 2026/10/08 – 2026/11/06 这 30 天内被下载 6,498 次,日均约 217 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bigbinary/neeto-trash-frontend 还在维护吗?

最新版本 3.2.3 发布于 2026/10/29(10 天前);至今共发布 8 个版本,其中过去 12 个月发布了 8 个;首次发布于 2026/07/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。