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

Added rooms sorting by favorites first #173

Merged
merged 31 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fa3828c
added logic to show starting times in the time picker, and combined i…
Jun 26, 2024
9da87b8
fix show durations in bookingdrawer
Jun 26, 2024
4b57462
format
Jun 26, 2024
678ff56
tests fixed
Jun 26, 2024
fdbb679
format again
Jun 26, 2024
382c099
format again & some css fixing in order to get the buttons use at lea…
Jun 26, 2024
cabd8e7
added multisectiondigitalclock for starting time selection (custom), …
Jun 28, 2024
a49cb74
puzzling with set constant duration buttons (quick duration selection)
Jul 2, 2024
63dafe0
custom starting time & duration buttons, 1st draft for presentation
Jul 2, 2024
899138f
added custom duration possibility, adds extra button if custom durati…
Jul 5, 2024
3e04d6a
added custom button and custom value button for starting time working…
Jul 5, 2024
8c7e471
fixed starting time and duration to not use redux anymore, and bug fi…
Jul 6, 2024
6d0684e
Added rooms sorted by favorites first
villepynttari Jul 8, 2024
6969371
merge from summer 2024 branch
Jul 8, 2024
4411325
fixed problems found after merge
Jul 8, 2024
3340d93
fixed problems found after merge, v2
Jul 8, 2024
f333728
ready for pr
Jul 8, 2024
33c76fe
trying to fix styled engine build error
Jul 8, 2024
aa56e21
first jest test refactored to vitest
Jul 9, 2024
48db87f
rest of the jest tests converted to vitest
Jul 9, 2024
3de8eb8
based on review: remove unnecessary onchange and move logic to child …
Jul 9, 2024
b3e9d81
rest of code review changes, refactoring etc.
Jul 9, 2024
dac1cdb
one test was not refactored to vitest, now trying again
Jul 9, 2024
0d81741
fix
Jul 9, 2024
87346a7
Merge pull request #175 from Vincit/feature/ilkka_starting_time_freely
iltelko2 Jul 9, 2024
0b26c56
Added rooms sorted by favorites first
villepynttari Jul 8, 2024
cb39a0d
Merge remote-tracking branch 'github/feature/sort-favorited-rooms-fir…
villepynttari Jul 10, 2024
3ca7957
Updated test to vitest
villepynttari Jul 10, 2024
33894dc
Moved vitest imports to setup file
villepynttari Jul 10, 2024
196951e
Fixed vitest type checkings
villepynttari Jul 10, 2024
36ef9a4
Fixing test types
villepynttari Jul 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 20 additions & 23 deletions frontend/src/components/AvailableRoomList/AvailableRoomList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import RoomCard from '../RoomCard/RoomCard';
import NoRoomsCard from '../RoomCard/NoRoomsCard';
import BookingDrawer from '../BookingDrawer/BookingDrawer';
import TimePickerDrawer from '../TimePickerDrawer/TimePickerDrawer';
import { sortByFavoritedAndName } from '../../util/arrayUtils';

const SKIP_CONFIRMATION = true;

Expand Down Expand Up @@ -317,29 +318,25 @@ const AvailableRoomList = (props: BookingListProps) => {
{noAvailableRooms(rooms) ? (
<NoRoomsCard />
) : (
rooms
.sort((a, b) => (a.name < b.name ? -1 : 1))
.map((room) =>
isAvailableFor(bookingDuration, room, startingTime)
? (isFavorited(room, preferences),
(
<li key={room.id}>
<RoomCard
room={room}
onClick={handleCardClick}
bookingLoading={bookingLoading}
disableBooking={false}
isSelected={selectedRoom === room}
expandFeatures={
expandedFeaturesAll
}
preferences={preferences}
setPreferences={setPreferences}
/>
</li>
))
: null
)
sortByFavoritedAndName<Room>(rooms).map((room) =>
isAvailableFor(bookingDuration, room, startingTime)
? (isFavorited(room, preferences),
(
<li key={room.id}>
<RoomCard
room={room}
onClick={handleCardClick}
bookingLoading={bookingLoading}
disableBooking={false}
isSelected={selectedRoom === room}
expandFeatures={expandedFeaturesAll}
preferences={preferences}
setPreferences={setPreferences}
/>
</li>
))
: null
)
)}
</List>
</Box>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/BookingView/BookingView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
UserIcon
} from '../../theme_2024';
import { useUserSettings } from '../../contexts/UserSettingsContext';
import { sortByFavoritedAndName } from '../../util/arrayUtils';

const UPDATE_FREQUENCY = 30000;
const GET_RESERVED = true;
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/util/arrayUtils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { sortByFavoritedAndName } from './arrayUtils';

const testArray = [
{ name: 'a', favorited: false },
{ name: 'b', favorited: true },
{ name: 'c', favorited: false }
];
describe('isNonEmptyArray', () => {
test('Should return false for null', () => {
expect(sortByFavoritedAndName(testArray)).toEqual([
{ name: 'b', favorited: true },
{ name: 'a', favorited: false },
{ name: 'c', favorited: false }
]);
});
});
10 changes: 10 additions & 0 deletions frontend/src/util/arrayUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function sortByFavoritedAndName<T>(
array: { name: string; favorited: boolean }[]
): T[] {
return array.sort((a, b) => {
if (a.favorited === b.favorited) {
return a.name.localeCompare(b.name);
}
return a.favorited ? -1 : 1;
}) as T[];
}