Improve preview of relational columns in tabular layout (#15269)

* improve preview of relational tabular columns

* update pnpm-lock

* Use the improved get method (#15548)

* Update app/src/layouts/tabular/index.ts

---------

Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
Nitwel
2023-02-24 15:01:57 +01:00
committed by GitHub
parent da9c3fed3c
commit 21bb26988e
4 changed files with 88 additions and 2 deletions

View File

@@ -16,3 +16,8 @@ test('Returns values in array path as flattened array', () => {
const input = { test: [{ path: 'example' }, { path: 'another' }] };
expect(get(input, 'test.path')).toEqual(['example', 'another']);
});
test('Returns values in array path as flattened array', () => {
const input = { test: [{ path: 'example' }, { falsePath: 'another' }] };
expect(get(input, 'test:collection.path')).toEqual(['example']);
});

View File

@@ -9,9 +9,12 @@
* ```
*/
export function get(object: Record<string, any> | any[], path: string, defaultValue?: unknown): any {
const [key, ...follow] = path.split('.');
let key = path.split('.')[0]!;
const follow = path.split('.').slice(1);
const result = Array.isArray(object) ? object.map((entry) => entry?.[key!]) : object?.[key!];
if (key.includes(':')) key = key.split(':')[0]!;
const result = Array.isArray(object) ? object.map((entry) => entry?.[key]).filter((entry) => entry) : object?.[key];
if (follow.length > 0) {
return get(result, follow.join('.'), defaultValue);