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 mazemap embed to events and meetings #2383

Merged
merged 19 commits into from Feb 9, 2022
Merged

Conversation

ollfkaih
Copy link
Contributor

@ollfkaih ollfkaih commented Dec 29, 2021

Adds a map to the sidebar of events and meetings if the event or meeting has mazemapPoi set,
and adds fields to the edit pages to be able to search for rooms and set the mazemapPoi.

Solved the jest/test issues by bundling mazemap as a node module instead of in pageRenderer, based on this.

Minor issue:

  • The saved room is not shown in the field, but is shown in the dropdown, because I have not figured out how to fetch the name of the room when EventEditRoute is rendering.

^ Fixed by using location saved on server

Oh, and this is also based on Tirils prior work in pr #1680

Screenshot for anyone curious
Screenshot

@ollfkaih ollfkaih changed the title [WIP] Add mazemap embed to events and meetings Add mazemap embed to events and meetings Jan 6, 2022
@ollfkaih ollfkaih marked this pull request as ready for review January 6, 2022 20:29
Copy link
Member

@SmithPeder SmithPeder left a comment

Choose a reason for hiding this comment

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

Very good work.

A couple of comments. (I guess some of them apply to the previous work done by Tiril, but yeah, you'll get the credits and the blame) 😆

  1. (Major) When we select a MazeMapRoom, it's kinda wired that we also have to fill in the normal Location. I get that sometimes one wants to write something in both, but if the event is in R1, then the mazemapPoi field will be translated to R1, Realfagbygget so writing anything in the Location is wired. This is kind of a business-logic problem, but something that should be addressed. I think the solution is to make the fields co-required, meaning at least one has to be filled in.
  2. (Minor) When selecting a room in a create or edit view the map is not visible. I can see arguments in favor of hiding a map in this view. But, when trying to select kinky rooms it could be nice to see that the correct room is selected. We could add the Åpne kart i ny fane label under, so the creator can open the map to check that the correct room was selected.

app/actions/MeetingActions.js Outdated Show resolved Hide resolved
app/components/Search/mazemapAutocomplete.js Outdated Show resolved Hide resolved
app/components/Form/SelectInput.js Outdated Show resolved Hide resolved
app/components/Search/mazemapAutocomplete.js Outdated Show resolved Hide resolved
app/components/MazemapEmbed/index.js Outdated Show resolved Hide resolved
app/components/MazemapEmbed/index.js Outdated Show resolved Hide resolved
app/components/Search/mazemapAutocomplete.js Outdated Show resolved Hide resolved
app/components/Search/mazemapAutocomplete.js Outdated Show resolved Hide resolved
app/components/MazemapEmbed/index.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@ollfkaih
Copy link
Contributor Author

ollfkaih commented Jan 8, 2022

I share your sentiment on having only one location field at a time. Perhaps a checkbox ("[x] Bruk mazemap") to toggle whether you type in the freetext location, or if you search for a room and then location gets set to that rooms displayname, would be a good solution.

I skipped adding a map to the event view because I wanted to keep the scope down for this PR so that i could finish it, but did originally consider displaying search results on the map. It would be easy, however, to display the room you've selected (not all results). This would make the sidebar even longer, unless the map is displayed below the description, but that would be a weird place to have the map when the search field is in the sidebar... A link seems like a decent solution.

Also, I'm no UX designer, but I think the colors should be more Abakus and less jarring (blue polygon and purple marker). I'll change them to something more red, but some feedback is appreciated.
embed-red

@SmithPeder
Copy link
Member

the colors should be more Abakus and less jarring (blue polygon and purple marker). I'll change them to something more red, but some feedback is appreciated.

I think the red looks great 👍🏻 Maybe @ivarnakken has some nit-picking 😆

This would make the sidebar even longer, unless the map is displayed below the description, but that would be a weird place to have the map when the search field is in the sidebar... A link seems like a decent solution.

yeah, I agree that showing the embedded map can be a bit much. I was thinking a link, or a "Open in new window icon" like this:
Screen Recording 2022-01-08 at 14 30 04

@ollfkaih
Copy link
Contributor Author

ollfkaih commented Jan 8, 2022

a "Open in new window icon" like this

That is an elegant solution.
Also, there are some oddities with the map's zLevelControl when changing rooms (it is not removed) due to how mapbox handles its container, so it would require some changes to the embed to display changing mazemapPois on the same map (one could of course create a completely new div on each change, but that seems wasteful).

@SmithPeder
Copy link
Member

I share your sentiment on having only one location field at a time. Perhaps a checkbox ("[x] Bruk mazemap") to toggle whether you type in the freetext location, or if you search for a room and then location gets set to that rooms displayname, would be a good solution.

yeah, something like that. It's still nice to have the location field set, because the location is used in multiple places, like here
image

@ollfkaih
Copy link
Contributor Author

ollfkaih commented Jan 9, 2022

I've just added a toggle that switches between mazemap/location fields. Someone more familiar with redux forms might be able to simplify this code, but it seems to work correctly.

Comment on lines 169 to 175
{
// TODO: Bug; meeting is not updated when the field above is changed, so the link
// will go to whatever room mazemapPoi was set to when the editor was opened
/*meeting.mazemapPoi > 0 && (
<MazemapLink mazemapPoi={meeting.mazemapPoi} linkText="↗️" />
)*/
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the editor for events, I've also added a small icon to link externally to mazemap for the given poi, but I couldn't make this work for meetings due to meeting not updating on every change to the field, like event does in the event edtior. I've left this as a comment for now.

Copy link
Member

Choose a reason for hiding this comment

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

The reason for this is that the state of the form (both the event and the meeting, is stored in the form state in redux. This is extracted for each of the editors, so that we can use the current form values in the components again.

If you look in the EventEditRoute, in the mapStateToProps, you can see that the event prop consists of the current event and all the values from the event form overriding any properties. This is the valueSelector that is used.

You can also see in the MeetingEditRoute that the valueSelector is used to get the invitingUsers. So if you want to use the current mazeMapPoi form value, just override that prop on the meeting object with the one from the valueSelector just as you have done with events. Then this should work great 😄

Maybe drone can find mazemap now (?)
.drone.yml Outdated Show resolved Hide resolved
Copy link
Member

@SmithPeder SmithPeder left a comment

Choose a reason for hiding this comment

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

LGTM 👍🏻

Copy link
Contributor

@PeterJFB PeterJFB left a comment

Choose a reason for hiding this comment

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

Looks good to me! 😍

Copy link
Member

@LudvigHz LudvigHz left a comment

Choose a reason for hiding this comment

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

Nice work! This is a really great feature 👍. Just fixup the comment/TODO in the meeting editor and make sure SSR is good then we can merge this.

Comment on lines 169 to 175
{
// TODO: Bug; meeting is not updated when the field above is changed, so the link
// will go to whatever room mazemapPoi was set to when the editor was opened
/*meeting.mazemapPoi > 0 && (
<MazemapLink mazemapPoi={meeting.mazemapPoi} linkText="↗️" />
)*/
Copy link
Member

Choose a reason for hiding this comment

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

The reason for this is that the state of the form (both the event and the meeting, is stored in the form state in redux. This is extracted for each of the editors, so that we can use the current form values in the components again.

If you look in the EventEditRoute, in the mapStateToProps, you can see that the event prop consists of the current event and all the values from the event form overriding any properties. This is the valueSelector that is used.

You can also see in the MeetingEditRoute that the valueSelector is used to get the invitingUsers. So if you want to use the current mazeMapPoi form value, just override that prop on the meeting object with the one from the valueSelector just as you have done with events. Then this should work great 😄

app/components/MazemapEmbed/index.js Show resolved Hide resolved
@ollfkaih
Copy link
Contributor Author

ollfkaih commented Feb 8, 2022 via email

@LudvigHz
Copy link
Member

LudvigHz commented Feb 8, 2022

Oh, if that's the case I guess you can merge it.grin

Actually, hold that thought. It seems that for me, joblistings is broken with the Element is not defined error coming from Mazemp 🤔. I don't know why that is, but it seems that the mazemap library is being loaded in some places when it absolutely should not. So I think this needs some more investigating sadly

@ollfkaih
Copy link
Contributor Author

ollfkaih commented Feb 8, 2022

Could it be in or related to SelectInput.js?
Edit: had some faulty uncommited code locally, but reproduced the errors with joblistnings.

@LudvigHz
Copy link
Member

LudvigHz commented Feb 8, 2022

Could it be in or related to SelectInput.js? Edit: had some faulty uncommited code locally, but reproduced the errors with joblistnings.

See my latest reply in the thread here: #2383 (comment)

Comment on lines 59 to 96
const { Mazemap } = this.state;
const handleSearch = (query: string): void => {
if (!query || !Mazemap) {
return;
}
const mazemapSearchController = new Mazemap.Search.SearchController({
campusid: 1,
rows: 10,
withpois: true,
withbuilding: false,
withtype: false,
withcampus: false,
resultsFormat: 'geojson',
});
this.setState({
searching: true,
});
mazemapSearchController
.search(query)
.then((results) => {
if (this._isMounted) {
this.setState({
result: results.results.features.map((result) =>
mapRoomAndBuildingToResult(
result.properties.dispPoiNames[0],
result.properties.dispBldNames[0],
result.properties.poiId
)
),
});
}
})
.finally(() => {
if (this._isMounted) {
this.setState({ searching: false });
}
});
};
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, why did you move these methods into render()? This will make every render heavier as it sets up new functions for every render and not when creating the component as before.

Also, it's probably alot better to initialize the Mazemap.Search.SearchController only once in the mount when you do the import, and rather store that in state instead of the entire Mazemap lib, since it seems that that's the only thing used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good questions all around, I've done some cleanup and moved the methods back out of render(), in what is hopefully the final™ commit on this pr.

Copy link
Member

@LudvigHz LudvigHz left a comment

Choose a reason for hiding this comment

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

Nice! :shipit: 🚀 🚀 🚀

Copy link
Member

@eikhr eikhr left a comment

Choose a reason for hiding this comment

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

LTGM! 💯 But it seems like there are some small flow problems

Copy link
Member

@eikhr eikhr left a comment

Choose a reason for hiding this comment

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

Great!

@LudvigHz LudvigHz merged commit 03a2012 into webkom:master Feb 9, 2022
@eikhr eikhr mentioned this pull request Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants