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: dockge set/update agent friendly name #414

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

lohrbini
Copy link

@lohrbini lohrbini commented Feb 1, 2024

⚠️⚠️⚠️ Since we do not accept all types of pull requests and do not want to waste your time. Please be sure that you have read pull request rules:
https://github.com/louislam/dockge/blob/master/CONTRIBUTING.md

Tick the checkbox if you understand [x]:

  • I have read and understand the pull request rules.

Disclaimer

I am not a Software programmer and only have basic understandings on any Programming Languages used in the project, so please be patient and maybe assist me with further development of this feature

Description

Since dockge agents is still a beta feature and in the future maybe more and more remote instances will be added I wanted to enable the option for setting a friendly name for a remote instance. If the name is not set via the prompt. The default agent.url will be displayed
Fixes #345

Type of change

  • New feature (non-breaking change which adds functionality)

  • My code follows the style guidelines of this project

  • I ran ESLint and other linters for modified files

  • I have performed a self-review of my own code and tested it

  • I have commented my code, particularly in hard-to-understand areas
    (including JSDoc for methods)

  • My changes generate no new warnings

  • My code needed automated testing. I have added them (this is optional task)

Screenshots

dgagents-friendlyname

Add the option to set a friendly name to a dockge remote
agent. If the field is not used the `agent.url` will be
displayed
@cyril59310
Copy link
Contributor

cyril59310 commented Feb 1, 2024

After testing your PR, I have two small remarks:

  1. Could you add the translation key "Friendly Name" to the en.json file?
  2. It would be interesting for the friendly name to be applied here as well
    si7sb7
    hhi5hq

@lohrbini
Copy link
Author

lohrbini commented Feb 1, 2024

Hey @cyril59310,

thanks for your feedback.

The translation can be added - for sure.
Could you maybe point out, where the friendlyName is missing exactly ? Figured out where you want to add the friendlyName

Currently trying to refactor the code a bit to enable renaming - which seems more difficult as expected ..

@cyril59310
Copy link
Contributor

In the file

frontend/src/lang/en.json ,

please add "Friendly Name": "Friendly Name" so that translators can translate it into other languages using our Weblate tool.

adding `Friendly Name` to en.json
allow updates and removal of `friendly name`
@lohrbini
Copy link
Author

lohrbini commented Feb 1, 2024

@cyril59310 point 2 of your request is now also done. Only need to update codebase and remove all debug options

image

@lohrbini lohrbini force-pushed the feat/dockge-agents-friendly-name branch from 6529f6d to 96b5205 Compare February 2, 2024 06:17
adding the `friendlyname` option to the running and paused container
@lohrbini lohrbini force-pushed the feat/dockge-agents-friendly-name branch from 96b5205 to 8f142af Compare February 2, 2024 06:20
@cyril59310
Copy link
Contributor

Thank you for taking my feedback.
I noticed afterwards that here too, the friendly name could be added.
image

when create a new stack via UI the friendly name should also be displayed
@lohrbini
Copy link
Author

lohrbini commented Feb 3, 2024

Thanks again @cyril59310 . This is now also implemented

Merge branch 'feat/dockge-agents-friendly-name' into feat/dockge-agents-friendly-name-editable
add a query to update the friendlyname correctly
remove edit-pen for controller which cannot have a friendlyname for now
@lohrbini
Copy link
Author

lohrbini commented Feb 6, 2024

Finally I was able to get the update feature working. Friendly names are now updated properly by a small dialog

image
image

@larswmh maybe need help this time with syntaxing/linting issues for sqlite statement. Or even a better solution than a "hardcoded" query

@lohrbini lohrbini changed the title feat: dockge agent friendly name feat: dockge set/update agent friendly name Feb 6, 2024
fix tsc check by updating var type
remove if condition and update to proper values to prevent
duplicates
@lohrbini lohrbini force-pushed the feat/dockge-agents-friendly-name branch from 1e688f8 to dcc48d3 Compare February 6, 2024 07:55
@cyril59310
Copy link
Contributor

cyril59310 commented Feb 6, 2024

I made some suggestions in order to add translation keys for our translators.

