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 11 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

@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);

* @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.

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?

@lohrbini
Copy link
Author

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

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.

None yet

5 participants