npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bigbinary/neeto-activities-frontend

v2.1.1

Published

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

Downloads

17

Readme

neeto-activities-nano

The nano that manages backend structure for activities.

Schema

create_table :neeto_activities_engine_activities, id: :uuid do |t|

   # Parent association for the activity, example: Ticket
   t.references :trackable, polymorphic: true, index: true, type: :uuid

   # Performer of the activity, example: User
   t.references :performer, polymorphic: true, type: :uuid

   # Unique key per activity that can be used in translations to render on UI
   t.string :key

   # Any additional details that might be helpful for building the translations or debugging purpose
   t.jsonb :metadata, default: {}

   t.timestamps

end

Usage

Example

Check an example of an activity generated for updating the ticket status in neetoDesk.

#<NeetoActivitiesEngine::Activity:0x000000013237f158> {
                :id => "d0458158-68d1-423f-b364-d22a8916f6d0",
               :key => "activity.ticket.update.status",
    :trackable_type => "Ticket",
      :trackable_id => "c5104a50-2eff-49a3-accb-f2fa8f4fc1f7",
    :performer_type => "User",
      :performer_id => "b028d29e-f40a-4c09-9222-357cfe84e2c3",
        :created_at => Mon, 30 Oct 2023 10:23:26.705884000 UTC +00:00,
        :updated_at => Mon, 30 Oct 2023 10:23:26.705884000 UTC +00:00,
          :metadata => {
        "new_value" => "trash",
        "old_value" => "open"
    }
}

Concern

We have a concern that can be included in the models that need to track the activities, this concern adds associations and a helper method that allows creating activities easily.

Refer: NeetoActivitiesEngine::Trackable

Example:

class User
   include NeetoActivitiesEngine::Trackable

   after_save :log_account_block_activity!, if: :blocked?

   private

      def log_account_block_activity!
         old_value, new_value = saved_change_to_blocked_at

         key = new_value ? "activity.user.blocked" : "activity.user.unblocked"
         metadata = { performer_name: User.current&.name }

         log_activity!(key:, metadata:, performer: User.current)
      end
end

Complex implementation

neetoDesk needs many custom activities for tickets, in order to achieve it, we have created another concern that works on top of the above concern.

Refer: app/models/concerns/trackable/tickets.rb

Usage:

class Ticket
   include NeetoActivitiesEngine::Trackable
   include Trackable::Tickets # Depends on NeetoActivitiesEngine::Trackable
end

Use different provider than User.current

Using User.current is not a good practice, it also does not fit in all the places.

Example: In neetoDesk, Automation rules can update tickets, here the performer is Automation::Rule not User.

To get around this problem, we have activity_performer attr_accessor.

class Ticket
   include NeetoActivitiesEngine::Trackable

   after_save :log_status_activity!, if: :saved_change_to_status?

   private

      def log_status_activity!
         old_value, new_value = saved_change_to_status

         key = "activity.ticket.status.update"
         metadata = { old_value:, new_value: }

         log_activity!(key: , metadata:, performer: activity_performer)
      end
end

ticket.activity_performer = Automation::Rule.first
ticket.update(status: :closed)

Skip an activity in a special case?

Occationally, the business logic demands to skip the activity. For this, we have added skip_activity attr_accessor in the concern.

Example: Assume that you want to skip the activities when you update the ticket from Rails console.

class Ticket
   include NeetoActivitiesEngine::Trackable

   after_save :log_status_activity!, if: :saved_change_to_status?

   private

      def log_status_activity!
         old_value, new_value = saved_change_to_status

         key = "activity.ticket.status.update"
         metadata = { old_value:, new_value: }

         log_activity!(key: , metadata:, performer: activity_performer)
      end
end

# rails c
ticket.skip_activity = true
ticket.update(status: :closed)