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 new Location field #1736

Merged
merged 23 commits into from
Oct 7, 2019
Merged

Add new Location field #1736

merged 23 commits into from
Oct 7, 2019

Conversation

jordanoverbye
Copy link
Contributor

I've created a new Location field which stores data about a particular location data using the Google Maps API.

Below is a basic flow of how the field works in the Admin UI (there are also testing instructions and screenshots below):

  1. User searches for a location and is given a list of suggestions which come from the Google Maps AutoSuggest API. The value of each suggestion is a Google Place ID.
  2. Once the user selects a location, we use the Google Place ID to make a client-side request is made to the Google Maps Geoode API. This will return the formatted address, lat, lng etc. Once we have this information we show the user a map with a pin and also updated the input value to the formatted address.
  3. When the user creates or updates the page, the Google Place ID is sent to the server, and the server will do its own request to get the lat, lng, formatted address etc - which will then get saved into the DB. The reason this happens again on the server is so we only have to send a Google Place ID to create a Location field. I think this would be handy for applications other than the AdminUI.

Notes: I've had to update @arch-ui/select so that it allows us to use async and creatable react-selects through the isCreatable and isAsync props.

Testing

This is a basic Keystone config which shows off how this new field works.

const { Keystone } = require('@keystone-alpha/keystone');
const { MongooseAdapter } = require('@keystone-alpha/adapter-mongoose');
const { Location, Text } = require('@keystone-alpha/fields');
const { GraphQLApp } = require('@keystone-alpha/app-graphql');
const { AdminUIApp } = require('@keystone-alpha/app-admin-ui');
const { StaticApp } = require('@keystone-alpha/app-static');

const keystone = new Keystone({
  name: 'Keystone Event App',
  adapter: new MongooseAdapter(),
});

keystone.createList('Event', {
  fields: {
    name: {
      type: Text,
    },
    venue: {
      type: Location,
      googleMapsKey: `AIzaSyDml6rqKwjgQgPomyAhC-WxVt4aLodlraU`, // Some random key from a public code sandbox
    },
  },
});

module.exports = {
  keystone,
  apps: [
    new GraphQLApp(),
    new StaticApp({ path: '/', src: 'public' }),
    // Setup the optional Admin UI
    new AdminUIApp({ enableDefaultRoute: true }),
  ],
};

Screenshots

Searching

Screen Shot 2019-10-05 at 11 57 54 am

Search by business ...

Screen Shot 2019-10-05 at 11 56 37 am

Search by address ...

Screen Shot 2019-10-05 at 11 56 58 am

Once a location is selected, the select value will show the formatted address and will display map with a marker.

Screen Shot 2019-10-05 at 11 58 02 am

Editing a post with selected location

Screen Shot 2019-10-05 at 11 58 08 am

Cell view - just display the formatted address

Screen Shot 2019-10-05 at 11 58 15 am

Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
Signed-off-by: Jordan Overbye <jordanoverbye@gmail.com>
@changeset-bot
Copy link

changeset-bot bot commented Oct 5, 2019

🦋 Changeset is good to go

Latest commit: e8806c9

We got this.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@VinayaSathyanarayana
Copy link
Contributor

Will be a good addition to Keystone 5

@@ -0,0 +1,11 @@
// @flow
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we using flow or not?

@MadeByMike
Copy link
Contributor

Mate, I love this :)

@MadeByMike MadeByMike merged commit 464d757 into master Oct 7, 2019
@MadeByMike MadeByMike deleted the fields/location branch October 7, 2019 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants