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

Entity type editor – Show correct properties in property selector, add edit bar, and minor changes #1184

Merged
merged 24 commits into from
Oct 12, 2022

Conversation

nathggns
Copy link
Contributor

@nathggns nathggns commented Oct 11, 2022

🌟 What is the purpose of this PR?

Next stage in entity type editor – see below.

πŸ”— Related links

🚫 Blocked by

N/A

πŸ” What does this change?

Functionality changes:

  • Populate property type selector with existing property types, hide property types already added
  • Ensure the property type you click on is the one inserted and displayed
  • Temporarily remove inoperable property menu buttons
  • Ensure property menu shows the correct version number
  • Edit bar – including operable discard changes button
  • Add JSON object type for expected values chips
  • Tooltip with full path for property type in the property type menu

Code changes:

  • New useInitTypeSystem hook – and init the type system on the view entity type page
  • useEntityType hook now takes on onCompleted param, which we use to reset the state of the editor whenever the entity type loads
  • We no longer use router.asPath to resolve the entity type – this fixes a bug where hash or query params breaks finding the entity type
  • The state management of changes / UI mode has been moved to simplify the UI
  • All property types are now fetched on load and provided via a context to enable the property selector to display them
  • New dataTypeNames to show the human readable name of data type chips
  • The new property type menu no longer inserts a fake property type – this is in preparation for making it actually work

πŸ“œ Does this require a change to the docs?

N/A

⚠️ Known issues

🐾 Next steps

πŸ›‘ What tests cover this?

❓ How to test this?

  1. Create an entity type in the new entity type form
  2. Ensure you can select property types from the property type selector and that the edit bar appears
  3. Ensure you can remove property types
  4. Ensure discard changes on the edit bar works

@github-actions github-actions bot added area/apps > hash* Affects HASH (a `hash-*` app) frontend labels Oct 11, 2022
@nathggns nathggns marked this pull request as ready for review October 11, 2022 17:33
@lgtm-com
Copy link

lgtm-com bot commented Oct 11, 2022

This pull request introduces 1 alert when merging 739444a into 6303196 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@lgtm-com
Copy link

lgtm-com bot commented Oct 11, 2022

This pull request introduces 1 alert when merging 509121d into 074ed5d - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

Copy link
Contributor

@kachkaev kachkaev left a comment

Choose a reason for hiding this comment

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

The diff looks clean – I've left a couple of optional code style suggestions

discardButtonProps: ButtonProps;
confirmButtonProps: ButtonProps;
}) => (
<Container
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional, for all similar cases: it'd useful to use explicit return statements in all React components instead of this arrow function shortcut. If we need to add some hook later, we won't end up with a crazy diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there an autofixable lint rule for this? I tend to agree (from an "optimise for change" perspective) – although not for diff reasons because you can just hide whitespace in the diff, just for reducing friction of adding a hook. You could create a ticket?

Copy link
Contributor

Choose a reason for hiding this comment

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

you can just hide whitespace in the diff

That won't help if JSX is wide enough to be re-formatted.

I created https://app.asana.com/0/1200211978612931/1203132574912430/f

Comment on lines +8 to +20
const EditBarContents = ({
icon,
title,
label,
discardButtonProps,
confirmButtonProps,
}: {
icon: ReactNode;
title: ReactNode;
label: ReactNode;
discardButtonProps: ButtonProps;
confirmButtonProps: ButtonProps;
}) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

I remember us chatting about potential removal of FunctionComponent in code, but if we go for it, we should probably do so in some organised way. I'd stick with FunctionComponent for consistency for now, especially for exportable components. Defining type FooBarProps separately can also contribute to overall consistency. I'm not strongly opinionated about any of the styles, just suggesting to keep code rhythm as consistent as possible.

Comment on lines +136 to +138
const OntologyChipForwardRef = forwardRef(OntologyChip);

export { OntologyChipForwardRef as OntologyChip };
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const OntologyChipForwardRef = forwardRef(OntologyChip);
export { OntologyChipForwardRef as OntologyChip };
export const OntologyChip = forwardRef(RenderOntologyChip);
Suggested change
const OntologyChipForwardRef = forwardRef(OntologyChip);
export { OntologyChipForwardRef as OntologyChip };
export const OntologyChip = forwardRef(renderOntologyChip);

etc.

ForwardRefRenderFunction is not a React component because it has two args instead of one. It's useful to call ref forwarding functions distinctly to avoid accidental misuse or confusion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What you're suggesting messes up the name in dev tools, hence this approach (which is already used elsewhere in the project).

We want the dev tools to look like this

image

What you're suggesting makes it look like this

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's also worth saying forwardRef is a stop gap solution. They plan to remove it. reactjs/rfcs#107

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right I did not know about that effect for the dev tools. I think I usually just call forwardRef inline, but I'm beginning to forget that. Need to write more react code πŸ˜…

@nathggns nathggns merged commit 2646115 into main Oct 12, 2022
@nathggns nathggns deleted the nh/entity-type-view branch October 12, 2022 14:17
@vilkinsons vilkinsons added type/eng > frontend Owned by the @frontend team and removed area: frontend labels Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apps > hash* Affects HASH (a `hash-*` app) type/eng > frontend Owned by the @frontend team
Development

Successfully merging this pull request may close these issues.

3 participants