-
Notifications
You must be signed in to change notification settings - Fork 178
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
refactor(deps)!: remove moment
dep and usage
#535
refactor(deps)!: remove moment
dep and usage
#535
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
6679442
to
6062986
Compare
`moment` has been [deprecated since Sep 2020](https://momentjs.com/docs/#/-project-status/) and recommends using native `Intl` or newer libraries that make use of native `Intl`, such as `luxon` and `dayjs` - `moment` is also a very large dependency and hence is ripe for pruning and replacement as well - remove `formatTimestamp` function from `v2/utils` as it is unused - it is unused [internally](https://github.com/search?q=repo%3Aargoproj%2Fargo-ui+formattimestamp&type=code) (it is only exported here), unused by [CD](https://github.com/search?q=repo%3Aargoproj%2Fargo-cd%20formattimestamp&type=code), unused by [Workflows](https://github.com/search?q=repo%3Aargoproj%2Fargo-workflows+formattimestamp&type=code) - it's also and unused by Rollouts, which has [two](https://github.com/argoproj/argo-rollouts/blob/c688dd89a7f883c8c004b4024b390104b5be5770/ui/src/app/shared/utils/utils.tsx#L17) [internal](https://github.com/argoproj/argo-rollouts/blob/c688dd89a7f883c8c004b4024b390104b5be5770/ui/src/app/components/rollout/revision.tsx#L21) copies of this function - change `Ticker` component to use plain `Date` instead of `moment` - downstream projects should get a type error on this which should make the switch straightforward - change `Duration` component to use existing `formatDuration` function which doesn't use `moment` - this will look different than the previous version, but the formatting between the two should really be consistent in any case - other option was to just remove this component entirely, since this repo is not actively maintained - leaving the component in instead of deleting it gives a more gradual off-ramp - CD uses this component in [two](https://github.com/argoproj/argo-cd/blob/9ecc5aec2a4dba485eb8b5b0ab75fff8927b3418/ui/src/app/applications/components/application-deployment-history/application-deployment-history.tsx#L1) [places](https://github.com/argoproj/argo-cd/blob/9ecc5aec2a4dba485eb8b5b0ab75fff8927b3418/ui/src/app/applications/components/application-operation-state/application-operation-state.tsx#L1) and Rollouts uses this in [one place](https://github.com/argoproj/argo-rollouts/blob/c688dd89a7f883c8c004b4024b390104b5be5770/ui/src/app/components/pods/pods.tsx#L3) - Workflows does not use this, it has [its own `DurationPanel` component](https://github.com/argoproj/argo-workflows/blob/1dbc856e51967feb58066a4087a8679b08b87be3/ui/src/app/shared/components/duration-panel.tsx#L7) and its own [internal copy](https://github.com/argoproj/argo-workflows/blob/1dbc856e51967feb58066a4087a8679b08b87be3/ui/src/app/shared/duration.ts#L11) of the `formatDuration` function as well - none of these use the `allowNewLines` prop, so it is safe to remove Signed-off-by: Anton Gilgur <[email protected]>
6062986
to
53189d0
Compare
Rebased on top of / fixed merged conflicts with #534 now that it's been merged and marked this ready for review! |
That was intentional, to match the |
OHHH, did you mean the "Active for: 85d"? That does sound buggy and is not equivalent to "02:00 hours" I didn't notice that initially (playing spot the difference as you didn't specify 😅), I thought you just meant the different format in "Time to deploy: 0s" (which is equivalent to the previous "00:00 min") |
ms -> s Signed-off-by: Anton Gilgur <[email protected]>
fd135f7
to
05d91cc
Compare
Should be fixed now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks okay but unable to run storybook locally, deps need updating
Huh well that's more confusing... |
I did some testing: const minute = 60;
const hour = minute * 60;
const day = hour * 24;
// spot checks
console.log(formatDuration(20)); // 20s
console.log(formatDuration(day)); // 24h
console.log(formatDuration(day * 4)); // 4d
// CD screenshot checks
const s4m9s = minute * 4 + 9;
console.log(formatDuration(s4m9s)); // 4m
console.log(formatDuration(s4m9s / 1000)); // 0s
const s4d5h = day * 4 + hour * 5;
console.log(formatDuration(s4d5h)); // 4d
console.log(formatDuration(s4d5h / 1000)); // 6m Those numbers line up exactly -- this means that the above is actually a bug in CD; it's passing seconds to Or, well, that does also mean that this component was buggy; it previously took seconds despite the |
- apparently `durationMs` was incorrectly named as it actually took seconds, not milliseconds - for backward compat, leave `durationMs`, but also introduce `durationS` - and add JSDoc to indicate this to users of the component Signed-off-by: Anton Gilgur <[email protected]>
Signed-off-by: Anton Gilgur <[email protected]>
Added JSDoc indication that looks like: Note that the JSDoc
I made it |
Man, so close. I did a sync in the UI and got this:
|
moment
dep and usagemoment
dep and usage
That error is coming from this line in CD. The error is correct, this PR makes a breaking change to the It'll fail to typecheck as well, as I wrote in my PR description. So that is intentional, CD needs to refactor its usage of the
If there's no other issues, I think this is good to merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks! Do you have time to set up the Argo CD refactor PR?
Sure, it's <2 LoC: argoproj/argo-cd#19655, though I do recommend following that up with a |
Related to the goals of argoproj/argo-workflows#12059, just removing / replacing a large dep entirely.
Follow-up to argoproj/argo-workflows#12097 and #534 here.
Needed for argoproj/argo-workflows#12611
Motivation
moment
has been deprecated since Sep 2020 and recommends using nativeIntl
or newer libraries that make use of nativeIntl
, such asluxon
andday.js
moment
is also a very large dependency and hence is ripe for pruning and replacement as wellModifications
remove
formatTimestamp
function fromv2/utils
as it is unusedchange
Ticker
component to use plainDate
instead ofmoment
change
Duration
component to use existingformatDuration
function which doesn't usemoment
00:00:00
format instead of adding amin
suffix argo-cd#4388DurationPanel
component and its own internal copy of theformatDuration
function as wellallowNewLines
prop, so it is safe to removeVerification
Builds and tests pass
Notes to Reviewers
I actually wrote this weeks ago in Jan (see the commits), around the same time as my other PRs, but this merge conflicts with some of them, so I didn't create the PR, intending to rebase with those once they were merged. It's already been over a month with no review/merge, so I'm placing this here as as Draft at least so I can reference/link to it from other PRs (argoproj/argo-workflows#12611 for instance) and before it gets entirely forgotten 😕