Skip to content

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

Open
wants to merge 5 commits into
base: react-example
Choose a base branch
from

Conversation

CallawayJay
Copy link
Owner

…ck button functionality.

src/app.tsx Outdated
@@ -7,6 +8,7 @@ import { generateSelect } from 'ts-force';

interface AppState {
acc: AccountFields;
accs: any;

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} />;

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

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

@@ -6,6 +6,7 @@ import { hot } from 'react-hot-loader';

interface AccountDisplayProps {
acc: AccountFields;
onBackClick: (account: AccountFields) => void;

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

@@ -14,25 +15,33 @@ export class AccountDisplay extends React.Component<AccountDisplayProps, {}> {
super(props);
}

public handleBackClick = () => {
this.props.onBackClick(null);

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}>

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

@@ -0,0 +1,30 @@
import { Button, Form, Input } from 'antd';
import * as React from 'react';
import { hot } from 'react-hot-loader';

Choose a reason for hiding this comment

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

import is not needed

return <div>No Accounts Found</div>;
}

if (this.state.selectedAccount) {

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.

}

interface SearchResultsStates {
selectedAccount: AccountFields;

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, {}> {

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

import { Account, AccountFields} from '@src/generated/sobs';
import { Form } from 'antd';
import * as React from 'react';
import { hot } from 'react-hot-loader';

Choose a reason for hiding this comment

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

import not needed

Copy link

@ChuckJonas ChuckJonas left a 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


interface SearchDisplayStates {
searchValue: string;
searchResults: any;

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

<Input
id='search-box'
value={this.state.searchValue}
onChange={evt => this.updateSearchValue(evt)}

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).

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);
}

}

</Form>
<ul>

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

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