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

feat: add attribute in nested table (PT-186024205) #43

Merged
merged 2 commits into from
Oct 5, 2024

Conversation

emcelroy
Copy link
Contributor

@emcelroy emcelroy commented Sep 26, 2024

#186024205

Adds the ability to add attributes in the nested table view. An "Add Attribute to Collection" button now appears next to the header of each hierarchical level of the table. Clicking the button adds a new attribute, which in turn causes a new column to be added in the target collection's table. The new column is added at the end of the set of table columns, and its header is automatically made editable so the user can change the attribute name from the default newAttr[n] value.

These minor changes are also included:

  1. The padding and showHeaders options are on by default
  2. Fixed dataset selection menu to remain on selected dataset after selection is made
  3. Drops the use of resizeCounter as it didn't appear to do what it was intended to do and was interfering with the ability to edit attribute names

@emcelroy emcelroy force-pushed the 186024205-add-attribute-in-nested-table-2 branch from c9b5466 to 885b797 Compare September 29, 2024 21:13
@emcelroy emcelroy marked this pull request as ready for review September 30, 2024 14:34
Copy link
Member

@scytacki scytacki left a comment

Choose a reason for hiding this comment

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

This generally looks good, but I don't understand the focusSet context.

Also when I play around with it, sometimes I can click on an attribute name in the header to edit it, but not always. Perhaps that is related to this focusSet code?

I also found some rendering issues in the Landscape view. This seems to happen when there are 3 levels. But perhaps that is a known issue.
image

Comment on lines 128 to 132
{
<button className={css.dropdownIcon} onClick={handleShowHeaderMenu}>
{showDropdownIcon && <DropdownIcon className={css.dropdownIcon} />}
</button>
}
Copy link
Member

Choose a reason for hiding this comment

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

The { ... } seems unnecessary here but maybe I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right -- not necessary. I'll remove.

Comment on lines 135 to 139
const focusSetForLevels = new Map<number, boolean>();

const updateFocusSetForLevel = (level: number) => {
focusSetForLevels.set(level, true);
};
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain the purpose of this focus set code?

From what I can tell:

  • on each render of the portrait view table the focusSetForLevels is reset to a new map
  • when updateFocusSetForLevel is called it "sets the focus" for that level.
  • when the PortraitViewRow is rendered it "sets the focus" for its parent level if it isn't already set.
  • the shouldGetFocusOnNewAttribute is based on whether the parent of the row focus

Is the idea to try to track whether the a editable header is being edited (so it has focus)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@scytacki The idea is to determine which instance of a new attribute's column header should get focus when a new attribute is added.

There can be multiple tables for a single level in the hierarchy. In that situation, when a new attribute is added to that level, only the first table's column header for that attribute should become editable. If we don't track that with the focusSetForLevels map and shouldGetFocusOnNewAttribute, the last/bottom table's column header for the new attribute will get focus instead.

I know this isn't ideal. If you have any thoughts on how it might be better handled given that added context, please let me know. If not, I can at least add a comment explaining the purpose.

Copy link
Member

Choose a reason for hiding this comment

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

This is what I see when I try it in CODAPv3:
image

If I understand your intention right, this doesn't seem to be working. I think the reason is because the code assumes the nested tables will be rendered from top to bottom so the first one rendered will get the shouldGetFocusOnNewAttribute. I'm pretty sure the order of the rendering will be random. So this approach won't work. I can't think of a solution off the top of my head, but maybe if we pair we can come up with something. Or maybe this isn't really that important to get right.

@emcelroy emcelroy requested a review from scytacki October 4, 2024 21:45
Copy link
Member

@scytacki scytacki left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@emcelroy emcelroy merged commit 1202bbe into main Oct 5, 2024
5 checks passed
@emcelroy emcelroy deleted the 186024205-add-attribute-in-nested-table-2 branch October 5, 2024 17:29
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