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

Migrating Vue components to React and stores refactoring #585

Merged
merged 192 commits into from
Aug 20, 2020

Conversation

ixrock
Copy link
Contributor

@ixrock ixrock commented Jul 15, 2020

Most noticeable changes:

In follow-up PRs

ixrock added 30 commits July 3, 2020 14:15
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
# Conflicts:
#	src/common/cluster-store.ts
#	src/common/cluster-store_spec.ts
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
});
server.on("error", error => {
logger.error(`Can't resolve new port: "${error}"`);
reject(error);
Copy link
Contributor

Choose a reason for hiding this comment

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

should there be a defensive server.close() here?

@@ -10,7 +12,10 @@ jest.mock("net", () => {
return this
})
address = () => {
return { port: 12345 }
newPort = Math.round(Math.random() * 10000)
Copy link
Contributor

Choose a reason for hiding this comment

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

why use a random number in this test? (this could return 0, which although it would still pass the test, isn't a valid TCP port number)

* A bit of cleaning in Add Cluster page

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Adding head-col to WizardLayout

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Fixing Cluster Settings general layout bugs

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Cluster Status view refactoring

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Install Metrics component refactoring

Using notifications for error, removed picking
button icon method, simplified button generation.

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Remove icons / checks from RemoveClusterButton

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Fixing colorError in Input styles

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Preventing Input's spellchecking

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* ClusterNameSettings refactoring

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* ClusterWorkspaceSettings refactoring/fixing

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* ClusterProxySetting refactoring

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* ClusterPrometheusSetting refactoring

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Clean up Removal section

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Glued InstallMetrics & InstallUserMode into 1 component

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Removing unused styles in Cluster Settings

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Cluster Settings styling

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Adding close button to settings header

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* ClusterHomeDirSetting refactoring

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* FilePicker restyling

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Fixing Prometheus selector

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Fixing Hashicon

Passing cluster name instead of cluster id to prevent
icon changing while typing new
cluster name

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Minor ClusterSettings fixes

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Increasing opacity for non-interactive icons

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Keep feature install loading state

Waiting for props to change before
disabling loading state (gray button
width spinner)

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Remove arrays in disposeOnUnmount()

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Fix Cluster select behavior

Now clicking cluster icon in sidebar
always leads to / dashboard. And
'Settings' submenu switches active
cluster at first and only the showing
Cluster Settings

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Using structuralComparator in feature installer

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Saving input fields on blur

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Setting Select color same as Input color

Signed-off-by: alexfront <alex.andreev.email@gmail.com>
@Nokel81 Nokel81 linked an issue Aug 7, 2020 that may be closed by this pull request
nevalla and others added 8 commits August 10, 2020 09:03
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
Signed-off-by: alexfront <alex.andreev.email@gmail.com>
Signed-off-by: alexfront <alex.andreev.email@gmail.com>
Signed-off-by: alexfront <alex.andreev.email@gmail.com>
Signed-off-by: alexfront <alex.andreev.email@gmail.com>
* Removing legacy browserCheck() utility

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Revert select box-shadow (outline) color

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Allowing to save prometheus service address

Signed-off-by: alexfront <alex.andreev.email@gmail.com>
This prevents scrollbar flickering caused by Animation component
with 'slide-left' appearing.

Signed-off-by: alexfront <alex.andreev.email@gmail.com>
* Normalizing titles size and weight

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Replacing deployment scale icon

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Replacing download logs icon

Signed-off-by: alexfront <alex.andreev.email@gmail.com>

* Making <h4> tag bigger than <h5>

Signed-off-by: alexfront <alex.andreev.email@gmail.com>
@ixrock ixrock changed the title [WIP]: Migrating Vue components to React and stores refactoring Migrating Vue components to React and stores refactoring Aug 11, 2020
* add some simple user store tests

Signed-off-by: Sebastian Malton <smalton@mirantis.com>

Co-authored-by: Sebastian Malton <smalton@mirantis.com>
syncEnabled: true,
...params,
}
this.init();
Copy link
Collaborator

@Nokel81 Nokel81 Aug 12, 2020

Choose a reason for hiding this comment

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

I think this call is fundamentally broken. It is not awaited (so when the getInstance call finishes the store isn't even up to date) and the default params to init block from enabling sync.

Especially since the load is just called later anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wat? :) can you elablorate/provide more examples?
When you call getInstance() you always have an instance of the store.
Yes, it might be not loaded with a data yet because of async load() and it doesn't mean it is ready-to-use immediately. Every store has isLoaded field which takes in account before app ready to start.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I mean that it seems like a massive foot gun to get one of these and not be able to get the correct data immediately afterwards.

What I mean is that even if you pass into getInstance the argument { parms: { autoLoad: true } } it won't be correct.

Further more, in the default case it seems weird for the unbounded promise (which in future versions of node will abort the process if it throws) halts on await this.whenLoaded. I understand that the point of this is so that enableSync can be started only once the store has loaded but the current method seems clunky.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not be able to get the correct data immediately afterwards

how you can get it immediately for async store loading? (yes, currently it can be loaded sync from file-system, but it was developed to support async load)

didn't get what you mean about await this.whenLoaded and what's wrong with it?
electron has similar stuff, like app.whenReady

Comment on lines 139 to 141
* [Symbol.iterator]() {
yield* Object.entries(this.toJSON());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If it's not used anywhere why we added it? Sounds like a dead code to me 🤔

}

// Logic adapted from dashboard
// see: https://github.com/kontena/kontena-k8s-dashboard/blob/7d8f9cb678cc817a22dd1886c5e79415b212b9bf/client/api/endpoints/nodes.api.ts#L147
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 is not publicly accessible, we should remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

const userPrefs = userStore.getPreferences()
return !!userPrefs.allowTelemetry
} catch (err) {
console.error(`Failed to track "${eventCategory}:${eventAction}"`, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this use logger?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, maybe

@action
protected fromStore({ currentWorkspace, workspaces = [] }: WorkspaceStoreModel) {
if (currentWorkspace) {
this.currentWorkspaceId = currentWorkspace
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @jim-docker here, this code is a bit confusing if it first expects that there are always workspaces and then it still checks if there are none. Maybe stop hard if we detect invalid state (== no workspaces)?

this.contextName = cluster.contextName;
this.defaultNamespace = kc.getContextObject(cluster.contextName).namespace
this.url = `http://${this.id}.localhost:${cluster.port}/`
this.kubernetesApi = `http://127.0.0.1:${cluster.port}/${this.id}`
Copy link
Contributor

Choose a reason for hiding this comment

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

How these changes are related to Vue->React refactoring (I mean most changes in this file)? I'm a bit afraid that these will cause troubles without more testing.

Copy link
Contributor Author

@ixrock ixrock Aug 14, 2020

Choose a reason for hiding this comment

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

Vue->React + stores + overall design requires this changes..

throw("getNextAvailablePort() threw: '" + error + "'")
}
return freePort
export async function getFreePort(): Promise<number> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, how this is related to Vue->React refactoring?

Copy link
Contributor Author

@ixrock ixrock Aug 14, 2020

Choose a reason for hiding this comment

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

It's not like normal converting single vue->react component :)
so please percept this like almost kick-starting new app with extra refactoring (only where it's simple or neccesary)

"electron-builder": "^22.7.0",
"electron-notarize": "^0.3.0",
"electron-rebuild": "^1.11.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

electron-rebuild not required if you use electron-builder, please consider to remove excess dependency from devDependencies

I think we should remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is used in yarn rebuild-pty (this commands helps when switching electron versions)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i'm wondering why it's caring about devDependencies 🤔

@Nokel81 Nokel81 linked an issue Aug 13, 2020 that may be closed by this pull request
ixrock and others added 6 commits August 14, 2020 15:21
Signed-off-by: Roman <ixrock@gmail.com>
* add some basic workspace store tests

Signed-off-by: Sebastian Malton <smalton@mirantis.com>

Co-authored-by: Sebastian Malton <smalton@mirantis.com>
* Views management refactoring

Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
Signed-off-by: Roman <ixrock@gmail.com>
@nevalla nevalla merged commit 5670312 into master Aug 20, 2020
@nevalla nevalla deleted the vue_react_migration branch August 20, 2020 06:02
@nevalla nevalla restored the vue_react_migration branch August 20, 2020 06:04
@nevalla nevalla deleted the vue_react_migration branch August 27, 2020 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
6 participants