-
Notifications
You must be signed in to change notification settings - Fork 29
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
Feature/#68 edit table move field up down #117
Conversation
onClick={() => onMoveDownField(field.id)} | ||
disabled={true} | ||
/> | ||
)} |
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.
MMm.. I think we could write this as:
<CommandIconButton
icon={<DownIcon />}
onClick={() => onMoveDownField(field.id)}
disabled={fields[fields.length - 1].id !== field.id }
/>
So it would be something like:
- {fields[fields.length - 1].id !== field.id ? (
<CommandIconButton
icon={<DownIcon />}
onClick={() => onMoveDownField(field.id)}
+ disabled={fields[fields.length - 1].id !== field.id }
/>
- ) : (
- <CommandIconButton
- icon={<DownIcon />}
- onClick={() => onMoveDownField(field.id)}
- disabled={true}
- />
- )}
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.
And as additional enhancement we can add a small helper function (even could be moved to business and unit tested):
const isLasItemInArray = (fields : FieldVm[], fieldId : GUID) : boolean =>
fields[fields.length - 1].id !== fieldId
The the code would be a bit easier to read:
<CommandIconButton
icon={<DownIcon />}
onClick={() => onMoveDownField(field.id)}
disabled={isLasItemInArray(fields, field.id)}
/>
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.
It's fixed
onClick={() => onMoveUpField(field.id)} | ||
disabled={true} | ||
/> | ||
)} |
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.
Similar solution here:
const isFirstItemInArray = (fields : FieldVm[], fieldId : GUID) : boolean =>
fields[0].id !== field.id
And in the markup
<CommandIconButton
icon={<UpIcon />}
onClick={() => onMoveUpField(field.id)}
disabled={isLasItemInArray(fields, field.id)}
/>
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.
It's fixed
Fixed #68