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

fix(compass-crud): show "expand all / collapse all" button on readonly documents COMPASS-4635 #6265

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

kraenhansen
Copy link
Contributor

@kraenhansen kraenhansen commented Sep 19, 2024

Description

To follow the design specification outlined in EXPO-2098.

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • Move "edit" and "delete" buttons under a menu button (once this question resolves)
  • Decrease padding when not editing (as per design bullet 2, once this question resolves).
  • Display the expand / collapse button on ReadonlyDocument (as per design bullet 4).
  • Hide the "expand all" button if the document has no embedded objects (once this question resolves)
  • Show "expand all" button on the JSON view (as per design bullet 3).
  • Adjust the tooltip content by appending "embedded fields" to the text (as per design bullet 5).
  • Adjust the padding around the button icon (as per design bullet 5).
  • Create an issue to track upstreaming the "compact" button with reduced padding as an alternative to the current, less intuitive CSS selector.

Expand / collapse in the "read only" mode

Screen.Recording.2024-09-19.at.22.54.37.mov

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@github-actions github-actions bot added the fix label Sep 19, 2024
@kraenhansen kraenhansen changed the title fix(compass-crud): show "expand all / collapse all" button on readonly documents fix(compass-crud): show "expand all / collapse all" button on readonly documents COMPASS-4635 Sep 19, 2024
@kraenhansen kraenhansen self-assigned this Sep 19, 2024
@@ -44,6 +44,13 @@ const actionsGroupSignalPopover = css({
display: 'block !important',
});

const expandButton = css({
'& > div:has(svg)': {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is less ideal. I'd like to upstream a suggestion for a Size.XSmallCompact size here and here.

Comment on lines +52 to +99
/**
* Subscribe to the update store on mount.
*/
componentDidMount() {
this.subscribeToDocumentEvents(this.props.doc);
}

/**
* Refreshing the list updates the doc in the props so we should update the
* document on the instance.
*/
componentDidUpdate(prevProps: ReadonlyDocumentProps) {
if (prevProps.doc !== this.props.doc) {
this.unsubscribeFromDocumentEvents(prevProps.doc);
this.subscribeToDocumentEvents(this.props.doc);
}
}

/**
* Unsubscribe from the update store on unmount.
*/
componentWillUnmount() {
this.unsubscribeFromDocumentEvents(this.props.doc);
}

/**
* Subscribe to the document events.
*/
subscribeToDocumentEvents(doc: Document) {
doc.on(DocumentEvents.Expanded, this.handleExpanded);
doc.on(DocumentEvents.Collapsed, this.handleCollapsed);
}

/**
* Unsubscribe from the document events.
*/
unsubscribeFromDocumentEvents(doc: Document) {
doc.on(DocumentEvents.Expanded, this.handleExpanded);
doc.on(DocumentEvents.Collapsed, this.handleCollapsed);
}

handleExpanded = () => {
this.setState({ expanded: true });
};

handleCollapsed = () => {
this.setState({ expanded: false });
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is mostly copied from the EditableDocument to react to relevant events on the doc.

@@ -94,7 +178,6 @@ class ReadonlyDocument extends React.Component<ReadonlyDocumentProps> {
static propTypes = {
copyToClipboard: PropTypes.func,
doc: PropTypes.object.isRequired,
expandAll: PropTypes.bool,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was extraenuous. Most likely a leftover from some prop that got removed.

@@ -399,13 +399,15 @@ export const HadronElement: React.FunctionComponent<{
value: HadronElementType;
editable: boolean;
editingEnabled: boolean;
extraPaddingLeft?: number;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Element in the Document now takes some extraPaddingLeft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant