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

pkg/lib: Port various components to TypeScript #20648

Merged

Conversation

allisonkarlitskaya
Copy link
Member

... mostly stuff used by Cockpit Files.

This was all fairly trivial. In utils.tsx most of the changes are adjusting the newer language features rather than adding typing.

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks! This generally looks nice, but (1) subtly breaks the manifest config parser (see failed tests). I also have some questions/suggestions for improvements.

pkg/lib/cockpit-components-dropdown.tsx Outdated Show resolved Hide resolved
pkg/lib/cockpit-components-dropdown.tsx Show resolved Hide resolved
pkg/lib/cockpit-components-dropdown.tsx Show resolved Hide resolved
pkg/lib/cockpit-dark-theme.ts Show resolved Hide resolved
pkg/lib/utils.tsx Show resolved Hide resolved
pkg/lib/cockpit-components-dropdown.tsx Outdated Show resolved Hide resolved
pkg/lib/cockpit-components-dropdown.tsx Outdated Show resolved Hide resolved
@@ -67,12 +73,3 @@ export const KebabDropdown = ({ dropdownItems, position = "end", isDisabled = fa
</Dropdown>
);
};

KebabDropdown.propTypes = {
Copy link
Member

Choose a reason for hiding this comment

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

Yay, that works for ... typescript but this is also something which happens runtime in React which we now lose. (And this only works for full typescript projects, which more and more seems like a mistake to port projects to typescript).

Copy link
Member Author

Choose a reason for hiding this comment

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

I dropped propTypes annotations on previous ports of code to typescript. I'm open to leaving them.

Copy link
Member

Choose a reason for hiding this comment

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

I know and might have even approved it, but it sounds sensible to keep it around for third party consumers and podman/machines. Does it hurt us to keep it around?

Copy link
Member Author

Choose a reason for hiding this comment

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

#20652 gets to the crux of the issue here, I think. Maybe we should discuss this there.

I think we want to be checking our JavaScript with tsc, but not in strict mode. In that case, -machines and friends would indeed benefit from the types.

Copy link
Member

Choose a reason for hiding this comment

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

Only if you use typescript, which we don't require. So proptypes can stay useful. I don't think I rely on them as they are runtime and a warning. But when I do spot such issues I usually fix it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can bring it back.

@allisonkarlitskaya allisonkarlitskaya force-pushed the monday-morning-typescript branch 2 times, most recently from b0204eb to 3a88ccf Compare June 24, 2024 07:53
martinpitt
martinpitt previously approved these changes Jun 24, 2024
Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Thanks, I resolved all my previous threads. Assuming this goes green, good enough for me. But please also wait for @jelly 's re-review, not sure how strongly he feels about propTypes. They still seem to make sense to me for projects which aren't 100% TS yet (i.e. all but -files 😁 )

@martinpitt martinpitt requested a review from jelly June 24, 2024 08:20
... mostly stuff used by Cockpit Files.

This was all fairly trivial.  In `utils.tsx` most of the changes are
adjusting the newer language features rather than adding typing.

For <Dropdown> we drop the `props` property — it's unused.
if (window.debugging == "all" || window.debugging?.includes("style")) {
console.debug([`cockpit-dark-theme: ${document.documentElement.id}:`, ...arguments].join(" "));
console.debug([`cockpit-dark-theme: ${document.documentElement.id}:`, ...args].join(" "));
Copy link
Contributor

Choose a reason for hiding this comment

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

This added line is not executed by any test.

Copy link
Member

@martinpitt martinpitt left a comment

Choose a reason for hiding this comment

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

Static and dynamic type testing? What a treat! 🙊

@allisonkarlitskaya
Copy link
Member Author

Static and dynamic type testing? What a treat! 🙊

einmal mit alles, bitte. auf die hand.

@@ -21,7 +21,7 @@ import React, { useState } from 'react';
import PropTypes from "prop-types";

import { MenuToggle } from "@patternfly/react-core/dist/esm/components/MenuToggle";
import { Dropdown, DropdownList } from "@patternfly/react-core/dist/esm/components/Dropdown";
import { Dropdown, DropdownList, DropdownPopperProps } from "@patternfly/react-core/dist/esm/components/Dropdown";
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we want to use import type not sure if get is useful because the current form wont get shook? Or does it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think import type only makes sense on files that you wouldn't already import for non-type reasons.

ie: If you already have an import then don't add an import type. But if you wouldn't otherwise have an import, and only want it for typing reasons, then import type is the one you want.

@jelly jelly merged commit fdcd3a2 into cockpit-project:main Jun 25, 2024
80 checks passed
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.

None yet

4 participants