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

connectHits sortable table access to helper #2520

Closed
rogerroelofs opened this issue Oct 24, 2017 · 13 comments
Closed

connectHits sortable table access to helper #2520

rogerroelofs opened this issue Oct 24, 2017 · 13 comments

Comments

@rogerroelofs
Copy link
Contributor

What is your use case for such a feature?
I would like to build a sortable table custom widget that combines the functionality of the hits and sort widgets.

What is your proposed API entry? The new option to add? What is the behavior?
All that is needed is to add the helper object to the init parameters in src/connectors/hits/connectHits.js This would allow the custom widget to call the setIndex().search() method to trigger the search, sort and redraw.

(If there's a better way, I'm all ears)

@timkelty
Copy link
Contributor

Working on this with @rogerroelofs, would love to find a solution!

@bobylito
Copy link
Contributor

Hi @rogerroelofs and @timkelty, thanks for opening this issue.

We've chosen to make the API of the connectors an abstraction over the Helper. Adding it would be practical but not in the spirit of the connectors.

Why not use the hits widget for the body of the table and use a custom widget (based on connectors) for the each column header?

@timkelty
Copy link
Contributor

timkelty commented Oct 24, 2017

@bobylito So you're suggesting something like this? (pseudocode)

<table>
	<thead>
		<tr>
			<td>{{ customWidget({asc: 'productsAsc', desc: 'productsDesc'}))}}</td>
			<td>{{ customWidget({asc: 'productsPriceAsc', desc: 'productsPriceDesc'}))}}</td>
		</tr>
	</thead>
	<tbody>
		{{ hitsWidget }}
	</tbody>
</table>

We were trying to create a single widget for the entire thing, so that we could pass a single columns array and not have to worry as much about our column counts lining up.

@bobylito
Copy link
Contributor

I thought you wanted to have custom sort for each column. I had some excel / spreadsheet layout in mind, I was wrong :)

Can you show me what the design should be?

@timkelty
Copy link
Contributor

timkelty commented Oct 24, 2017

I thought you wanted to have custom sort for each column.

@bobylito No, that's what we're after - I think you had it right…here's our mockup:
https://www.evernote.com/l/AAL7CNj5QzlOi7n8JkMr3UAv_sPy1imVArM

We could achieve this using the hits widget as-is, and creating a "toggle index" widget that would toggle between sorted/slave indexes.

The drawback to this managing & lining up the columns between the templating. For this reason, we wanted to create a single widget that accepted settings like:

{
    container: someDomElement,
    columns: [
        {
            templates: {
                header: ``,
                cell: ``,
            },
            ascIndex: 'productsByRatingAsc',
            descIndex: 'productsByRatingDesc',
        },
    ],
}

@bobylito
Copy link
Contributor

So yes I would for what I proposed first. It is the most straightforward approach.

But then I don't know what is your need for reusability or If it needs to be configurable and managed by some end-users. Is it the case?

@timkelty
Copy link
Contributor

But then I don't know what is your need for reusability or If it needs to be configurable and managed by some end-users. Is it the case?

Either approach works for us, it just seemed like an opportunity to share a configurable widget with the community, as it seemed like there were quite a few people asking for a "sortable IS table" widget.

@timkelty
Copy link
Contributor

timkelty commented Oct 24, 2017

The other option of course is to just not use (or use a forked version of) connectHits, which is what we're doing. We just wanted it to behave as much like hits as possible.

We'll proceed with this route, but if you have any other ideas how we might leverage connectHits, let us know!

@Haroenv
Copy link
Contributor

Haroenv commented Oct 24, 2017

I'm wondering if the "table component" couldn't be

---------------
connectSortBy
---------------
connectHits
---------------

This all together wouldn't be a "single widget", but still something you can import and add options to

@bobylito
Copy link
Contributor

Either approach works for us, it just seemed like an opportunity to share a configurable widget with the community, as it seemed like there were quite a few people asking for a "sortable IS table" widget.

That would be a great idea :)

The other option of course is to just not use (or use a forked version of) connectHits, which is what we're doing.

That would be too bad indeed. How do you see the API of a table widget? Why use a connector in this context? I'd be happy to see what you've come up with.

@timkelty
Copy link
Contributor

@rogerroelofs is doing the heavy lifting, want to share what the API is currently looking like?

@rogerroelofs
Copy link
Contributor Author

rogerroelofs commented Oct 24, 2017

I am modeling after the hits widget as much as possible. If we were just doing a table I might have preferred an api closer to https://github.com/react-tools/react-table but our use case is a bit more complicated than that.

Here's what I have so far. It is the hits api + a columns object

dataTableWidget({
        container: this.$container.find(this.config.selectors.dataTable)[0],
        hitsPerPage: this.config.hitsPerPage,
        transformData: (data) => {
           ...
        },
        templates: {
          allItems: `
        {{#hits}}
          {{#fullWidthAd}}
            <tr>
              <td colspan="{{columns.length}}">{{{ fullWidthAd }}}</td>
            </tr>
          {{/fullWidthAd}}
            <tr>
              <td></td>
              <td>{{ manufacturer.0.title }}</td>
              <td>{{ title }}</td>
              <td>{{ ratingAvg }}</td>
              <td>{{ reviewTotal }}</td>
            </tr>
        {{/hits}}
`,
          empty: config.templates.noResults
        },
        columns: [
          {
            templates: {
              header: ``,
            },
          },
          {
            templates: {
              header: `Brand`,
            },
          },
          {
            templates: {
              header: `Product`,
            },
          },
          {
            templates: {
              header: `Review Score`,
            },
            ascIndex: 'productsByRatingAsc',
            descIndex: 'productsByRatingDesc',
          },
          {
            templates: {
              header: `# of Reviews`,
              cell: `{{ reviewTotal }}`,
            },
            ascIndex: 'productsByReviewTotalAsc',
            descIndex: 'productsByReviewTotalDesc',
          },
        ]
      })

@Haroenv
Copy link
Contributor

Haroenv commented Nov 15, 2019

Sorry for not responding further here. IIRC it was taken up via support and now this thread no longer seems useful, which is why I'll close it :)

@Haroenv Haroenv closed this as completed Nov 15, 2019
Haroenv pushed a commit that referenced this issue Jan 4, 2023
# [6.0.0-beta.1](algolia/react-instantsearch@v5.7.0...v6.0.0-beta.1) (2019-10-18)

### Bug Fixes

