mirror of
https://github.com/directus/directus.git
synced 2026-01-24 09:18:06 -05:00
Move get-with-arrays to shared (#15332)
* Move get-with-arrays to shared, add fallback * Just fallback to undefineds, let the usage handle fallbacks
This commit is contained in:
@@ -185,7 +185,7 @@ import { useSync } from '@directus/shared/composables';
|
||||
import { Field, Filter, Item, ShowSelect } from '@directus/shared/types';
|
||||
import { ComponentPublicInstance, inject, ref, Ref, watch, computed } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { get } from '@/utils/get-with-arrays';
|
||||
import { get } from '@directus/shared/utils';
|
||||
import { useAliasFields, AliasField } from '@/composables/use-alias-fields';
|
||||
import { adjustFieldsForDisplays } from '@/utils/adjust-fields-for-displays';
|
||||
import { isEmpty, merge } from 'lodash';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useAliasFields } from '@/composables/use-alias-fields';
|
||||
import { getDisplay } from '@/displays';
|
||||
import { useFieldsStore } from '@/stores/fields';
|
||||
import { get } from '@/utils/get-with-arrays';
|
||||
import { get } from '@directus/shared/utils';
|
||||
import { DisplayConfig, Field, Item } from '@directus/shared/types';
|
||||
import { saveAs } from 'file-saver';
|
||||
import { parse } from 'json2csv';
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { test, expect } from 'vitest';
|
||||
|
||||
import { get } from '@/utils/get-with-arrays';
|
||||
import { get } from './get-with-arrays';
|
||||
|
||||
test('Returns static value from object', () => {
|
||||
const input = { test: { path: 'example' } };
|
||||
@@ -8,10 +8,10 @@
|
||||
* // => [1, 2]
|
||||
* ```
|
||||
*/
|
||||
export function get(object: Record<string, any> | any[], path: string, defaultValue?: any): any {
|
||||
export function get(object: Record<string, any> | any[], path: string, defaultValue?: unknown): any {
|
||||
const [key, ...follow] = path.split('.');
|
||||
|
||||
const result = Array.isArray(object) ? object.map((entry) => entry[key!]) : object?.[key!];
|
||||
const result = Array.isArray(object) ? object.map((entry) => entry?.[key!]) : object?.[key!];
|
||||
|
||||
if (follow.length > 0) {
|
||||
return get(result, follow.join('.'), defaultValue);
|
||||
@@ -15,6 +15,7 @@ export * from './get-functions-for-type';
|
||||
export * from './get-output-type-for-function';
|
||||
export * from './get-relation-type';
|
||||
export * from './get-simple-hash';
|
||||
export * from './get-with-arrays';
|
||||
export * from './is-dynamic-variable';
|
||||
export * from './merge-filters';
|
||||
export * from './move-in-array';
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { get, isObjectLike } from 'lodash';
|
||||
import { isObjectLike } from 'lodash';
|
||||
import { REGEX_BETWEEN_PARENS } from '../constants';
|
||||
import { Accountability, Filter, Role, User } from '../types';
|
||||
import { adjustDate } from './adjust-date';
|
||||
import { deepMap } from './deep-map';
|
||||
import { get } from './get-with-arrays';
|
||||
import { isDynamicVariable } from './is-dynamic-variable';
|
||||
import { toArray } from './to-array';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user