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

Adding functionality to switch user terminal to dom. #15892

Merged
merged 6 commits into from
Feb 12, 2020

Conversation

Katka92
Copy link
Contributor

@Katka92 Katka92 commented Jan 31, 2020

What does this PR do?

Add functionality to switch terminal to dom. This would allow us to check the text in the terminal.

What issues does this PR fix or reference?

Part of #15038

@che-bot che-bot added status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. kind/enhancement A feature request - must adhere to the feature request template. labels Jan 31, 2020
@che-bot
Copy link
Contributor

che-bot commented Jan 31, 2020

✅ E2E Happy path tests succeed 🎉

See Details

Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1)

@che-bot
Copy link
Contributor

che-bot commented Jan 31, 2020

E2E tests of Eclipse Che Multiuser on OCP has been successful:

@che-bot
Copy link
Contributor

che-bot commented Jan 31, 2020

Can one of the admins verify this patch?

constructor(@inject(CLASSES.RequestHandler) private readonly requestHandler: RequestHandler) {
}

public async setTerminalToDom() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Method implementation looks overflowed, please try to clean up method and make it more readable.
(Simplifying logic, extracting steps to the atomic private methods ...)

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah... I would actually do two changes here.

  1. I would change this method to be more general (something like setTerminalType(string/enum) so we can switch back and forth if needed. This shouldn't be a big change.
  2. I would also prefer separation to for example two methods - this one would be handling the requests (get/post) and second one would be handling the work with json (parsing&editing the json object)

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've simplified the logic, so now I don't think we need to separate it to methods. WDYT? Can you please review it again?

@Katka92 Katka92 force-pushed the add_terminal_switch branch from 581cc8f to 1d9b28e Compare February 5, 2020 13:13
@che-bot
Copy link
Contributor

che-bot commented Feb 5, 2020

✅ E2E Happy path tests succeed 🎉

See Details

Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1)

@che-bot
Copy link
Contributor

che-bot commented Feb 5, 2020

E2E tests of Eclipse Che Multiuser on OCP has been successful:

@che-bot
Copy link
Contributor

che-bot commented Feb 5, 2020

❌ E2E Happy path tests failed ❗

See Details

Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1)

⚠️ https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

ℹ️ Use comment "crw-ci-test" to rerun happy path E2E test.

@Katka92
Copy link
Contributor Author

Katka92 commented Feb 5, 2020

crw-ci-test

@che-bot
Copy link
Contributor

che-bot commented Feb 5, 2020

✅ E2E Happy path tests succeed 🎉

See Details

Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1)

@che-bot
Copy link
Contributor

che-bot commented Feb 5, 2020

E2E tests of Eclipse Che Multiuser on OCP has been successful:

@che-bot
Copy link
Contributor

che-bot commented Feb 6, 2020

❌ E2E Happy path tests failed ❗

See Details

Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1)

⚠️ https://github.com/orgs/eclipse/teams/eclipse-che-qa please check this report.

ℹ️ Use comment "crw-ci-test" to rerun happy path E2E test.

@che-bot
Copy link
Contributor

che-bot commented Feb 6, 2020

E2E tests of Eclipse Che Multiuser on OCP has been successful:

@Katka92 Katka92 force-pushed the add_terminal_switch branch from 014a550 to 80b66cf Compare February 7, 2020 09:41
@che-bot
Copy link
Contributor

che-bot commented Feb 7, 2020

✅ E2E Happy path tests succeed 🎉

See Details

Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1)

constructor(@inject(TYPES.HeaderHandler) private readonly headerHandler: IHeaderHandler) {
}

async get(url: string) : Promise<AxiosResponse> {
Copy link
Contributor

Choose a reason for hiding this comment

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

On my opinion the relativeUrl will be more convenient here.
Because simple url may leads to confusion,
for example if I see url I think about full url http://www.example....
but in this case, uses relative URL.

return await axios.get(this.assembleUrl(url), await this.headerHandler.getHeaders());
}

async post(url: string, data?: string) : Promise<AxiosResponse> {
Copy link
Contributor

Choose a reason for hiding this comment

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

}
}

async delete(url: string) : Promise<AxiosResponse> {
Copy link
Contributor

Choose a reason for hiding this comment

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

return await axios.delete(this.assembleUrl(url), await this.headerHandler.getHeaders());
}

private assembleUrl(url: string) : string {
Copy link
Contributor

Choose a reason for hiding this comment

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

async post(url: string, data?: string) : Promise<AxiosResponse> {
if ( data === undefined ) {
return await axios.post(this.assembleUrl(url), await this.headerHandler.getHeaders());
} else {
Copy link
Contributor

@Ohrimenko1988 Ohrimenko1988 Feb 7, 2020

Choose a reason for hiding this comment

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

Redundant else

    async post(url: string, data?: string): Promise<AxiosResponse> {
        if (data === undefined) {
            return await axios.post(this.assembleUrl(url), await this.headerHandler.getHeaders());
        }

        return await axios.post(this.assembleUrl(url), data, await this.headerHandler.getHeaders());
    }

Do you agree that it looks more clear than:

    async post(url: string, data?: string) : Promise<AxiosResponse> {
        if ( data === undefined ) {
            return await axios.post(this.assembleUrl(url), await this.headerHandler.getHeaders());
        } else {
            return await axios.post(this.assembleUrl(url), data, await this.headerHandler.getHeaders());
        }
    }

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see much difference in this specific case. I understand that the form you are suggesting could be very beneficial in some other cases.
If it would be for my personal feeling, then here (and I emphasize here), the version with else is a bit more nicer to my eyes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here you can read an extended description of the rule I mentioned.
Of course, this is not a very serious resource, but if you want
I can find a more serious source.
https://www.geeksforgeeks.org/writing-clean-else-statements

Copy link
Contributor

@dmytro-ndp dmytro-ndp Feb 7, 2020

Choose a reason for hiding this comment

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

I would suggest to prefer If without else where it's possible, because it shortens possible execution paths and so makes the code easier to read and understand.
This specific case Smalltalk calls "guard clauses" https://softwareengineering.stackexchange.com/a/18459

Copy link
Contributor

Choose a reason for hiding this comment

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

Heh... This conversation about ifs and elses is starting to be almost "decadent" :-D
Nobody is questioning, that the approach you are suggesting here and all the resources you are linking here are talking about is the right approach in general and in most of the cases, but in some specific cases writing else statement could be "neutral" (nor good, nor bad) :-D
Anyway... To close this pointless discussion... Isn't this if unecessary after all? Because axios.post has data as optional:

post<T = any>(url: string, data?: any, config?: AxiosRequestConfig): AxiosPromise<T>;

Thus we don't have to care about that at all, isn't that right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Of course, you are right, if axios can apply null data. But I am not 100% that axios handle null data in the way we expected. Should be verified I guess.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll try that and if it handles null data correctly, I'll push this.

constructor(@inject(CLASSES.TokenHandler) private readonly tokenHandler: TokenHandler) {
}
async getHeaders() : Promise<AxiosRequestConfig> {
let token = await this.tokenHandler.getCheBearerToken();
Copy link
Contributor

Choose a reason for hiding this comment

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

According to the best practices, we should use "const" where it possible.
In this case, token will not be changed so better to use const instead let

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, it would be great don't forget about types, so declare the "string" type here, please.


@injectable()
export class SingleUserHeaderHandler implements IHeaderHandler {
async getHeaders() {
Copy link
Contributor

Choose a reason for hiding this comment

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

getHeaders() : Promise<AxiosRequestConfig> ?

import { TestConstants } from '../TestConstants';

@injectable()
export class TokenHandler {
Copy link
Contributor

Choose a reason for hiding this comment

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

It also would be great to make the TokenHandler optional (ITokenHandler).
This will make it possible to fully manage queries with inversify and not think about rebuilding logic in the future.
Because for now, it looks like a bottleneck in the queries handling logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what you mean by this. Could you please elaborate a bit more?

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean that with current changes we may easily configure all parts of the RequestHandler except token obtaining part. And I see that it may be a problem in the future. For example if we will need test "Che" with external keycloak. And this is only one example.
In this case we will not be able to reconfigure RequestHandler for successful queries
using inversify.
And I suggest to lay this opportunity.
Besides, it doesn't require a lot of changes, minutes on this stage may save hours or even days in the future.

Copy link
Contributor

@rhopp rhopp Feb 7, 2020

Choose a reason for hiding this comment

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

Hmm.. Hosted che is not using keycloak.. So the logic for obtaining active token there is completely different.
@Katka92 How did you plan to deal with that on hosted che side? Did you want to create your own implementation of IHeaderHandler and there use your own logic (possible own class, as it's here) for token obtaining?
I wouldn't even be against having token obtaining part (what is now TokenHandler) implemented direclty inside MultiUserHeaderHandler.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rhopp I was for having the code from TokenHandler directly in MultiUserHeaderHandler, but as @Ohrimenko1988 wanted it strictly separated I created this class.
When I was creating it, I was thinking about having class (e.g. HostedCheHeaderHandler) implementing IHeaderHandler which will use our own token handling logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Ohrimenko1988 If I compare your solution to mine, we only differ in the fact, that you put "another layer" there. I didn't... just because I don't find this necessary.

Thinking about it now, I can think of only one reason to keep the mechanism of obtaining token separate - And that's if somebody would need to use the token without using CheApiRequestHandler... Is that why you separated this into own layer? If we have good (future) use case for this, let's go with this separation. If no, I would prefer to use "simpler" approach.

Copy link
Contributor

@Ohrimenko1988 Ohrimenko1988 Feb 10, 2020

Choose a reason for hiding this comment

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

We have several different places. My variant gives us huge flexibility and the possibility to reuse all separated modules (for example "Token") in other places.
Let's agree to stop discussing about placing all to the one place, at least this approach doesn't respect SOLID principles, and I don't see any reason for intentional misconduct these principles and reducing the quality of the code.
I strongly disagree with your point that if the proposed solution resolves a specific problem we don't care about anything else. And for forwarding the best practices we need additional reasons.
Just resolve a problem don't enough for me. We should think strategically. This solution should respect the code quality, clean code principles and don't reduce tests flexibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok. Let's go with your variant.
I don't particularly like the (in my opinion unecessary) overengineering, but I see I don't have any strong case against (except of simplicity).
@Katka92 Can you please act on this and provide update when you have time to do so? Or should somebody else take this responsibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ohrimenko1988 Could you please make a PR with your branch to mine? It will be easier for me to apply all the changes. I'll test it and commit changes here for the final review. Thank you

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not overengineering, just respecting best practices.

@che-bot
Copy link
Contributor

che-bot commented Feb 7, 2020

E2E tests of Eclipse Che Multiuser on OCP has failed:

@dmytro-ndp
Copy link
Contributor

@Katka92: what about storing PreferencesHandler.ts and TokenHandler.ts together with other files in the utils/requestHandlers/ directory?

@che-bot
Copy link
Contributor

che-bot commented Feb 12, 2020

✅ E2E Happy path tests succeed 🎉

See Details

Tested with Eclipse Che Multiuser User on K8S (minikube v1.1.1)

@che-bot
Copy link
Contributor

che-bot commented Feb 12, 2020

E2E tests of Eclipse Che Multiuser on OCP has been successful:

Copy link
Contributor

@Ohrimenko1988 Ohrimenko1988 left a comment

Choose a reason for hiding this comment

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

Looks good for me. Thank you for collaboration.

@Katka92 Katka92 merged commit f2273b2 into eclipse-che:master Feb 12, 2020
@che-bot che-bot removed the status/code-review This issue has a pull request posted for it and is awaiting code review completion by the community. label Feb 12, 2020
@che-bot che-bot added this to the 7.9.0 milestone Feb 12, 2020
@Katka92 Katka92 deleted the add_terminal_switch branch April 21, 2020 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement A feature request - must adhere to the feature request template.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants