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

🔦 Feature: Allow to set global default for interpreting LongText columns as Markdown ("rich text") #7832

Closed
1 task done
salim-b opened this issue Mar 10, 2024 · 6 comments

Comments

@salim-b
Copy link
Contributor

salim-b commented Mar 10, 2024

Please confirm if feature request does NOT exist already ?

  • I confirm there is no existing issue for this

Describe the usecase for the feature

I really like NocoDB allowing to interpret LongText columns as Markdown aka "rich text". But it's tedious to enable it for every single text column in a database when you want to use the feature by default.

Suggested Solution

It would be great if users could set a default for the Enable Rich Text column toggle globally per base.

@dstala
Copy link
Member

dstala commented Mar 12, 2024

@salim-b are you creating schema from the scratch? if so, it's a quite easily accessible option on the menu when creating a long text field. Are you connecting to existing DB and converting long text to rich text something?

@salim-b
Copy link
Contributor Author

salim-b commented Mar 12, 2024

@dstala I'm connecting to an existing PostgreSQL DB with multiple tables. The columns I'd like NocoDB to interpret as Markdown are of type text (variable unlimited length). Currently, I have to switch the Enable Rich Text toggle for every single one of these columns (because the toggle is disabled by default). Instead, I would like to change the toggle's default globally per base.

@dstala
Copy link
Member

dstala commented Mar 14, 2024

Discussed with the team - we do not have any plans as of now to make it as a configurable aspect;
One thing that we can try out is, prepare a script that - given a base, converts all long text fields to rich text.

@salim-b
Copy link
Contributor Author

salim-b commented Mar 14, 2024

Discussed with the team - we do not have any plans as of now to make it as a configurable aspect;

Ok, I understand. Thanks für the update.

One thing that we can try out is, prepare a script that - given a base, converts all long text fields to rich text.

How would that work exactly? Such a script would need to change NocoDB's internal metadata DB, right?

@dstala
Copy link
Member

dstala commented Mar 14, 2024

You can refer to our API documentation at https://meta-apis-v2.nocodb.com/
Below script, give a table ID - should help you convert all long text fields into rich text

let axios = require("axios").default;
let baseUrl = 'http://localhost:9000'
let authToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InVzZXJAbm9jb2RiLmNvbSIsImlkIjoidXNtM3IwbDI1OXh1cWpyZiIsInJvbGVzIjoib3JnLWxldmVsLWNyZWF0b3Isc3VwZXIiLCJ0b2tlbl92ZXJzaW9uIjoiZTU0OThjYWY3YzkzYjk2ZTc1MjhiZWNmODhkNTA2YzNiMjY1N2M0NjFjMTE1NzI0MzMzMTIzZjMzMzk0MmQ2NTI5NzU1ZWQ2MTIzMTdkNDMiLCJpYXQiOjE3MTA0MTEzMDAsImV4cCI6MTcxMDQ0NzMwMH0.akMkQm5Y3RzZYDfKcdy7X89Eygr5grRvcsBVC9EDoqY';

// table id can be retrieved from the URL when viewing the table in the browser
// example: http://localhost:9000/dashboard/#/nc/pekjheec4mwp7g5/mk61da5vmtj3qi3
let tableId = 'mk61da5vmtj3qi3'

async function nc_axios(options, token, data, cookie) {
    if(token) {
        options.headers = {'xc-auth': token}
    }

    if(data) {
        options.data = data;
    }

    if(cookie) {
        options.headers = {'xc-auth': token, 'withCredentials': true}
    }

    try {
        let response = await axios.request(options);
        return response.data;
    } catch (error) {
        console.error(error);
        return error;
    }
}

(async () => {
    // retrieve table fields
    let tableRead = {
        method: 'GET',
        url: `${baseUrl}/api/v2/meta/tables/${tableId}`,
        headers: {
            'xc-auth': authToken
        }
    }
    let table = await nc_axios(tableRead, authToken);
    
    // filter for fields that are long text
    let fields = table.columns.filter(c => c.uidt === 'LongText');

    // for each long text field, trigger update to convert to rich text field
    for(let i = 0; i < fields.length; i++) {
        let field = fields[i];

        let updateField = {
            method: 'PATCH',
            url: `${baseUrl}/api/v2/meta/columns/${field.id}`,
            headers: {
                'xc-auth': authToken
            },
            data: {
                ...field,
                meta: { richMode: true }
            }
        }

        await nc_axios(updateField, authToken);
    }
})().catch(err => {
    console.log(err);
});

@dstala dstala closed this as not planned Won't fix, can't repro, duplicate, stale Mar 14, 2024
@salim-b
Copy link
Contributor Author

salim-b commented Mar 17, 2024

You can refer to our API documentation at https://meta-apis-v2.nocodb.com/
Below script, give a table ID - should help you convert all long text fields into rich text

Hey @dstala, I tried to enable rich-text mode via the API as you suggested. (I'm using R, not JS, but it shouldn't matter).

The Update Column API endpoint is quite peculiar. Although it's a PATCH endpoint, the two fields column_name and title are mandatory in the request body. I only want to alter the meta field:

  • When I only supply {"meta":{"richMode":true}} in the request body, the API returns with HTTP 400 Bad Request and

    {"msg":"Cannot read properties of undefined (reading 'replace')"}
  • When I supply {"column_name":"MY_COLUMN_NAME","meta":{"richMode":true}} in the request body, the API returns with HTTP 400 Bad Request and

    {"msg":"Undefined binding(s) detected when compiling FIRST. Undefined column(s): [title] query: select * from `nc_columns_v2` where not `id` = ? and `title` = ? and `fk_model_id` = ? limit ?"}
  • When I supply {"column_name":"MY_COLUMN_NAME","title":"MY_TITLE","meta":{"richMode":true}}1, the API returns with HTTP 400 Bad Request and

    {"msg":"\nALTER TABLE \"referendums\" ALTER COLUMN \"level\" TYPE character varying USING \"level\"::character varying;\n\nALTER TABLE \"referendums\" ALTER COLUMN \"level\"  DROP NOT NULL;\n; - must be owner of table referendums"}

    indicating that NocoDB is trying to alter the column in the actual DB table (external Postgres) and not just its internal metadata. This is kinda scary.

When I change the table owner in Postgres to the user I connect NocoDB with, the last request above runs fine but actually alters my DB table, changing its data type and dropping the NOT NULL constraint, which I obviously don't want.

Is there a way to set "richMode":true via NocoDB's API without altering the external data source?

Footnotes

  1. Whereas MY_COLUMN_NAME and MY_TITLE are the original/unaltered column name and title as returned by a GET request.

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

No branches or pull requests

2 participants