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

Type model information in SearchDrawer #5597

Merged
merged 6 commits into from
Oct 8, 2023

Conversation

matmair
Copy link
Member

@matmair matmair commented Sep 22, 2023

This PR moves model information out from the SearchDrawer and in a reusable typed format. That way it can be used in other places and the InstanceRender can not be supplied with unknown models.

Made this to make #5559 simpler

@matmair matmair added refactor Platform UI Related to the React based User Interface labels Sep 22, 2023
@matmair matmair added this to the 0.12.8 milestone Sep 22, 2023
@matmair matmair self-assigned this Sep 22, 2023
@netlify
Copy link

netlify bot commented Sep 22, 2023

Deploy Preview for inventree ready!

Name Link
🔨 Latest commit 7f58c29
🔍 Latest deploy log https://app.netlify.com/sites/inventree/deploys/651ca2a1f2a05a0008d47db7
😎 Deploy Preview https://deploy-preview-5597--inventree.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100
Accessibility: 86
Best Practices: 100
SEO: 70
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@matmair matmair changed the title Type model information in SearcDrawer Type model information in SearchDrawer Sep 22, 2023
Copy link
Contributor

@wolflu05 wolflu05 left a comment

Choose a reason for hiding this comment

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

Generally, I would define one interface for each Model, extending from a Generic model interface. Next create a union type. Then everywhere you need any model, use the union type. Otherwise you can type guard, checking model.type. That way you could define the appropriate type for each renderer, and have type safety there. And generally, are you aware of typescript generics? (I'm not sure if you need them in this scenario, but they get pretty handy)

src/frontend/src/components/render/Instance.tsx Outdated Show resolved Hide resolved
src/frontend/src/components/render/ModelType.tsx Outdated Show resolved Hide resolved
@SchrodingersGat SchrodingersGat removed this from the 0.12.8 milestone Sep 25, 2023
@SchrodingersGat
Copy link
Member

@matmair I am happy with this approach - if you can respond to @wolflu05 I'd like to move forward and merge when we are all happy

@matmair
Copy link
Member Author

matmair commented Sep 27, 2023

I still have to learn the patterns @wolflu05 mentioned and rewrite a bit of code, this will take at least till the weekend

@matmair matmair marked this pull request as draft September 27, 2023 06:07
@matmair matmair marked this pull request as draft September 27, 2023 06:07
@matmair
Copy link
Member Author

matmair commented Oct 4, 2023

@wolflu05 is this the way you meant? I researched generics but i am not sure how one would use them here.

@matmair matmair marked this pull request as ready for review October 4, 2023 21:50
@wolflu05
Copy link
Contributor

wolflu05 commented Oct 5, 2023

Looks much better. The only thing we could do is add typing for each model, instead of using any everywhere. But to keep them in sync, maybe it would be good to generate them via a Python script. But then we are again at the point where it would make sense to generate them from the api schema, which is another topic. I would suggest doing this manually for now so that we have the types already and can auto generate them at a later point.

You're right, you don't need generics here, but they are good to know if you deal with function that have related arguments/return types, so they can be used instead of any. I first thought this would be useful for the model type input and the instance input. But then I realized that we don't have any typing for the models, and therefore also no map from model type keys to the actual model type

@matmair
Copy link
Member Author

matmair commented Oct 6, 2023

@SchrodingersGat this is ready for merge from my POV

@SchrodingersGat SchrodingersGat added this to the 0.13.0 milestone Oct 8, 2023
@SchrodingersGat
Copy link
Member

Cheers @matmair

@SchrodingersGat SchrodingersGat merged commit 608ca75 into inventree:master Oct 8, 2023
19 checks passed
@matmair matmair deleted the typed-drawer branch October 8, 2023 13:34
@SchrodingersGat SchrodingersGat mentioned this pull request Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform UI Related to the React based User Interface refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants