mirror of
https://github.com/directus/directus.git
synced 2026-02-08 11:54:58 -05:00
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:
@@ -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']);
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user