-
Notifications
You must be signed in to change notification settings - Fork 0
Displaying all accounts, showing individual account info on click, ba… #2
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
base: react-example
Are you sure you want to change the base?
Conversation
…ck button functionality.
src/app.tsx
Outdated
@@ -7,6 +8,7 @@ import { generateSelect } from 'ts-force'; | |||
|
|||
interface AppState { | |||
acc: AccountFields; | |||
accs: any; |
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.
type this please
src/app.tsx
Outdated
} | ||
|
||
public render() { | ||
return <AccountDisplay acc={this.state.acc} />; |
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.
curious why you removed this? I would expect instead there to be some sort of conditional rendering which determines if Search vs Display is shown
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.
I see now that you've instead chosen to render <AccountDisplay />
from the ` component... Refactor so it's conditionally rendered here
src/components/accountDisplay.tsx
Outdated
@@ -6,6 +6,7 @@ import { hot } from 'react-hot-loader'; | |||
|
|||
interface AccountDisplayProps { | |||
acc: AccountFields; | |||
onBackClick: (account: AccountFields) => void; |
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.
not sure it makes sense to pass the account in
src/components/accountDisplay.tsx
Outdated
@@ -14,25 +15,33 @@ export class AccountDisplay extends React.Component<AccountDisplayProps, {}> { | |||
super(props); | |||
} | |||
|
|||
public handleBackClick = () => { | |||
this.props.onBackClick(null); |
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.
again, this is somewhat weird. I don't think the back button should be responsible for setting a value.
return <div>No Account Found</div>; | ||
} | ||
|
||
return ( | ||
<Card title={this.props.acc.name}> |
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.
you don't need to change any of the display of this component for the assignment
src/components/searchControls.tsx
Outdated
@@ -0,0 +1,30 @@ | |||
import { Button, Form, Input } from 'antd'; | |||
import * as React from 'react'; | |||
import { hot } from 'react-hot-loader'; |
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.
import is not needed
src/components/searchResults.tsx
Outdated
return <div>No Accounts Found</div>; | ||
} | ||
|
||
if (this.state.selectedAccount) { |
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.
I don't think it makes sense for the Search Results component to be responsible for rendering the selected account.
1: this just doesn't really fit into the component hierarchy. EG: it wouldn't really make sense to render the account here as then the search controls would still be show.
2: It add additional dependancies. Search Results should only be responsible for displaying the results... not displaying the selected account. Once an account is "Selected" the interface should just replace the search components with the AccountDisplay
component.
src/components/searchResults.tsx
Outdated
} | ||
|
||
interface SearchResultsStates { | ||
selectedAccount: AccountFields; |
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.
I think this state should be managed higher up in the component tree (related to below comment about how the search results component shouldn't be responsible for rendering the AccountDisplay
)
onAccountClick?: (account: AccountFields) => void; | ||
} | ||
|
||
export class SearchResultsItem extends React.Component<SearchResultsItemProps, {}> { |
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 is a good case for a "Stateless function" component
src/components/searchResults.tsx
Outdated
import { Account, AccountFields} from '@src/generated/sobs'; | ||
import { Form } from 'antd'; | ||
import * as React from 'react'; | ||
import { hot } from 'react-hot-loader'; |
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.
import not needed
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.
@CallawayJay A couple minor tweaks needed but overall looking good. Code is well structured and properties are named correctly.
Demonstrates Knowledge of:
- Controlled Inputs
- Conditional rendering
- Passing State modification actions through component hierarchy
There is still room for improvement around
- how functions behave as parameters
- Typescript types
- Use of Stateless Function components
src/components/searchDisplay.tsx
Outdated
|
||
interface SearchDisplayStates { | ||
searchValue: string; | ||
searchResults: any; |
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.
never use any
type if you don't have to... This can easily be typed
src/components/searchDisplay.tsx
Outdated
<Input | ||
id='search-box' | ||
value={this.state.searchValue} | ||
onChange={evt => this.updateSearchValue(evt)} |
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 is redundant. Because you aren't changing the parameter in anyway, just pass in the function (instead of calling updateSearchValue
in a inline function).
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 is the equivent of
function(evt){
this.updateSearchValue(evt);
}
src/components/searchDisplay.tsx
Outdated
} | ||
|
||
</Form> | ||
<ul> |
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.
Probably should have been decomposed into it's own component just to improve decomposition
…larity. And make other tweaks for best practices.
…ck button functionality.