-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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(ui): reorganize shared/utils.ts
#13339
Conversation
let isRunning = false; | ||
let hasFailed = false; | ||
conditions.map(condition => { | ||
if (condition.status === 'False') { | ||
hasFailed = true; | ||
} else if (condition.status === 'Unknown') { | ||
isRunning = true; | ||
} | ||
}); | ||
if (hasFailed) { | ||
classes = [icon, 'status-icon--failed']; | ||
} else if (isRunning) { | ||
classes = [icon, 'status-icon--spin']; | ||
} else { | ||
classes = [icon, 'status-icon--running']; | ||
} |
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.
I simplified this quite a bit as the two flags, hasFailed
and isRunning
, are mutually exclusive (by the logic here but also by definition), so can just return as soon as one of them is hit
- its main purpose is for namespace manipulation, so rename to `shared/namespaces.ts` - and rename `Utils` to `nsUtils` for explicitness as well - this singleton may not be necessary in the future, but keeping it as-is right now for simpler diff - generally speaking, "dumping grounds" are not good to have and organizing them when they get large is best practice - several util functions were used in exactly one place, so just move them to that place - `statusIconClasses` was only used in `phase-icon.tsx` - `isWorkflowRunning`, `isWorkflowSuspended` were only used in `workflow-operations-map.tsx` - some were only used together with exactly one component, so move to that component - `getValueFromParameter` was only used with `ParametersInput` - others were only used for one section of the UI, e.g. Events or Workflows - so move them to a `utils.ts` file there; they are not shared between sections - also `queryParams` was only used in `services/` - also simplify some of these functions: - with optional chaining - by inverting unnecesarily nested conditionals - by removing unnecessary singleton structures - these changes also make these functions easier to unit test and give them proper encapsulation - private functions are no longer exported Signed-off-by: Anton Gilgur <[email protected]>
…eview Signed-off-by: Anton Gilgur <[email protected]>
Signed-off-by: Anton Gilgur <[email protected]>
0918598
to
2ab845e
Compare
Signed-off-by: Anton Gilgur <[email protected]>
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, can you please make the CI pass?
Yea, looks like I accidentally added an extra new line during conflict resolution |
Signed-off-by: Anton Gilgur <[email protected]>
Should pass 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.
Code looks fine, I am unsure if we should merge this personally though, just due to future potential git conflicts.
Same as I wrote in #12539 (comment), this logic applies to any refactor, so this is a strawman, as we ofc don't avoid refactors. |
Attempting to build the UI on `main` currently fails with the following error: ``` ERROR in ./src/app/workflows/components/retry-workflow-node-panel.tsx 26:0-43 Module not found: Error: Can't resolve '../../shared/utils' in '/home/vscode/go/src/github.com/argoproj/argo-workflows/ui/src/app/workflows/components' ``` This is happening due to a merge conflict between argoproj#13343 and argoproj#13339. The latter was merged first and deleted `ui/src/app/shared/utils.ts`, which the former is importing. The reason the CI build didn't fail for the former PR is that the branch wasn't up-to-date with `main` at the time of merge. Signed-off-by: Mason Malone <[email protected]>
While writing various PRs, I've had some of these changes in a stash for a while. When working on some recent namespace fix PRs, this refactor felt particularly necessary given all the unrelated functions to namespaces in this file
Motivation
this file's main purpose is for namespace manipulation, so rename to
shared/namespaces.ts
Utils
tonsUtils
for explicitness as wellthese changes also make these functions easier to unit test and give them proper encapsulation
Modifications
shared/utils.ts
->shared/namespaces.ts
Utils
->nsUtils
several util functions were used in exactly one place, so just move them to that place
statusIconClasses
was only used inphase-icon.tsx
isWorkflowRunning
,isWorkflowSuspended
were only used inworkflow-operations-map.tsx
some were only used together with exactly one component, so move to that component
getValueFromParameter
was only used withParametersInput
others were only used for one section of the UI, e.g. Events or Workflows
utils.ts
file there; they are not shared between sectionsqueryParams
was only used inservices/
also simplify some of these functions:
Verification
yarn lint
,test
&build
all pass