-
Notifications
You must be signed in to change notification settings - Fork 0
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
Family member search #160
Open
junzai97
wants to merge
4
commits into
dev-version-2
Choose a base branch
from
family-member-search
base: dev-version-2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+49
−36
Open
Family member search #160
Changes from 8 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7cf4941
Merge branch 'member-list' into family-member-search
junzai97 c151d44
Implement Native search engines into family member list search and ad…
junzai97 a989133
Fix tslint error
junzai97 0aebf6f
Merge branch 'dev-version-2' into family-member-search
junzai97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import ErrorBoundaryRoute from 'app/shared/error/error-boundary-route'; | ||
import React from 'react'; | ||
import { RouteComponentProps, Switch } from 'react-router-dom'; | ||
import Member from './member'; | ||
|
||
const Routes: React.FC<RouteComponentProps> = ({ match }) => ( | ||
<> | ||
<Switch> | ||
<ErrorBoundaryRoute exact path={match.url} component={Member} /> | ||
</Switch> | ||
</> | ||
); | ||
|
||
export default Routes; |
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,6 @@ | ||
import { IUserCCInfo } from 'app/shared/model/user-cc-info.model'; | ||
|
||
export const generateIndex = (userCCInfo: IUserCCInfo) => { | ||
const searchIndex = (userCCInfo.user?.firstName?.trim() || '') + (userCCInfo.user?.lastName?.trim() || ''); | ||
return searchIndex.replace(/\s+/g, '').toLowerCase(); | ||
}; |
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,141 @@ | ||
import { updateKey, updateKeys } from 'app/shared/util/deep-copy-utils'; | ||
import { memberTabList } from 'app/shared/util/tab.constants'; | ||
import axios from 'axios'; | ||
import React, { useEffect, useState } from 'react'; | ||
import { RouteComponentProps, useLocation } from 'react-router-dom'; | ||
import { Dropdown, DropdownItem, DropdownMenu, DropdownToggle } from 'reactstrap'; | ||
import CustomTab from 'app/shared/components/customTab/custom-tab'; | ||
import { SearchEngine } from 'app/shared/util/native-search-utils'; | ||
import { IUserCCInfo } from 'app/shared/model/user-cc-info.model'; | ||
import { generateIndex } from './member.indexer'; | ||
|
||
function useQuery() { | ||
return new URLSearchParams(useLocation().search); | ||
} | ||
|
||
const member: React.FC<RouteComponentProps> = (props: RouteComponentProps) => { | ||
const searchEngine: SearchEngine<IUserCCInfo> = new SearchEngine([], generateIndex); | ||
const query = useQuery(); | ||
const [viewModel, setViewModel] = useState({ | ||
isLoading: false, | ||
dropdownOpen: false, | ||
selectedYearSession: '2019/2020', | ||
memberName: '', | ||
yearSessionList: ['2019/2020', '2020/2021', '2021/2022', '2022/2023', '2023/2024', '2024/2025', '2025/2026'], | ||
retrievedMembers: [], | ||
}); | ||
|
||
const toggle: React.MouseEventHandler = () => { | ||
const currentViewModel = updateKey(viewModel, 'dropdownOpen', !viewModel.dropdownOpen); | ||
setViewModel(currentViewModel); | ||
}; | ||
|
||
useEffect(() => { | ||
search(); | ||
}, []); | ||
|
||
const updateViewModel: React.ChangeEventHandler<HTMLInputElement> = event => { | ||
const currentViewModel = updateKey(viewModel, 'memberName', event.target.value); | ||
setViewModel(currentViewModel); | ||
}; | ||
|
||
const search = () => { | ||
const currentViewModel = updateKey(viewModel, 'isLoading', true); | ||
setViewModel(currentViewModel); | ||
|
||
const searchString = `api/cc-members?yearSession.equals=${viewModel.selectedYearSession}`; | ||
|
||
axios | ||
.get<IUserCCInfo[]>(searchString) | ||
.then(response => { | ||
const values = new Map(); | ||
if (response?.data) { | ||
const filteredResponseData = searchEngine.updateEngine(response.data).search(viewModel.memberName); | ||
values.set('retrievedMembers', filteredResponseData); | ||
} | ||
values.set('isLoading', false); | ||
const currentViewModel1 = updateKeys(viewModel, values); | ||
setViewModel(currentViewModel1); | ||
}) | ||
.catch(alert); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div> | ||
<h2 id="club-family-heading" className="member-module-heading"> | ||
Fishes | ||
</h2> | ||
<div className="my-3"> | ||
<CustomTab tabList={memberTabList} currentTab="CC Family" key={Date.now()} /> | ||
</div> | ||
<div className="jumbotron container"> | ||
<div className="row"> | ||
<div className="col-4"> | ||
<Dropdown isOpen={viewModel.dropdownOpen} toggle={toggle}> | ||
<DropdownToggle caret>{viewModel.selectedYearSession}</DropdownToggle> | ||
<DropdownMenu> | ||
{viewModel.yearSessionList ? ( | ||
viewModel.yearSessionList.map(yearSession => { | ||
const setYearSession = () => { | ||
viewModel.selectedYearSession = yearSession; | ||
setViewModel(viewModel); | ||
}; | ||
|
||
return ( | ||
<DropdownItem key={yearSession}> | ||
<div onClick={setYearSession}>{yearSession}</div> | ||
</DropdownItem> | ||
); | ||
}) | ||
) : ( | ||
<DropdownItem>no year session</DropdownItem> | ||
)} | ||
</DropdownMenu> | ||
</Dropdown> | ||
</div> | ||
<div className="col-8"> | ||
<div className="input-group mb-3"> | ||
<div className="input-group-prepend"> | ||
<button className="btn btn-outline-secondary" type="button" onClick={search}> | ||
search | ||
</button> | ||
</div> | ||
<input | ||
name="memberName" | ||
type="text" | ||
className="form-control" | ||
placeholder="" | ||
aria-label="" | ||
aria-describedby="basic-addon1" | ||
value={viewModel.memberName} | ||
onChange={updateViewModel} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="row container"> | ||
<div className="container"> | ||
{viewModel.isLoading ? ( | ||
`Loading` | ||
) : ( | ||
<div> | ||
{viewModel?.retrievedMembers && | ||
viewModel.retrievedMembers.map((retrievedMember: any) => { | ||
return ( | ||
<div className="row" key={retrievedMember.id}> | ||
{JSON.stringify(retrievedMember.user)} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default member; |
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this one hardcoded?
not get from BE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or this PR is just for UI?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was pulled from #159. But for this PR, I mainly implement the search function into family-member search. Not sure why it still displaying this part of code as this is already existed in the dev-version-2 branch