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

Add guide "Create a Calendar Widget" #2687

Merged
merged 13 commits into from
Feb 5, 2018
Merged

Add guide "Create a Calendar Widget" #2687

merged 13 commits into from
Feb 5, 2018

Conversation

francoischalifour
Copy link
Member

@francoischalifour francoischalifour commented Jan 31, 2018

⚠️ Waiting for #2686 and algolia/create-instantsearch-app#8 to be merged. DONE ✅


This PR is the result of the app and the guide: "Create a Calendar Widget".

I'm looking for feedback on both the app and the guide 🙌

@algobot
Copy link
Contributor

algobot commented Jan 31, 2018

Deploy preview for algolia-instantsearch ready!

Built with commit 1f6f89b

https://deploy-preview-2687--algolia-instantsearch.netlify.com

Copy link
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the best guide I've read! Very clear and beginner-friendly. I left some comments on smaller things, nothing too blocking

* `location`: the venue of the concert
* `date`: the date of the event we will refine the results with

Both `name` and `location` will be added to the [searchable attributes](https://www.algolia.com/doc/guides/ranking/searchable-attributes/) in the Algolia dashboard so that the user can filter events on their name *and* their location.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for italic and IMO


If you're using [npm](https://www.npmjs.com/):

```console
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console is not recognised, and is showing it very faint, try sh, bash or nothing

If you're using [npm](https://www.npmjs.com/):

```console
npm install -g create-instantsearch-app
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npx create-instantsearch-app [name-of-your-new-app]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel so old 👴 what is npx?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's something npm 5 has, doing install globally and execute the binary, like yarn create

yarn create instantsearch-app [name-of-your-new-app]
```

The command-line tool will ask for your credentials:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing here where the dataset is, maybe list the credentials here, will be clearer, and we show them in the example anyway

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I should expose them. Should I make the JSON dataset downloadable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes the JSON dataset should be provided.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both the json and the credentials should be given IMO, you can put the JSON in https://github.com/algolia/datasets

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced the dataset is good enough to be officially exposed though. I might work a bit more on that beforehand!

The default `item` template from the `hits` widget provided by `create-instantsearch-app` is great, but we're going to enhance it to display the relevant information of our dataset.

```javascript
search.addWidget(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is runnable for some reason, but it doesn't work with the demo instant_search index; @bobylito can we make that configurable in the guide metadata 🤔 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh :/ It's because we do:

    if (exampleContent.indexOf("search.addWidget") === 0) {
      initWidgetExample(codeSample, index);
    }

in the runnable code JS :/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if the index would be configurable based on the page metadata, do you think that's possible @bobylito ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR sent #2690

);
```

We use the function syntax for the `item` template because we want to convert the numeric timestamp from our dataset to a JavaScript date on the fly.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  on the fly.

+ Be careful here with user-generated data, you can use existing libraries to prevent XSS,
+ or use a template and `transformData` instead.

(we don't currently have a guide on XSS I think, otherwise it should be linked

},
// Some good parameters based on our dataset:
start_date: new Date(),
end_date: new Date(`2020 00:00`),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better not to mix backticks and normal quotes

In our connector instantiation, we need to attach the calendar and specify its callback function to refine the search. This part will be specific to the calendar library that you use in your app. In the Baremetrics Calendar, this function is passed to the `callback` argument.

```javascript
const makeRangeWidget = instantsearch.connectors.connectRange(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

proposal: call the widget datePicker, since that's more consistent with the names in IS.js

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's also more explicit!

@vvo
Copy link
Contributor

vvo commented Feb 1, 2018

Nice guide!

Advice on behaviour

I would like your advice on the calendar behaviour.

Since I am used to the AirBnB like calendar, it took me some time to understand how to use this one. Here's the difference:

2018-02-01 11 35 55

2018-02-01 11 37 58

If you just blindly click on the two dates and you endup clicking only on the "End date (second date)" then the behaviour is very confusing because you think you're gonna select start then end dates while it's not the case. You're only changing the end date.

Is there a way to have the default demo behaviour where every time the calendar is opened then the action is "select the start date, then the end date" and never "select only the end date".

For the demo

Could you add a link to the source code in the demo? So the user once he have seen the demo can jump into the code right away.

@francoischalifour
Copy link
Member Author

I couldn't find a calendar widget without huge dependencies as good as react-dates UX-wise. This is definitely the pain point of this guide. I also had trouble getting familiar with the Baremetrics Calendar. I can try a workaround but it probably won't be very elegant.

As for the source code in the demo, I can add a link to the zip file.


Search results often need to be refined by dates. Calendars are a good visual way to improve the user experience when it comes to filtering dates. InstantSearch provides custom widgets to create reusable components within your app.

By the end of this guide, you'll understand how to implement a calendar widget to refine your results based on a single date and a range of dates. You can [preview](https://community.algolia.com/instantsearch.js/v2/examples/calendar-widget/) and [download](https://community.algolia.com/instantsearch.js/v2/examples/calendar-widget.zip) the concert app that you'll be able to build.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Links should be relative.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, should I make all links relative or only these two?
I've seen some other guides using absolute links.

@vvo
Copy link
Contributor

vvo commented Feb 1, 2018

I can try a workaround but it probably won't be very elegant.

It's OK for now since we show how to plug a calendar. This one also has some cool features like last 30 days etc.. Which are great

As for the source code in the demo, I can add a link to the zip file.

I would add a link to zip yes but also the GitHub direct link, since you might just want to read the code without having to download and unzip

@francoischalifour
Copy link
Member Author

@vvo What branch should I link it to? master? (that would be this link)

@vvo
Copy link
Contributor

vvo commented Feb 1, 2018

master yes since it's the branch tracking the releases (= doc website is master branch doc)

@francoischalifour
Copy link
Member Author

francoischalifour commented Feb 1, 2018

All changes have been made and all dependant PRs have been merged 🙂

Thank you all for your feedback!

@Haroenv I've fixed the "Invalid date" issue on Safari.

Copy link
Contributor

@vvo vvo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for my own comments

@bobylito
Copy link
Contributor

bobylito commented Feb 5, 2018

LGTM 👍 thanks for this awesome contribution @francoischalifour :)

@bobylito bobylito merged commit 44096c0 into develop Feb 5, 2018
@bobylito bobylito deleted the docs/calendar-widget branch February 5, 2018 14:02
Haroenv pushed a commit that referenced this pull request 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

Successfully merging this pull request may close these issues.

5 participants