* **connectToggleRefinement:** cast currentRefinement to boolean ([algolia/react-instantsearch#2701](algolia/react-instantsearch#2701)) ([aaf8043](algolia/react-instantsearch@aaf8043))
* **deps:** update dependency antd to v3.19.3 ([algolia/react-instantsearch#2530](algolia/react-instantsearch#2530)) ([a2a9ba0](algolia/react-instantsearch@a2a9ba0))
* **deps:** update dependency antd to v3.19.4 ([algolia/react-instantsearch#2559](algolia/react-instantsearch#2559)) ([c0d13a5](algolia/react-instantsearch@c0d13a5))
* **deps:** update dependency antd to v3.19.5 ([algolia/react-instantsearch#2560](algolia/react-instantsearch#2560)) ([089ed3e](algolia/react-instantsearch@089ed3e))
* **deps:** update dependency antd to v3.19.6 ([algolia/react-instantsearch#2564](algolia/react-instantsearch#2564)) ([eb496fb](algolia/react-instantsearch@eb496fb))
* **deps:** update dependency antd to v3.19.7 ([algolia/react-instantsearch#2573](algolia/react-instantsearch#2573)) ([f76c9b9](algolia/react-instantsearch@f76c9b9))
* **deps:** update dependency antd to v3.19.8 ([algolia/react-instantsearch#2584](algolia/react-instantsearch#2584)) ([2d243cd](algolia/react-instantsearch@2d243cd))
* **deps:** update dependency antd to v3.20.0 ([algolia/react-instantsearch#2611](algolia/react-instantsearch#2611)) ([635c0ee](algolia/react-instantsearch@635c0ee))
* **deps:** update dependency antd to v3.20.1 ([algolia/react-instantsearch#2635](algolia/react-instantsearch#2635)) ([c45ad1a](algolia/react-instantsearch@c45ad1a))
* **deps:** update dependency antd to v3.20.2 ([algolia/react-instantsearch#2655](algolia/react-instantsearch#2655)) ([aff6af1](algolia/react-instantsearch@aff6af1))
* **deps:** update dependency antd to v3.20.3 ([algolia/react-instantsearch#2658](algolia/react-instantsearch#2658)) ([2fe1b08](algolia/react-instantsearch@2fe1b08))
* **deps:** update dependency antd to v3.20.5 ([algolia/react-instantsearch#2686](algolia/react-instantsearch#2686)) ([767f6bb](algolia/react-instantsearch@767f6bb))
* **deps:** update dependency antd to v3.20.6 ([algolia/react-instantsearch#2711](algolia/react-instantsearch#2711)) ([1026bb1](algolia/react-instantsearch@1026bb1))
* **deps:** update dependency antd to v3.20.7 ([algolia/react-instantsearch#2712](algolia/react-instantsearch#2712)) ([5dbe0f6](algolia/react-instantsearch@5dbe0f6))
* **deps:** update dependency antd to v3.21.1 ([algolia/react-instantsearch#2736](algolia/react-instantsearch#2736)) ([b6028e7](algolia/react-instantsearch@b6028e7))
* **deps:** update dependency antd to v3.21.2 ([algolia/react-instantsearch#2738](algolia/react-instantsearch#2738)) ([fab0a42](algolia/react-instantsearch@fab0a42))
* **deps:** update dependency antd to v3.21.4 ([algolia/react-instantsearch#2747](algolia/react-instantsearch#2747)) ([b31b543](algolia/react-instantsearch@b31b543))
* **deps:** update dependency antd to v3.22.0 ([algolia/react-instantsearch#2758](algolia/react-instantsearch#2758)) ([be351e1](algolia/react-instantsearch@be351e1))
* **deps:** update dependency antd to v3.22.2 ([algolia/react-instantsearch#2791](algolia/react-instantsearch#2791)) ([79ef129](algolia/react-instantsearch@79ef129))
* **deps:** update dependency antd to v3.23.2 ([algolia/react-instantsearch#2814](algolia/react-instantsearch#2814)) ([bd12e7a](algolia/react-instantsearch@bd12e7a))
* **deps:** update dependency lodash to v4.17.13 ([2d2d2da](algolia/react-instantsearch@2d2d2da))
* **deps:** update dependency lodash to v4.17.14 ([algolia/react-instantsearch#2647](algolia/react-instantsearch#2647)) ([3075507](algolia/react-instantsearch@3075507))
* **deps:** update dependency lodash to v4.17.15 ([algolia/react-instantsearch#2684](algolia/react-instantsearch#2684)) ([081fe68](algolia/react-instantsearch@081fe68))
* **deps:** update dependency next to v9 ([algolia/react-instantsearch#2638](algolia/react-instantsearch#2638)) ([23be0c2](algolia/react-instantsearch@23be0c2))
* **deps:** update dependency next to v9.0.1 ([algolia/react-instantsearch#2652](algolia/react-instantsearch#2652)) ([100f04a](algolia/react-instantsearch@100f04a))
* **deps:** update dependency next to v9.0.2 ([algolia/react-instantsearch#2662](algolia/react-instantsearch#2662)) ([09947fb](algolia/react-instantsearch@09947fb))
* **deps:** update dependency next to v9.0.3 ([algolia/react-instantsearch#2724](algolia/react-instantsearch#2724)) ([aaa3f4c](algolia/react-instantsearch@aaa3f4c))
* **deps:** update dependency next to v9.0.4 ([algolia/react-instantsearch#2767](algolia/react-instantsearch#2767)) ([2a73410](algolia/react-instantsearch@2a73410))
* **deps:** update dependency next to v9.0.5 ([algolia/react-instantsearch#2789](algolia/react-instantsearch#2789)) ([c3ef3a7](algolia/react-instantsearch@c3ef3a7))
* **deps:** update dependency qs to v6.8.0 ([algolia/react-instantsearch#2757](algolia/react-instantsearch#2757)) ([0eb150a](algolia/react-instantsearch@0eb150a))
* **deps:** update dependency react-compound-slider to v2.1.0 ([algolia/react-instantsearch#2610](algolia/react-instantsearch#2610)) ([00c680d](algolia/react-instantsearch@00c680d))
* **deps:** update dependency react-compound-slider to v2.2.0 ([algolia/react-instantsearch#2649](algolia/react-instantsearch#2649)) ([fb37e13](algolia/react-instantsearch@fb37e13))
* **deps:** update dependency react-native-vector-icons to v6.5.0 ([algolia/react-instantsearch#2520](algolia/react-instantsearch#2520)) ([2da40fa](algolia/react-instantsearch@2da40fa))
* **deps:** update dependency react-native-vector-icons to v6.6.0 ([algolia/react-instantsearch#2599](algolia/react-instantsearch#2599)) ([cc3a5df](algolia/react-instantsearch@cc3a5df))
* **deps:** update dependency react-router-dom to v5.0.1 ([algolia/react-instantsearch#2506](algolia/react-instantsearch#2506)) ([10c1a8e](algolia/react-instantsearch@10c1a8e))
* **highlight:** switch to index as key ([algolia/react-instantsearch#2691](algolia/react-instantsearch#2691)) ([78e6fad](algolia/react-instantsearch@78e6fad)), closes [#2688](algolia/react-instantsearch#2688)
* **voiceSearch:** fix incorrect status on stop ([algolia/react-instantsearch#2535](algolia/react-instantsearch#2535)) ([129596e](algolia/react-instantsearch@129596e))

### chore

* **release:** 6.0.0-beta.1 ([algolia/react-instantsearch#2861](algolia/react-instantsearch#2861)) ([9a329da](algolia/react-instantsearch@9a329da)), closes [#2023](algolia/react-instantsearch#2023) [#2178](algolia/react-instantsearch#2178) [#2178](algolia/react-instantsearch#2178) [#2179](algolia/react-instantsearch#2179) [#2180](algolia/react-instantsearch#2180) [#2181](algolia/react-instantsearch#2181) [#2185](algolia/react-instantsearch#2185) [#2192](algolia/react-instantsearch#2192) [#2189](algolia/react-instantsearch#2189) [#2190](algolia/react-instantsearch#2190) [#2179](algolia/react-instantsearch#2179) [#2178](algolia/react-instantsearch#2178) [#2180](algolia/react-instantsearch#2180) [#2181](algolia/react-instantsearch#2181) [#2185](algolia/react-instantsearch#2185) [#2192](algolia/react-instantsearch#2192) [#2190](algolia/react-instantsearch#2190) [#2203](algolia/react-instantsearch#2203) [#2432](algolia/react-instantsearch#2432) [#2444](algolia/react-instantsearch#2444) [#2357](algolia/react-instantsearch#2357) [#2454](algolia/react-instantsearch#2454) [#2455](algolia/react-instantsearch#2455) [#2459](algolia/react-instantsearch#2459) [#2458](algolia/react-instantsearch#2458) [#2460](algolia/react-instantsearch#2460) [#2442](algolia/react-instantsearch#2442) [#2446](algolia/react-instantsearch#2446) [#2434](algolia/react-instantsearch#2434) [#2467](algolia/react-instantsearch#2467) [#2466](algolia/react-instantsearch#2466) [#2288](algolia/react-instantsearch#2288) [#2290](algolia/react-instantsearch#2290) [#2289](algolia/react-instantsearch#2289) [#2305](algolia/react-instantsearch#2305) [#2338](algolia/react-instantsearch#2338) [#2461](algolia/react-instantsearch#2461) [#2442](algolia/react-instantsearch#2442) [#2307](algolia/react-instantsearch#2307) [#2314](algolia/react-instantsearch#2314) [#2304](algolia/react-instantsearch#2304) [#2379](algolia/react-instantsearch#2379) [#2552](algolia/react-instantsearch#2552) [#2555](algolia/react-instantsearch#2555) [#2536](algolia/react-instantsearch#2536) [#2537](algolia/react-instantsearch#2537) [#2339](algolia/react-instantsearch#2339) [#2349](algolia/react-instantsearch#2349) [#2570](algolia/react-instantsearch#2570) [#2462](algolia/react-instantsearch#2462) [#2600](algolia/react-instantsearch#2600) [#2468](algolia/react-instantsearch#2468) [#2626](algolia/react-instantsearch#2626) [#2621](algolia/react-instantsearch#2621) [#2627](algolia/react-instantsearch#2627) [#2644](algolia/react-instantsearch#2644) [#2626](algolia/react-instantsearch#2626) [#2645](algolia/react-instantsearch#2645) [#2339](algolia/react-instantsearch#2339) [#2643](algolia/react-instantsearch#2643) [#2467](algolia/react-instantsearch#2467) [#2690](algolia/react-instantsearch#2690) [#2687](algolia/react-instantsearch#2687) [#2722](algolia/react-instantsearch#2722) [#2568](algolia/react-instantsearch#2568) [#2726](algolia/react-instantsearch#2726) [#2379](algolia/react-instantsearch#2379) [#2289](algolia/react-instantsearch#2289) [#2290](algolia/react-instantsearch#2290) [#2304](algolia/react-instantsearch#2304) [#2307](algolia/react-instantsearch#2307) [#2314](algolia/react-instantsearch#2314) [#2288](algolia/react-instantsearch#2288) [#2305](algolia/react-instantsearch#2305) [#2701](algolia/react-instantsearch#2701) [#2568](algolia/react-instantsearch#2568) [#2357](algolia/react-instantsearch#2357) [#2552](algolia/react-instantsearch#2552) [#2530](algolia/react-instantsearch#2530) [#2559](algolia/react-instantsearch#2559) [#2560](algolia/react-instantsearch#2560) [#2564](algolia/react-instantsearch#2564) [#2573](algolia/react-instantsearch#2573) [#2584](algolia/react-instantsearch#2584) [#2611](algolia/react-instantsearch#2611) [#2635](algolia/react-instantsearch#2635) [#2655](algolia/react-instantsearch#2655) [#2658](algolia/react-instantsearch#2658) [#2686](algolia/react-instantsearch#2686) [#2711](algolia/react-instantsearch#2711) [#2712](algolia/react-instantsearch#2712) [#2736](algolia/react-instantsearch#2736) [#2738](algolia/react-instantsearch#2738) [#2747](algolia/react-instantsearch#2747) [#2758](algolia/react-instantsearch#2758) [#2647](algolia/react-instantsearch#2647) [#2684](algolia/react-instantsearch#2684) [#2638](algolia/react-instantsearch#2638) [#2652](algolia/react-instantsearch#2652) [#2662](algolia/react-instantsearch#2662) [#2724](algolia/react-instantsearch#2724) [#2767](algolia/react-instantsearch#2767) [#2757](algolia/react-instantsearch#2757) [#2610](algolia/react-instantsearch#2610) [#2649](algolia/react-instantsearch#2649) [#2520](algolia/react-instantsearch#2520) [#2599](algolia/react-instantsearch#2599) [#2506](algolia/react-instantsearch#2506) [#2467](algolia/react-instantsearch#2467) [#2626](algolia/react-instantsearch#2626) [#2690](algolia/react-instantsearch#2690) [#2688](algolia/react-instantsearch#2688) [#2626](algolia/react-instantsearch#2626) [#2726](algolia/react-instantsearch#2726) [#2535](algolia/react-instantsearch#2535) [#2461](algolia/react-instantsearch#2461) [#2434](algolia/react-instantsearch#2434) [#2687](algolia/react-instantsearch#2687) [#2338](algolia/react-instantsearch#2338) [#2179](algolia/react-instantsearch#2179) [#2180](algolia/react-instantsearch#2180) [#2181](algolia/react-instantsearch#2181) [#2185](algolia/react-instantsearch#2185) [#2192](algolia/react-instantsearch#2192) [#2189](algolia/react-instantsearch#2189) [#2190](algolia/react-instantsearch#2190) [#2179](algolia/react-instantsearch#2179) [#2180](algolia/react-instantsearch#2180) [#2181](algolia/react-instantsearch#2181) [#2185](algolia/react-instantsearch#2185) [#2192](algolia/react-instantsearch#2192) [#2190](algolia/react-instantsearch#2190) [#2536](algolia/react-instantsearch#2536) [#2537](algolia/react-instantsearch#2537) [#2834](algolia/react-instantsearch#2834) [#2845](algolia/react-instantsearch#2845) [#2842](algolia/react-instantsearch#2842) [#2852](algolia/react-instantsearch#2852) [#2853](algolia/react-instantsearch#2853)

### BREAKING CHANGES

* **release:** translation will render default value if passed undefined as value

* chore(lodash): remove imports

* fix(translation): allow undefined value to be passed on purpose
* **release:** no longer do we allow paths like `attribute[5].something`, or other indexed forms, only `.` is allowed as special key.

All existing tests still pass, and we never documented you could use `lodash.get` patterns other than `.`.

* feat(get): accept array & bracked-separated string

moved to utils at the same time

* fix typo

* feedback: test for undefined behaviour

* chore(size): update expectation

this will go down afterwards, but for now there's some more duplication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants