-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from marmelab/features/game-search
Make the game list searchable by user
- Loading branch information
Showing
6 changed files
with
72 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,45 @@ | ||
import { | ||
AutocompleteInput, | ||
Datagrid, | ||
DateField, | ||
List, | ||
ReferenceField, | ||
ReferenceInput, | ||
SearchInput, | ||
SelectInput, | ||
TextField, | ||
WrapperField, | ||
} from "react-admin"; | ||
import { GameStatus } from "./GameStatus"; | ||
import { GameStatus, statusChoices } from "./GameStatus"; | ||
|
||
const filterToQuery = (searchText: any) => ({ | ||
"username@ilike": `%${searchText}%`, | ||
}); | ||
|
||
const postFilters = [ | ||
<SearchInput source="_players@ilike" alwaysOn />, | ||
<ReferenceInput source="winner_id" reference="users" alwaysOn> | ||
<AutocompleteInput filterToQuery={filterToQuery} optionText="username" /> | ||
</ReferenceInput>, | ||
<SelectInput | ||
label="Game status" | ||
source="_game_status" | ||
choices={statusChoices} | ||
alwaysOn | ||
/>, | ||
]; | ||
|
||
export const GameList = () => ( | ||
<List> | ||
<List filters={postFilters}> | ||
<Datagrid> | ||
<TextField source="id" /> | ||
<ReferenceField source="first_player_id" reference="users"> | ||
<TextField source="username" /> | ||
</ReferenceField> | ||
<ReferenceField source="second_player_id" reference="users"> | ||
<TextField source="username" /> | ||
</ReferenceField> | ||
<TextField source="first_player" label="First player" /> | ||
<TextField source="second_player" label="Second player" /> | ||
<WrapperField label="Game status"> | ||
<GameStatus /> | ||
</WrapperField> | ||
<DateField source="last_update_date" /> | ||
<TextField source="winner" label="Winner" /> | ||
<DateField source="creation_date" label="Game creation date" /> | ||
<DateField source="last_update_date" label="Game last update date" /> | ||
</Datagrid> | ||
</List> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
supabase/migrations/20240131101200_update_game_state_type.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ALTER TABLE games | ||
ALTER COLUMN game_state TYPE JSONB | ||
USING game_state::JSONB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
CREATE INDEX idx_games_winner ON games ((game_state->'victoryState'->>'player')); | ||
|
||
CREATE VIEW games_view AS | ||
SELECT | ||
g.id, | ||
g.first_player_id, | ||
u1.username as first_player, | ||
g.second_player_id, | ||
u2.username as second_player, | ||
g.game_state->'victoryState'->>'player' as winner_id, | ||
w.username as winner, | ||
g.creation_date, | ||
g.last_update_date, | ||
g.game_state, | ||
CONCAT(u1.username,' ',u2.username) as _players, | ||
CASE | ||
WHEN (g.game_state->'victoryState'->>'player') IS NOT NULL | ||
OR COALESCE((g.game_state->'victoryState'->>'isDraw')::BOOLEAN, FALSE) = TRUE | ||
THEN 'Finished' | ||
ELSE 'Ongoing' | ||
END as _game_status | ||
|
||
FROM games g | ||
LEFT JOIN users as u1 on first_player_id=u1.id | ||
LEFT JOIN users as u2 on second_player_id=u2.id | ||
LEFT JOIN users as w on (g.game_state->'victoryState'->>'player')::INT=w.id | ||
; |