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 Room Combobox to Initial Room Schedule page #557

Merged
merged 12 commits into from
Aug 11, 2022

Conversation

natalynyu
Copy link
Contributor

@natalynyu natalynyu commented Aug 4, 2022

This PR adds the initial Room Schedule tab/page, which includes a combobox that contains all of the rooms in the database. The previously existing location controller method getRoomAvailability was using the / route, and I updated the new controller method getRooms to use this route instead. This was because getRooms is more general and does not take parameters in order to find the room availability for a specific time (term/calendar year/day, etc).

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality
    to change)

Checklist:

  • I have run eslint on the code
  • I have added JSDoc for all of my code (where applicable)
  • I have added tests to cover my changes.

Priority:

  • Normal
  • High

Related Issues:

Fixes #550

The new room schedule path was added so that it appears in the list of tabs in the app header.
The existing API that is getting the room availability was updated so that its path is /api/rooms/availability instead so that this more general retrieval of rooms without availability can have the path /api/rooms. In order to get the room information, we are querying the existing roomListingViewRepository. While we do not technically need the capacity or campus information to build the room dropdown, we can reuse this service for the future room admin tab.
The existing room API's path was updated from /api/rooms/ to /api/rooms/availability so that our more general querying of room information can use the path /api/rooms/, so this is fixing the existing tests checking the room availability path.
This room schedule component includes a combobox that has a filter function that uses the mark-one regex filter function which allows a case insensitive search. It also allows you to search the middle of a word (e.g. if the room is 1414 Massachusetts Avenue 230, you could search "ave" to see this room as one of the search results). Two NoteText components were also added to the menu that show the (for now) hardcoded semester and currently selected room.
These tests check the results of calling the room controller. All rooms are returned as a result of calling the controller when the user is authenticated, and unauthenticated users will receive a forbidden status.
@codecov
Copy link

codecov bot commented Aug 4, 2022

Codecov Report

Merging #557 (68cdf9b) into develop (eee2d1b) will decrease coverage by 0.06%.
The diff coverage is 92.00%.

@@             Coverage Diff             @@
##           develop     #557      +/-   ##
===========================================
- Coverage    96.12%   96.06%   -0.07%     
===========================================
  Files          179      181       +2     
  Lines         3768     3812      +44     
  Branches       443      446       +3     
===========================================
+ Hits          3622     3662      +40     
- Misses          68       71       +3     
- Partials        78       79       +1     
Impacted Files Coverage Δ
src/client/components/layout/AppHeader.tsx 92.00% <ø> (ø)
src/client/components/layout/AppRouter.tsx 85.00% <ø> (ø)
.../client/components/pages/Schedule/ScheduleView.tsx 97.14% <ø> (ø)
src/common/dto/room/RoomResponse.dto.ts 100.00% <ø> (ø)
...ent/components/pages/RoomSchedule/RoomSchedule.tsx 85.71% <85.71%> (ø)
src/client/api/rooms.ts 100.00% <100.00%> (ø)
.../client/components/pages/Courses/RoomSelection.tsx 100.00% <100.00%> (ø)
...nt/components/pages/Courses/RoomSelectionTable.tsx 100.00% <100.00%> (ø)
.../components/pages/Schedule/blocks/SessionBlock.tsx 90.90% <100.00%> (+0.58%) ⬆️
src/client/components/pages/index.ts 100.00% <100.00%> (ø)
... and 3 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

…e to use it

The RoomMeetingResponse DTO has all of the properties that the original RoomResponse DTO had. The existing code related to room availability was updated to use the RoomMeetingResponse DTO, and the code related to the room combobox on the RoomSchedule page uses the RoomResponse DTO, which has the propeties id, name, campus, and capacity.
@natalynyu natalynyu requested a review from rmainwork August 8, 2022 20:00
Copy link
Contributor

@rmainwork rmainwork left a comment

Choose a reason for hiding this comment

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

This looks great, just a few small notes.

I'm also having some difficulty testing this in my browser - when I make a room selection, the room seems to have been successfully chosen, but the selection box is blank, the table is blank and no AJAX request seems to be being made to retrieve data. Is there something I'm doing wrong?

});
it('should return a nonempty array of data', function () {
strictEqual(Array.isArray(result), true);
notStrictEqual(result, 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be result.length?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, good call! I fixed this in dcd4821.

src/server/location/location.service.ts Show resolved Hide resolved
Comment on lines 38 to 43
.createQueryBuilder()
.select('id')
.addSelect('name')
.addSelect('campus')
.addSelect('capacity')
.getRawMany();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should be able to just replace this query builder call with Repository.find().

Suggested change
.createQueryBuilder()
.select('id')
.addSelect('name')
.addSelect('campus')
.addSelect('capacity')
.getRawMany();
.find({
select: ['name', 'campus', 'capacity']
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is good to know - thanks for the suggestion. I updated this in 68cdf9b.

const rawRooms = await locationRepo.createQueryBuilder('r')
.select('CONCAT_WS(\' \', b.name, r.name)', 'name')
.leftJoin('r.building', 'b')
.leftJoin('b.campus', 'c')
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you're not selecting anything from the campus table, you can probably get rid of this JOIN.

Suggested change
.leftJoin('b.campus', 'c')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, that's a good point.. This was removed in b8221b7


const loadRooms = useCallback(async (): Promise<void> => {
try {
const roomList = await LocationAPI.getRooms();
Copy link
Contributor

@rmainwork rmainwork Aug 9, 2022

Choose a reason for hiding this comment

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

Suggested change
const roomList = await LocationAPI.getRooms();
const roomList = await getRooms();

I'd suggest importing and using getRooms instead of LocationAPI.getRooms() here as the latter was producing a type error for me (likely due to the way things are exported/imported).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like we updated all the client APIs to export the functions in this style in this commit as a result of no longer being able to stub free-standing functions in Typescript 3.9.2+:

What type error are you seeing in importing with LocationAPI?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was getting Unsafe call of an any typed value from @typescript-eslint/no-unsafe-call.

Copy link
Contributor

Choose a reason for hiding this comment

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

I wouldn't think this would be related to Sinon as this error was thrown in the production code. I think it has more to do with the way it's being imported here (from client/api/rooms) and the way it's being exported (or rather isn't being exported ) from client/api.

Adding export * from './rooms'; to src/client/api/index.ts and then changing the import statement to import { LocationApi } from 'client/api' fixes this error.

Copy link
Contributor

Choose a reason for hiding this comment

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

diff --git a/src/client/api/index.ts b/src/client/api/index.ts
index f19ee6b4..4c61a767 100644
--- a/src/client/api/index.ts
+++ b/src/client/api/index.ts
@@ -6,3 +6,4 @@ export * from './nonClassMeeting';
 export * from './meetings';
 export * from './reports';
 export * from './httpStatus';
+export * from './rooms';
diff --git a/src/client/components/pages/RoomSchedule/RoomSchedule.tsx b/src/client/components/pages/RoomSchedule/RoomSchedule.tsx
index 3f9927cb..da1f7f57 100644
--- a/src/client/components/pages/RoomSchedule/RoomSchedule.tsx
+++ b/src/client/components/pages/RoomSchedule/RoomSchedule.tsx
@@ -1,4 +1,4 @@
-import { LocationAPI } from 'client/api/rooms';
+import { LocationAPI } from 'client/api';
 import { AppMessage, MESSAGE_TYPE, MESSAGE_ACTION } from 'client/classes';
 import { MenuFlex } from 'client/components/general';
 import { VerticalSpace } from 'client/components/layout';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rmainseas Ah ok thanks for looking into this. I can make the update, but for some reason I am not seeing this error - do you think we have different versions of the linter or something like that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah of course. Not sure, that's an interesting question and probably something we should look into....

This test was meant to check that the length of the data that is returned from the API was not 0.
Nothing is being queried in the campus table, so the join is not necessary.
@natalynyu
Copy link
Contributor Author

I'm also having some difficulty testing this in my browser - when I make a room selection, the room seems to have been successfully chosen, but the selection box is blank, the table is blank and no AJAX request seems to be being made to retrieve data. Is there something I'm doing wrong?

Thanks for reviewing this, Robert! As of now, the only thing that happens when selecting a room is that the text next to "Current Room:" is updated as an indication of what room was selected. The next ticket (#551) will implement the Room Schedule table for the selected room and the (for now) hardcoded semester.

@natalynyu natalynyu requested a review from rmainwork August 11, 2022 15:54
@rmainwork
Copy link
Contributor

Ah, gotcha. For some reason, I'd thought it was meant to populate a schedule view below the dropdown.

In that case, I'm going to approve this. Merge away.

@natalynyu natalynyu merged commit edbfb01 into develop Aug 11, 2022
@natalynyu natalynyu deleted the feature/550-initial-room-schedule-page branch August 11, 2022 15:57
@natalynyu natalynyu restored the feature/550-initial-room-schedule-page branch August 11, 2022 18:12
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.

2 participants