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

Use two separate types for IChartCatalogItem and IOperatorCatalogItem. #1806

Merged
merged 1 commit into from
Jun 22, 2020

Conversation

absoludity
Copy link
Contributor

It's not perfect - there's more that could be DRY'd up and encapsulated,
but with this change you can actually use TypeScript's type system to
ensure the correct fields are present.

I've not done an IRL test, this is just to demo the thought.

Fixes #1803 (maybe). Ref #1762

@@ -9,7 +9,7 @@ import { MessageAlert } from "../ErrorAlert";
import LoadingWrapper from "../LoadingWrapper";
import PageHeader from "../PageHeader";
import SearchFilter from "../SearchFilter";
import CatalogItem, { ICatalogItem } from "./CatalogItem";
import CatalogItem, { ICatalogItemProps, IChartCatalogItem, IOperatorCatalogItem } from "./CatalogItem";
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 specific interfaces are only required for generating the segment of the key that differs depending on the type... not sure if that segment is required for uniqueness? (see below, line 106, where it includes either the csv or the repo name).

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

Comment on lines +106 to +107
const keyComponent = c.type === "operator" ? (c.item as IOperatorCatalogItem).csv : (c.item as IChartCatalogItem).repo.name;
return <CatalogItem type={c.type} key={`${c.type}/${keyComponent}/${c.item.name}`} item={c.item} />
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems unnecessary complex for just the key but I don't have a better proposal 🤔

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 just for the required unique key, I think? so we could instead just use the index... I wasn't sure as I was only refactoring this code, so left it as it was - let me know if there's a reason for the more structured key?

// Cosmetic change, remove the version from the csv name
const csvName = props.csv.split(".v")[0];
const tag1 = <span>{csvName}</span>;
const link = `/ns/${namespace}/operators-instances/new/${csv}/${id}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

this link should be obtained from a function :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - grepping for "/ns/.*operator" shows quite a few operator URLs in non-test code that aren't using the shared urls helper (or even have a url helper defined as in this case for the operator-instance new).

@absoludity absoludity force-pushed the 1762-mc-ui-state branch 2 times, most recently from 1dce11e to 1ab6f1a Compare June 22, 2020 00:21
Base automatically changed from 1762-mc-ui-state to master June 22, 2020 01:30
It's not perfect - there's more that could be DRY'd up and encapsulated,
but with this change you can actually use TypeScript's type system to
ensure the correct fields are present.

I've not done an IRL test, this is just to demo the thought.

Fixes #1803 (maybe)
@absoludity absoludity merged commit 99225a5 into master Jun 22, 2020
@absoludity absoludity deleted the 1762-mc-ui-interlude branch June 22, 2020 02:25
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.

ICatalogItemProps encapsulates two different types with conditionals
2 participants