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

Feat#5688: Save As Profile option available for all tabs #8663

Merged
merged 9 commits into from Jul 11, 2023

Conversation

Clem-Fern
Copy link
Contributor

@Clem-Fern Clem-Fern commented Jul 7, 2023

Hi @Eugeny, I hope you are doing well !

I took a look on the feature request #5688 . This PR aims to make the 'Save As Profile' context menu item available for all tabs.

  1. I saw that they were no ID setted with the new saved profile before. It causes the profile to not be shown in the Profiles & Connections selector since the commit c983743 :

    profiles = profiles.filter(x => x.id && !this.config.store.profileBlacklist.includes(x.id))

    Should we create a recovery mechanism? Like creating an ID for profile those does not have one when the config is saved. What would be your approach on this?

  2. During my test, I encountered the same issue as the one describe in The settings button doesn't respond sometimes #8534.

    async save (): Promise<void> {
    await lastValueFrom(this.ready$)
    if (!this._store) {
    throw new Error('Cannot save an empty store')
    }
    // Scrub undefined values
    let cleanStore = JSON.parse(JSON.stringify(this._store))
    cleanStore = await this.maybeEncryptConfig(cleanStore)
    await this.platform.saveConfig(yaml.dump(cleanStore))
    this.emitChange()
    }
    Even with JSON.parse(JSON.stringify(this._store)) and in rare case, some invalid yaml type seems to be present in the config object on yaml dump. Sadly I wasn't able to identify which part precisely... Anyway, adding skipInvalid: true in yaml dump option prevent the method to raise {name: 'YAMLException', reason: 'unacceptable kind of an object to dump [object Function]'} by skipping invalid type.

  3. Also, It could be great to do a bit of refactoring in the future and create methods in the ProfileService for profile creation, edition and deletion to have only one entrypoint for profile operation. It would be simpler to maintain. What do you think ?

As always, feel free to ask me if changes needed :)

Resolve #5688

@Eugeny
Copy link
Owner

Eugeny commented Jul 7, 2023

Wow - great job! Thank you for your continued efforts improving the app by the way :)

  1. We can just assign random UUID IDs to any profiles that don't have one by adding a migration to ConfigService
  2. Weird - the only way would be if some non-json-safe values are added again by maybeEncryptConfig ? Can't immediately think of any place this would happen in
  3. Sounds great!

@Clem-Fern
Copy link
Contributor Author

Thank's for your quick feedback. Well, I'm really glad to know that I'm able to help a bit with my small skills. I would like to help more but the greatest majority of issues stills absolutely out of my league for now ahah

  1. Noted, I will add a commit for that in the next few days.

  2. I think it stills a good idea to leave the skipInvalid: true option to have an additional safeguard. Be sure that I will take another look into this too.

  3. Good! Expect a future PR ;)

@Clem-Fern
Copy link
Contributor Author

Clem-Fern commented Jul 11, 2023

Sorry for the delay,

  1. As discuss, I added a new config migration to assign IDs to any profiles that don't have one. (Lint Job failed during Install Deps)
  2. It's really weird... I was able to reproduce the issue The settings button doesn't respond sometimes #8534 almost all the time by following the path describe by @shankru5. Even with the code below in the save method, the YAMLException still raising. However, it seems that we do not encounter any error if the writing/parsing of the yaml is done with the yaml lib.
 async save (): Promise<void> { 
     await lastValueFrom(this.ready$) 
     if (!this._store) { 
         throw new Error('Cannot save an empty store') 
     } 
     // Scrub undefined values 
     let cleanStore = JSON.parse(JSON.stringify(this._store)) 
     // cleanStore = await this.maybeEncryptConfig(cleanStore) 
     await this.platform.saveConfig(yaml.dump(cleanStore)) 
     this.emitChange() 
 } 

Ready to merge from my side if you are ok with .1 and with the skipInvalid: true workaround for the .2.

@Eugeny
Copy link
Owner

Eugeny commented Jul 11, 2023

Found it! Reading his console log, the error is in readRaw, not save.

readRaw is used to generate the config text for Settings -> Config pane and doesn't have the JSON roundtrip - can you add it in this PR? That would be perfect

@Clem-Fern
Copy link
Contributor Author

Ohhh I see, great! I totally missed that... Thank's for the explanation

@Eugeny Eugeny merged commit e7f7d9b into Eugeny:master Jul 11, 2023
10 checks passed
@Clem-Fern Clem-Fern deleted the feat#5688 branch July 15, 2023 18:36
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.

Save Connection As missing on SSH tabs
2 participants