@@ -7,6 +7,7 @@ export async function up(knex: Knex): Promise<void> {
table.string("url", 255).notNullable().unique();
table.string("username", 255).notNullable();
table.string("password", 255).notNullable();
table.string("friendlyname", 255);
Copy link
Owner

@louislam louislam Feb 6, 2024

Choose a reason for hiding this comment

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

This file cannot be modified. Have to create a new file.

Migration guide:
https://github.com/louislam/uptime-kuma/tree/master/db/knex_migrations

Also the naming convention, it should be friendly_name.

Will come back later, as I would like to finish the next milestone of Uptime Kuma first.

@louislam louislam added this to the 1.5.0 milestone Feb 6, 2024
@louislam louislam added the question Further information is requested label Feb 6, 2024
*/
async add(url : string, username : string, password : string) : Promise<Agent> {
async add(url : string, username : string, password : string, friendlyname : string) : Promise<Agent> {
Copy link
Owner

Choose a reason for hiding this comment

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

Name Conventions

  • Javascript/Typescript: camelCaseType
  • SQLite: snake_case (Underscore)
  • CSS/SCSS: kebab-case (Dash)

https://github.com/louislam/dockge/blob/master/CONTRIBUTING.md#name-conventions

Copy link
Author

Choose a reason for hiding this comment

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

all namings has been updated

Copy link

@nathan815 nathan815 left a comment

Choose a reason for hiding this comment

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

Nice feature!

Have some code feedback

*/

async update(friendlyname : string, updatedFriendlyName : string) {
await R.exec("UPDATE agent SET friendlyname = " + updatedFriendlyName + " WHERE friendlyname = " + friendlyname + "");

Choose a reason for hiding this comment

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

SQL injection vuln here - if name has quotes this will break.

You can use parameter bindings to build queries safely:

await R.exec("UPDATE agent SET friendlyname = ? WHERE friendlyname = ?", [
    updatedFriendlyName,
    friendlyname
]);

https://github.com/louislam/redbean-node/blob/master/docs/Query.md

Choose a reason for hiding this comment

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

Instead of a raw query, you could utilize the redbean ORM methods. See: https://github.com/louislam/redbean-node/blob/master/docs/Create-Update-Bean.md

Something like this if by ID (primary key):

const agent = await R.load('agent', id);
agent.friendlyName = friendlyName;
await R.store(agent);

Or by URL:

const agent = await R.findOne('agent', ' url = ? ', [url]);
agent.friendlyName = friendlyName;
await R.store(agent);

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the input. Added this with update by url and started a small "discussion"
#414 (comment)

* @param updatedFriendlyName
*/

async update(friendlyname : string, updatedFriendlyName : string) {

Choose a reason for hiding this comment

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

I would consider accepting the agent's id or the url here for identifying the agent to update instead of friendly name.

ID is the primary key, so thats probably best to use for updating the agent. But URL is always set and has a unique constraint, so it will work too.

Choose a reason for hiding this comment

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

I agree with nathan, I would refactor to pass id around for the agent

Copy link
Author

Choose a reason for hiding this comment

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

sure it should be the id ? it is currently not passed in the agentList and needs to be added. If a host will be added and deleted it will still increase and not release a taken number. The url would be the "better" identifier ?
( just a small comment. I am not against refactoring this to id but while updating this MR I was thinking about)

Comment on lines 26 to 27
friendlyname: this.friendlyname,
updatedFriendlyName: this.updatedFriendlyName

Choose a reason for hiding this comment

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

Why is updatedFriendlyName also here on the model? Shouldn't just friendlyName be sufficient?

Copy link
Author

Choose a reason for hiding this comment

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

I forgot to update this file while adding the other suggestions but it still worked with the correct variables. Where is this needed 🤔

@lohrbini
Copy link
Author

Long time no see. Will have a look the next days on all your feedback. Many thanks 🙏🏻

Copy link

@kayakyakr kayakyakr left a comment

Choose a reason for hiding this comment

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

I appreciate this addition. Short of hacking the docker swarm mechanics to do node auto-discovery, I think is a fairly nice quality of life improvement.

Left some comments on some changes I'd make to make this prod-ready.

* @param updatedFriendlyName
*/

async update(friendlyname : string, updatedFriendlyName : string) {

Choose a reason for hiding this comment

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

I agree with nathan, I would refactor to pass id around for the agent

@@ -23,6 +23,8 @@ export class Agent extends BeanModel {
url: this.url,
username: this.username,
endpoint: this.endpoint,
friendlyname: this.friendlyname,

Choose a reason for hiding this comment

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

recommendation: you should consider just naming this field name. There are no conflicts using the simpler version of the field name.

Comment on lines 76 to 78
if (typeof(updatedFriendlyName) !== "string") {
throw new Error("FriendlyName must be a string");
}

Choose a reason for hiding this comment

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

the more you know: since this is typescript, you shouldn't actually need to typecheck the input value for friendly name. We already know it's a string from before.

</template>

<!-- Edit FriendlyName -->
<font-awesome-icon v-if="agent.friendlyname !== '' && agent.friendlyname !== ''" icon="pen-to-square" @click="showEditAgentFriendlynameDialog[agent.friendlyname] = !showEditAgentFriendlynameDialog[agent.friendlyname]" />

Choose a reason for hiding this comment

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

suggestion: I'm not sure why you're checking for blank string twice here, but if you switch to passing around agent.id you will be able to edit a name no matter if the server was created with friendly name or not, so the v-if will be unnecessary.

<!-- Edit Dialog -->
<BModal v-model="showEditAgentFriendlynameDialog[agent.friendlyname]" :no-close-on-backdrop="true" :close-on-esc="true" :okTitle="$t('Update Friendlyname')" okVariant="info" @ok="updateFriendlyname(agent.friendlyname, agent.updatedFriendlyName)">
<label for="Update Friendlyname" class="form-label">Current value: {{ $t(agent.friendlyname) }}</label>
<input id="updatedFriendlyName" v-model="agent.updatedFriendlyName" type="text" class="form-control" optional>
Copy link

@kayakyakr kayakyakr Jun 4, 2024

Choose a reason for hiding this comment

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

suggestion: similar to nathan's comments up above, if you are finding agents by their ID, you can just set agent.name here and use that to update the value. You also then don't have to show Current value: in the label, because the input will have the current value. You may want to show agent.url as part of the label, though, in case input name is blank.

Comment on lines 52 to 56
<template v-if="$root.agentStatusList[endpoint]">
<span v-if="endpoint === '' && agent.friendlyname === ''" class="badge bg-secondary me-2">Controller</span>
<span v-else-if="agent.friendlyname === ''" :href="agent.url">{{ endpoint }}</span>
<span v-else :href="agent.url">{{ agent.friendlyname }}</span>
</template>

Choose a reason for hiding this comment

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

Couple of suggestions here:

  1. We can use the fact that an empty string is falsy to shorten this chain.
  2. You probably don't want to be modifying things so drastically. If it's working, then a small change will do.
Suggested change
<template v-if="$root.agentStatusList[endpoint]">
<span v-if="endpoint === '' && agent.friendlyname === ''" class="badge bg-secondary me-2">Controller</span>
<span v-else-if="agent.friendlyname === ''" :href="agent.url">{{ endpoint }}</span>
<span v-else :href="agent.url">{{ agent.friendlyname }}</span>
</template>
<span v-if="endpoint === ''" class="badge bg-secondary me-2">{{ $t("currentEndpoint") }}</span>
<a v-else :href="agent.url" target="_blank">{{ agent.name || endpoint }}</a>

@mon5termatt
Copy link

would love for this to be added!

updating the merge request by adding the suggestions from reviewer
update agent.ts file by renaming the variables and added suggestion
@lohrbini
Copy link
Author

lohrbini commented Aug 6, 2024

Ready & happy about a second review :)

&& could need help with that one failing CI pipeline

updated variables in language file
@lohrbini lohrbini requested review from nathan815 and kayakyakr August 6, 2024 16:28
@lohrbini lohrbini requested review from louislam and larswmh August 14, 2024 09:19
Comment on lines 53 to 55
<span v-if="endpoint === '' && agent.name === ''" class="badge bg-secondary me-2">Controller</span>
<span v-else-if="agent.name === ''" :href="agent.url">{{ endpoint }}</span>
<span v-else :href="agent.url">{{ agent.name }}</span>
Copy link

@larswmh larswmh Aug 14, 2024

Choose a reason for hiding this comment

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

Suggested change
<span v-if="endpoint === '' && agent.name === ''" class="badge bg-secondary me-2">Controller</span>
<span v-else-if="agent.name === ''" :href="agent.url">{{ endpoint }}</span>
<span v-else :href="agent.url">{{ agent.name }}</span>
<span v-if="endpoint === '' && agent.name === ''" class="badge bg-secondary me-2">Controller</span>
<span v-else-if="agent.name === ''" :href="agent.url" class="me-2">{{ endpoint }}</span>
<span v-else :href="agent.url" class="me-2">{{ agent.name }}</span>

Add spacing from controller badge to edit icon for agent url and agent name display.

Before:
image
After:
image

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback. Updated in latest commit

@@ -76,12 +76,15 @@ export class AgentManager {
* @param url
* @param username
* @param password
* @param name
* @param updatedName
Copy link

@larswmh larswmh Aug 14, 2024

Choose a reason for hiding this comment

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

Suggested change
* @param updatedName

Parameter updatedName is not used in this function, can be removed

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the feedback. Updated in latest commit

@XenoUniv3rse
Copy link

on which tag do i need to be to have this feature?

@lohrbini
Copy link
Author

on which tag do i need to be to have this feature?

It is planned to be included in the next release v1.5.0 . To use this feature you need to be on my branch and build the image on your own

implement suggestions from review
@lohrbini lohrbini requested a review from larswmh August 20, 2024 13:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants