-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Taks done #1788
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: master
Are you sure you want to change the base?
Taks done #1788
Changes from all commits
7fe0404
da1e0bf
b08fbab
5e4d938
35f2cff
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,58 +15,97 @@ export const goods = [ | |
| 'Garlic', | ||
| ]; | ||
|
|
||
| export const App: React.FC = () => ( | ||
| <main className="section container"> | ||
| <h1 className="title">No goods selected</h1> | ||
| interface State { | ||
| selectedGood: string; | ||
| } | ||
|
|
||
| <h1 className="title is-flex is-align-items-center"> | ||
| Jam is selected | ||
| {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
| <button data-cy="ClearButton" type="button" className="delete ml-3" /> | ||
| </h1> | ||
| export class App extends React.Component<{}, State> { | ||
| state = { | ||
| selectedGood: 'Jam', | ||
| }; | ||
|
|
||
| <table className="table"> | ||
| <tbody> | ||
| <tr data-cy="Good"> | ||
| <td> | ||
| <button data-cy="AddButton" type="button" className="button"> | ||
| + | ||
| </button> | ||
| </td> | ||
| // Select a good by reading the data-good attribute from the event target | ||
| handleSelectGood = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
| const good = e.currentTarget.dataset.good || ''; | ||
|
|
||
| <td data-cy="GoodTitle" className="is-vcentered"> | ||
| Dumplings | ||
| </td> | ||
| </tr> | ||
| this.setState({ selectedGood: good }); | ||
| }; | ||
|
|
||
| <tr data-cy="Good" className="has-background-success-light"> | ||
| <td> | ||
| // Clear the current selection | ||
| handleClearSelection = () => { | ||
| this.setState({ selectedGood: '' }); | ||
| }; | ||
|
|
||
| // Remove (clear) selection — kept as a separate method per request | ||
| handleRemoveSelection = () => { | ||
| this.setState({ selectedGood: '' }); | ||
| }; | ||
|
|
||
| render() { | ||
| return ( | ||
| <main className="section container"> | ||
| <h1 className="title is-flex is-align-items-center"> | ||
| {this.state.selectedGood !== '' ? ( | ||
| <>{this.state.selectedGood} is selected</> | ||
| ) : ( | ||
| <>No goods selected</> | ||
| )} | ||
| {/* eslint-disable-next-line jsx-a11y/control-has-associated-label */} | ||
| {this.state.selectedGood !== '' ? ( | ||
| <button | ||
| data-cy="RemoveButton" | ||
| data-cy="ClearButton" | ||
| type="button" | ||
| className="button is-info" | ||
| > | ||
| - | ||
| </button> | ||
| </td> | ||
|
|
||
| <td data-cy="GoodTitle" className="is-vcentered"> | ||
| Jam | ||
| </td> | ||
| </tr> | ||
| className="delete ml-3" | ||
| onClick={this.handleClearSelection} | ||
| /> | ||
| ) : null} | ||
| </h1> | ||
|
|
||
| <tr data-cy="Good"> | ||
| <td> | ||
| <button data-cy="AddButton" type="button" className="button"> | ||
| + | ||
| </button> | ||
| </td> | ||
| <table className="table"> | ||
| <tbody> | ||
| {goods.map(good => { | ||
| return ( | ||
| <tr | ||
| data-cy="Good" | ||
| key={good} | ||
| className={ | ||
| good === this.state.selectedGood | ||
| ? 'has-background-success-light' | ||
| : '' | ||
| } | ||
| > | ||
| <td> | ||
| {this.state.selectedGood !== good ? ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates the task description: "Don't show |
||
| <button | ||
| data-cy="AddButton" | ||
| type="button" | ||
| className="button" | ||
| data-good={good} | ||
| onClick={this.handleSelectGood} | ||
| > | ||
| + | ||
| </button> | ||
| ) : ( | ||
| <button | ||
| data-cy="RemoveButton" | ||
| type="button" | ||
| className="button is-info" | ||
| onClick={this.handleRemoveSelection} | ||
| > | ||
| - | ||
| </button> | ||
| )} | ||
|
Comment on lines
+78
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates the requirement: "Don't show
This ensures AddButtons are hidden whenever a selection exists and only the selected row shows the RemoveButton, matching the specification and tests. |
||
| </td> | ||
|
|
||
| <td data-cy="GoodTitle" className="is-vcentered"> | ||
| Garlic | ||
| </td> | ||
| </tr> | ||
| </tbody> | ||
| </table> | ||
| </main> | ||
| ); | ||
| <td data-cy="GoodTitle" className="is-vcentered"> | ||
| {good} | ||
| </td> | ||
| </tr> | ||
| ); | ||
| })} | ||
| </tbody> | ||
| </table> | ||
| </main> | ||
| ); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.