Skip to content
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

Merged
merged 4 commits into from
Jan 16, 2024

Conversation

deletidev
Copy link
Collaborator

Fixed #68

onClick={() => onMoveDownField(field.id)}
disabled={true}
/>
)}
Copy link
Member

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

Copy link
Member

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

Copy link
Collaborator Author

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}
/>
)}
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's fixed

@brauliodiez brauliodiez merged commit ddae78a into main Jan 16, 2024
1 check passed
@brauliodiez brauliodiez deleted the feature/#68-Edit-table-move-field-up-down branch January 16, 2024 09:18
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.

Edit table move field up / down
2 participants