Redirect directly to related data on table row click

Hi there,

We have a table with transactions. When a user clicks on a row, it redirects them to details view of that transaction. We also have a smart relation set up for that called ‘related data’.

The question is how to set up redirect to related data bypassing details view of the record when a user clicks table row.

// forest/transactions.js

const { collection } = require('forest-express-mongoose');

collection('transactions', {
  actions: [],
  fields: [
    {
      field: 'relatedDatapoints',
      type: ['String'],
      reference: 'transactions._id'
    },
  ],
}
// routes/transactions.js

router.get(
  '/transactions/:recordId/relationships/relatedDatapoints',
  (req, res, next)  => {
    // ...more code
  }
);

Thank you in advance. Any help is greatly appreciated!

Hello @Dmytro :wave:

If I understood correctly, you would like to redirect your users directly to the relatedDatapoints of a transaction, when then click on a transaction in the table view. Is this correct ?

If this is the case, I’m afraid this is not natively supported. However, If you really need this feature, we should be able to construct an url in a smart field where your users could click on to be directly redirected from table view to related data.

If you are interested on this type of workaround, I can provide you some code.

Steve.

2 Likes

Hello, @Steve_Bunlon,

Yes, that’s what I’m looking for. If you could provide some code, that will be much appreciated. Thank you!

Regards,

Dmytro

May I suggest a little trick here? Maybe configuring a Summary View with one section only that is the Related Data one could help? It would span over the whole available area for it.

Here’s a demo :point_down:t3:

Hi, @anon20071947,

Thank you for providing the video. However, we would like to proceed with the solution offered by @Steve_Bunlon

However, If you really need this feature, we should be able to construct an url in a smart field where your users could click on to be directly redirected from table view to related data.

This feels more intuitive and closer to what we’re trying to achieve. Could you please advise how this can be accomplished? Greatly appreciate your time.

Regards,

Dmytro

1 Like

Hello @Dmytro :wave:

I have a sample code that you can use to accomplish what you want. Please note the statements below first:
1 - This is a custom code I provide you, if you really want to commit to this solution, you will be the owner and you might need to adapt it over time
2 - Our current implementation of the link widget forces a new tab to be opened. So when your users would like to access related data directly, a new browser tab will be opened redirecting them to the related data.

Here are the steps to get this working:
1 - First, create the smart field that will contain the link. I’ve taken your transactions collection, and I’ve added the smart field as below:

// forest/transactions.js
..
fields: [{
    field: 'relatedData',
    type: 'String',
  },{
    field: 'relatedDatapoints',
    type: ['String'],
    reference: 'transactions._id'
  },
],
..

2 - Then, you need to compute and populate the smart field. We need to know the team of the current user to compute the URL, this is why we can’t use a simple smart field getter (which is not aware of the current user), we need to override the getAll transactions’ route (here we can get the current user’s team):

// routes/transactions
// Get a list of transactions
router.get('/transactions', permissionMiddlewareCreator.list(), (request, response, next) => {
  const params = request.query;
  const recordsGetter = new RecordsGetter(transactionsModel);

  recordsGetter.getAll(params)
      .then(records => {
        records.forEach((record) => {
          record.relatedData = `/[PROJECT_NAME]/[ENVIRONMENT_NAME]/${request.user.team}/data/transactions/index/record/transactions/${record._id}/has-many/transactions-relatedDatapoints`
        });

        return records;
      })
      .then(records => recordsGetter.serialize(records))
      .then(recordsSerialized => response.send(recordsSerialized))
      .catch(next);
});

3 - Update the relatedData smart field settings to make it use the widget display link

4 - get back to your table view, and you should see the smart field with a link in it, which should redirect to the related of the record :+1:

In this snippet, PROJECT_NAME is the name of the project this code will run for, ENVIRONMENT_NAME is the name of the environment (eg server) this code will run on. You can store this two variables as environment variables for example, and adapt them accross you environments.

I adapted this code to make it fit your collections’ name, so it should run directly after you pasted it :+1:

Tell me if it helps :raised_hands:

Steve.

2 Likes

Hi, @Steve_Bunlon,

Thank you kindly. Yes, this solution works. Greatly appreciate your help.

I needed to change transactions part in the url you provided to smth similar to 57804360-b6st-56ea-8660-87136620hf9g which I got from req.headers.referer.

Thanks again!

Regards,

Dmytro

1 Like