Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Insights): Insights inside Instantsearch #3598

Merged
merged 9 commits into from Apr 15, 2019

Commits on Apr 12, 2019

  1. feat(Insights): integrate Insights (Click Analytics) with InstantSearch

    feat(Insights): add withInsightsClient connector wrapper
    
    This PR adds a withInsightsClient which is an HOC for connectors.
    
    ```js
    const connectHitsWithInsightsClient = withInsightsClient(connectHits)
    ```
    
    This connector will be used by default in the widget Hits and
    InfiniteHits to wrap connectHits and connectInfiniteHits respectively.
    
    When this PR is merged and released we can start using
    withInsightsClient in the flavours.
    
    feat(Insights): add template helpers
    
    feat(Insights): add withInsightsListener
    
    This commit adds withInsightsListener which
    - wraps Hits and InfiniteHits component,
    - listens to inner clicks targetting elements with data-insights attributes
    - calls the insights client exposed by `withInsightsClient`
    
    ```js
    const HitsWithInsightsListener = withInsightsListener(Hits)
    
    ```
    
    feat(Insights): allow passing insightsClient to instantsearch instance
    
    feat(Insights): add listener to Hits
    
    feat(Insights): add listener to InfiniteHits
    
    feat(Insights): add storybook example for hits
    
    feat(Insights & typescript): type all the things
    
    extract *WithInsightsListeners components to upper scope
    
    rename withInsightsClient to withInsights
    
    feat(Insights): fix positions in infiniteScroll
    
    feat(Insights): extract addAbsolutePositions to make it connector responsibility
    
    unshorten variable name ev -> event
    
    rename isFirstRendering -> isFirstRender
    
    type mouse event
    
    avoid inline return
    
    clean unsused comment
    
    avoid inline return
    
    inline cast document.querySelector<HTMLElement>
    
    prettier things
    
    remove document maniputation in tests
    
    remove inferrable types in readDataAttributes
    
    use post modern typing
    
    type return values
    
    Apply suggestions from code review
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    add space before describe
    
    change inferPayload signature to use named params
    
    remove perf comment
    
    add space before Unmounter
    
    Apply suggestions from code review
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    Update src/lib/__tests__/insights-client-test.js
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    remove param mutation
    
    absolute imports before relative
    
    convert to typescript client and listener tests
    
    factorize Without inside 'types/utils'
    
    simplify types
    
    typo
    
    feedback: expose addAbsolutePosition in utils
    
    feedback: improved error message
    
    add type on serializedPayload
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    casting div.firstElementChild with as keyword
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    feedback: move casting on another line
    
    feedback: improve error message on incorrect data-insights-payload json string
    
    prettier all the things
    
    feedback: add type for Hits React component
    
    fix typescript file linting
    
    add query id
    
    feat(insights): add __queryID to connectHits & connectInfiniteHits
    
    simplified tests
    
    feat(insights): encode payload to base64
    
    typo
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    typo
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    feedback: fix insightsClient defaulting to jest.fn()
    
    feedback: remove unused beforeEach
    
    feedback: group expect statements for payloads
    
    typo
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    feedback: add quotes around objectID
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    feedback: rename WidgetParams -> TWidgetParams
    
    feedback: move clickAnalytics: true to configure
    
    feedback: use toHaveBeenNthCalledWith
    
    feedback: remove extra check for insightClient callability
    
    feedback: remove proptypes
    
    fix: typo
    
    inline setup function
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: error message formatting
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: error message formatting
    
    Co-Authored-By: tkrugg <tkrugg@users.noreply.github.com>
    
    fix: update snapshots after error message reformatting
    tkrugg committed Apr 12, 2019
    Copy the full SHA
    f3c6641 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    75898f1 View commit details
    Browse the repository at this point in the history
  3. fix: linting

    tkrugg committed Apr 12, 2019
    Copy the full SHA
    be03981 View commit details
    Browse the repository at this point in the history
  4. fix: types

    tkrugg committed Apr 12, 2019
    Copy the full SHA
    6244430 View commit details
    Browse the repository at this point in the history
  5. Copy the full SHA
    58a2b62 View commit details
    Browse the repository at this point in the history
  6. feat(Insights): expose insights helper on instantsearch instance

    This is mimicking the way we allow usage for `highlight` and `snippet`.
    
    ```js
      Instantsearch.widgets.hits({
        // ...
        templates: {
          item(hit) {
            return `
              <h2> ${hit.name} </h2>
              <button ${
                Instantsearch.insights('clickedObjectIDsAfterSearch', {
                  eventName: "Add to favorite",
                  objectIDs: [hit.objectID]
                })
              }>
                Add to favorite
              </button>
            `;
          },
        },
      });
    ```
    tkrugg committed Apr 12, 2019
    Copy the full SHA
    cb7d3ff View commit details
    Browse the repository at this point in the history

Commits on Apr 15, 2019

  1. feat(Insights): expose connectHitsWithInsights and connectInfiniteHit…

    …sWithInsights
    
    The intention is to make it easier and more straight forward to create
    custom InfiniteHits and Hits with the connector.
    
    If we exposed `withInsights` directly, this is what we'd need to decide
    on a definitive name that implies it works only on Hits (like withHitsInsights)
    
    ```js
    const connectHitsWithInsights = Instantsearch.connectors.withHitsInsights(Instantsearch.connectors.connectHits);
    const connectInfiniteHitsWithInsights = Instantsearch.connectors.withHitsInsights(Instantsearch.connectors.connectInfiniteHits);
    ```
    
    If we expose `connectHitsWithInsights` and `connectInfiniteHitsWithInsights` directly, we can keep `withInsights` totally private, and all custom components example are more simple.
    tkrugg committed Apr 15, 2019
    Copy the full SHA
    1cc932e View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    b8d4c0c View commit details
    Browse the repository at this point in the history
  3. Copy the full SHA
    77a7174 View commit details
    Browse the repository at this point in the history