Add functions support to the app + add count function (#12488)

* Rename date functions to fn, add json_array_length for pg

* Add json count to mssql

* Add json array count support to other vendors

* Add UI for selecting API functions

* Make it not break

* Render functions in filter preview better

* Include functions in field altering

* Add schema access to database helper

* Allow filtering against o2m/m2m/m2a count

* Add data function execution helpers in utils

* Fix type issue

* Inject function results in validate step

* Render field keys with function names translated

* Allow selecting nested/functions in field validation step

* Make sure number comparisons are treated as numbers

* Add check if instanceof date when casting to a Number

* Prevent selecting foreign keys for junction sort (#12463)

* [SDK] Add further request options to `items` functions (#12503)

* add possibility to set further options to the request

* fix options type

* add typings to interface

* add test if headers are passed thourght

* create reusable options param

* set higher priority to options param

* Small stylistic cleanup

Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
Co-authored-by: ian <licitdev@gmail.com>
Co-authored-by: Jürg Hunziker <juerg.hunziker@gmail.com>
This commit is contained in:
Rijk van Zanten
2022-03-31 16:56:26 -04:00
committed by GitHub
parent abcbc7ffcb
commit 90f5b0a471
40 changed files with 876 additions and 342 deletions

View File

@@ -0,0 +1,13 @@
import { REGEX_BETWEEN_PARENS } from '@directus/shared/constants';
import { FieldFunction } from '@directus/shared/types';
export function extractFieldFromFunction(fieldKey: string): { fn: FieldFunction | null; field: string } {
let functionName;
if (fieldKey.includes('(') && fieldKey.includes(')')) {
functionName = fieldKey.split('(')[0] as FieldFunction | undefined;
fieldKey = fieldKey.match(REGEX_BETWEEN_PARENS)![1];
}
return { fn: functionName ?? null, field: fieldKey };
}

View File

@@ -0,0 +1,17 @@
import { useFieldsStore } from '@/stores';
import { useI18n } from 'vue-i18n';
import { extractFieldFromFunction } from '@/utils/extract-field-from-function';
export function formatFieldFunction(collection: string, fieldKey: string) {
const { t } = useI18n();
const { field, fn } = extractFieldFromFunction(fieldKey);
const fieldName = useFieldsStore().getField(collection, field)?.name ?? field;
if (fn) {
return t(`functions.${fn}`) + ` (${fieldName})`;
}
return fieldName;
}