Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

72
Vistas
Pass function to React to execute from metadata

There is a table that needs to be filled with data from the server. The front is react, the back is java.
The relationship between field name and column in the table is described in the metadata file. Example:

JSON from server:

[
  {
    "id": 1,
    "userName": "administrator",
    "lastName": "Joe",
    "firstName": "Admino",
    "middleName": "",
    "role": "admin"
  },
  ...
]

Metadata:

"fields": [
      {
        "key": "userName",
        "label": "Username",
        "type": "STRING"
      },
      {
        "key": "role",
        "label": "Role",
        "type": "STRING"
      },
...
]

The current list of field types ("type": "STRING") in my application is limited to primitive types. The problem is that for my table, when formatting data for output to the table, I need to use some logic, i.e. functions. For example, one of the fields is formed as follows: return id + userName + (isExpired ? 'Active Directory' : '') + lastName + firstName + middleName

Yes, it's more convenient to return the formatted data from the server right away, but I can't change it.

My solution is to create a new type of field for the metadata (something like FUNCTION) which would allow me to describe a function in the metadata which would then be executed in the react. But I think it would be better to describe the function in react, and call it via metadata by name, something like:

{
    "key": "funcName, arg1, arg2, ...",
    "label": "FullName",
    "type": "FUNCTION"
}

Can you tell me how this can be implemented and is this a good approach?

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos