<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Taha Husain</title>
    <link>https://tahahusain.net/</link>
    <description>Recent content on Taha Husain</description>
    <generator>Hugo</generator>
    <language>en</language>
    <lastBuildDate>Fri, 22 Oct 2021 15:12:17 +0530</lastBuildDate>
    <atom:link href="https://tahahusain.net/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>React Table - How to implement row selection with controlled server-side pagination</title>
      <link>https://tahahusain.net/posts/tech/react-table-row-selection-with-controlled-pagination/</link>
      <pubDate>Fri, 22 Oct 2021 15:12:17 +0530</pubDate>
      <guid>https://tahahusain.net/posts/tech/react-table-row-selection-with-controlled-pagination/</guid>
      <description>&lt;p&gt;In this blog,&#xA;we will implement&#xA;multi-row selection&#xA;and select all&#xA;with controlled&#xA;server-side pagination&#xA;in React&#xA;using React Table hooks.&lt;/p&gt;&#xA;&lt;p&gt;We will use&#xA;examples provided by&#xA;&lt;code&gt;react-table&lt;/code&gt; for&#xA;&lt;a href=&#34;https://react-table.tanstack.com/docs/examples/pagination-controlled&#34;&gt;controlled pagination&lt;/a&gt;&#xA;and&#xA;&lt;a href=&#34;https://react-table.tanstack.com/docs/examples/row-selection-and-pagination&#34;&gt;row selection and pagination&lt;/a&gt;&#xA;and work our way to acheive desired result.&lt;/p&gt;&#xA;&lt;h3 id=&#34;implementation&#34;&gt;Implementation&lt;/h3&gt;&#xA;&lt;h4 id=&#34;step-1&#34;&gt;Step 1&lt;/h4&gt;&#xA;&lt;p&gt;To select all rows,&#xA;we would need unique identifier&#xA;of all rows pre-fetched&#xA;on the page.&#xA;Pass all ids to the &lt;code&gt;Table&lt;/code&gt; component.&lt;/p&gt;&#xA;&lt;h4 id=&#34;step-2&#34;&gt;Step 2&lt;/h4&gt;&#xA;&lt;p&gt;Use &lt;code&gt;getToggleAllRowsSelectedProps&lt;/code&gt;&#xA;instead of &lt;code&gt;getToggleAllPageRowsSelectedProps&lt;/code&gt;&#xA;for header checkbox&#xA;to trigger rows select event across&#xA;all pages.&#xA;Note - &lt;code&gt;getToggleAllRowsSelectedProps&lt;/code&gt; works&#xA;seamlessly for frontend pagination,&#xA;but needs to be customized for&#xA;server-side pagination.&lt;/p&gt;</description>
    </item>
    <item>
      <title>Theremin</title>
      <link>https://tahahusain.net/posts/music/theremin/</link>
      <pubDate>Sat, 09 Oct 2021 07:27:55 +0530</pubDate>
      <guid>https://tahahusain.net/posts/music/theremin/</guid>
      <description>&lt;p&gt;Theremin - a music instrument played without touching.&lt;/p&gt;&#xA;&lt;p&gt;It is known to be&#xA;one of the first&#xA;electronic instrument,&#xA;invented about 100 years ago.&lt;/p&gt;&#xA;&lt;p&gt;Mind blown!&lt;/p&gt;&#xA;&#xA;&lt;iframe width=&#34;100%&#34; height=&#34;315&#34; src=&#34;https://www.youtube.com/embed/wrUo9hmNwts&#34; title=&#34;YouTube video player&#34; frameborder=&#34;0&#34; allow=&#34;accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture&#34; allowfullscreen&gt;&lt;/iframe&gt;</description>
    </item>
    <item>
      <title>Capybara with Rspec - How to find and assert fields</title>
      <link>https://tahahusain.net/posts/tech/capybara-with-rspec-how-to-find-and-assert-fields/</link>
      <pubDate>Fri, 01 Oct 2021 11:45:14 +0530</pubDate>
      <guid>https://tahahusain.net/posts/tech/capybara-with-rspec-how-to-find-and-assert-fields/</guid>
      <description>&lt;p&gt;Capybara provides&#xA;&lt;a href=&#34;https://www.rubydoc.info/gems/capybara/Capybara%2FNode%2FFinders:find_field&#34;&gt;&lt;em&gt;find_field&lt;/em&gt;&lt;/a&gt;&#xA;API to find input fields.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;find_field&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;id_of_checkbox&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;ss&#34;&gt;type&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;checkbox&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;To add assertions&#xA;for input fields&#xA;we can use&#xA;Rspec matcher&#xA;&lt;a href=&#34;https://www.rubydoc.info/gems/capybara/Capybara%2FRSpecMatchers:have_field&#34;&gt;&lt;em&gt;have_field&lt;/em&gt;&lt;/a&gt;&#xA;which has similar usage as &lt;code&gt;find_field&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-ruby&#34; data-lang=&#34;ruby&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;expect&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;page&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;have_field&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt;&amp;#39;id_of_checkbox&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;ss&#34;&gt;type&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;checkbox&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;In some cases input fields are not&#xA;found using &lt;code&gt;find_field&lt;/code&gt;,&#xA;specially when input field(s)&#xA;are added by third party library.&lt;/p&gt;&#xA;&lt;p&gt;Let&amp;rsquo;s take an example of&#xA;&lt;a href=&#34;https://atlassian.design/components/toggle/examples&#34;&gt;toggle&lt;/a&gt;&#xA;component that we recently used&#xA;to understand this problem better.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-jsx&#34; data-lang=&#34;jsx&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;Toggle&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;na&#34;&gt;id&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;toggleId&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;na&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;toggleName&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;na&#34;&gt;size&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;large&amp;#34;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;na&#34;&gt;isDisabled&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;disableToggle&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;na&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;toggleValue&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;na&#34;&gt;isChecked&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;toggleValue&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;  &lt;span class=&#34;na&#34;&gt;onChange&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;nx&#34;&gt;handleToggleChange&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;/&amp;gt;&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Adding above component&#xA;in react code generates&#xA;following HTML.&lt;/p&gt;</description>
    </item>
    <item>
      <title>React Datepicker - How to select Date and time in UTC</title>
      <link>https://tahahusain.net/posts/tech/react-datepicker-how-to-select-date-time-in-utc/</link>
      <pubDate>Sun, 19 Sep 2021 11:28:55 +0530</pubDate>
      <guid>https://tahahusain.net/posts/tech/react-datepicker-how-to-select-date-time-in-utc/</guid>
      <description>&lt;p&gt;By default, &lt;a href=&#34;https://www.npmjs.com/package/react-datepicker&#34;&gt;React Datepicker&lt;/a&gt;&#xA;selects date and time in local timezone.&#xA;To select date in a specified timezone&#xA;we need to convert timezone manually.&#xA;To do so, we may also need to use library like&#xA;&lt;a href=&#34;https://momentjs.com/timezone/&#34;&gt;Moment Timezone&lt;/a&gt;.&lt;/p&gt;&#xA;&lt;p&gt;This blog focuses on selecting date and time in&#xA;standard UTC timezone&#xA;and its implementation doesn&amp;rsquo;t require&#xA;extra library installation.&lt;/p&gt;&#xA;&lt;p&gt;The original&#xA;&lt;a href=&#34;https://github.com/JohnStarich/sage/blob/b422b0ccef05fffe29143f335017ad2fc24f76fc/web/src/UTCDatePicker.js&#34;&gt;implementation&lt;/a&gt;&#xA;is suggested by&#xA;&lt;a href=&#34;https://github.com/JohnStarich&#34;&gt;@JohnStarich&lt;/a&gt;.&#xA;This implementation has a bit of tweak to accommodate time picker.&lt;/p&gt;</description>
    </item>
    <item>
      <title>React 18 introduces Automatic Batching</title>
      <link>https://tahahusain.net/posts/tech/react-18-introduces-automatic-batching/</link>
      <pubDate>Fri, 09 Jul 2021 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/react-18-introduces-automatic-batching/</guid>
      <description></description>
    </item>
    <item>
      <title>Sort query data on associated table in PostGraphile</title>
      <link>https://tahahusain.net/posts/tech/sort-query-data-on-associated-tables-in-postgraphile/</link>
      <pubDate>Tue, 19 Jan 2021 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/sort-query-data-on-associated-tables-in-postgraphile/</guid>
      <description></description>
    </item>
    <item>
      <title>Ruby 2.7 deprecates conversion of keyword arguments</title>
      <link>https://tahahusain.net/posts/tech/ruby-2-7-deprecates-conversion-of-keyword-arguments/</link>
      <pubDate>Tue, 14 Apr 2020 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/ruby-2-7-deprecates-conversion-of-keyword-arguments/</guid>
      <description></description>
    </item>
    <item>
      <title>Ruby 2.7 adds numbered parameters as default block parameters</title>
      <link>https://tahahusain.net/posts/tech/ruby-2-7-adds-numbered-parameters/</link>
      <pubDate>Tue, 03 Mar 2020 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/ruby-2-7-adds-numbered-parameters/</guid>
      <description></description>
    </item>
    <item>
      <title>Rails 6 adds ActionMailer#email_address_with_name</title>
      <link>https://tahahusain.net/posts/tech/rails-6-adds-actionmailer-email-address-with-name/</link>
      <pubDate>Tue, 22 Oct 2019 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/rails-6-adds-actionmailer-email-address-with-name/</guid>
      <description></description>
    </item>
    <item>
      <title>Rails 6 adds ActiveSupport::ActionableError</title>
      <link>https://tahahusain.net/posts/tech/rails-6-adds-activesupport-actionable-error/</link>
      <pubDate>Tue, 01 Oct 2019 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/rails-6-adds-activesupport-actionable-error/</guid>
      <description></description>
    </item>
    <item>
      <title>Rails 6 Pass custom config to ActionCable::Server::Base</title>
      <link>https://tahahusain.net/posts/tech/rails-6-custom-config-actioncable-server/</link>
      <pubDate>Wed, 21 Aug 2019 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/rails-6-custom-config-actioncable-server/</guid>
      <description></description>
    </item>
    <item>
      <title>Recyclable cache keys in Rails</title>
      <link>https://tahahusain.net/posts/tech/rails-recyclable-cache-keys/</link>
      <pubDate>Tue, 06 Aug 2019 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/rails-recyclable-cache-keys/</guid>
      <description></description>
    </item>
    <item>
      <title>Rails 6 deprecates where.not as NOR &amp; Rails 6.1 as NAND</title>
      <link>https://tahahusain.net/posts/tech/rails-6-deprecates-where-not-nor/</link>
      <pubDate>Wed, 31 Jul 2019 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/rails-6-deprecates-where-not-nor/</guid>
      <description></description>
    </item>
    <item>
      <title>Rails 6 adds ActiveRecord::Relation#extract_associated</title>
      <link>https://tahahusain.net/posts/tech/rails-6-adds-activerecord-extract-associated/</link>
      <pubDate>Wed, 17 Apr 2019 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/rails-6-adds-activerecord-extract-associated/</guid>
      <description></description>
    </item>
    <item>
      <title>Ruby 2.6 adds write_timeout to Net::HTTP</title>
      <link>https://tahahusain.net/posts/tech/ruby-2-6-adds-write-timeout-net-http/</link>
      <pubDate>Tue, 14 Aug 2018 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/ruby-2-6-adds-write-timeout-net-http/</guid>
      <description></description>
    </item>
    <item>
      <title>Ruby 2.6 adds Binding#source_location</title>
      <link>https://tahahusain.net/posts/tech/ruby-2-6-adds-binding-source-location/</link>
      <pubDate>Tue, 24 Jul 2018 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/ruby-2-6-adds-binding-source-location/</guid>
      <description></description>
    </item>
    <item>
      <title>Ruby 2.6 adds String#split with block</title>
      <link>https://tahahusain.net/posts/tech/ruby-2-6-adds-split-with-block/</link>
      <pubDate>Tue, 17 Jul 2018 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/ruby-2-6-adds-split-with-block/</guid>
      <description></description>
    </item>
    <item>
      <title>Ruby 2.6 adds endless range</title>
      <link>https://tahahusain.net/posts/tech/ruby-2-6-adds-endless-range/</link>
      <pubDate>Wed, 04 Jul 2018 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/posts/tech/ruby-2-6-adds-endless-range/</guid>
      <description></description>
    </item>
    <item>
      <title>Portfolio</title>
      <link>https://tahahusain.net/portfolio/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/portfolio/</guid>
      <description></description>
    </item>
    <item>
      <title>Resume</title>
      <link>https://tahahusain.net/resume/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://tahahusain.net/resume/</guid>
      <description></description>
    </item>
  </channel>
</rss>
