mirror of
https://github.com/directus/directus.git
synced 2026-02-14 09:25:17 -05:00
Add support for Conditional Fields (#6864)
* Add conditions field to directus_fields * Add conditions configuration * Apply conditional overrides * Handle conditions in nested groups * Fix reverse mutating conditions * Start on filter setup interface * Move field types/constants to shared * [WIP] Updated client side filter validation * Support logical operators in client validation step * Use new validation util in conditions check * Add nesting in filter seutp * Add filter rule setup configurator * Fixes that should've been done in the merge * Strip out filter-settings interface TBD in a new PR * Move browser to index
This commit is contained in:
@@ -10,14 +10,8 @@ import logger from '../logger';
|
||||
import { FieldsService, RawField } from '../services/fields';
|
||||
import { ItemsService, MutationOptions } from '../services/items';
|
||||
import Keyv from 'keyv';
|
||||
import {
|
||||
AbstractServiceOptions,
|
||||
Accountability,
|
||||
Collection,
|
||||
CollectionMeta,
|
||||
FieldMeta,
|
||||
SchemaOverview,
|
||||
} from '../types';
|
||||
import { AbstractServiceOptions, Accountability, Collection, CollectionMeta, SchemaOverview } from '../types';
|
||||
import { FieldMeta } from '@directus/shared/types';
|
||||
|
||||
export type RawCollection = {
|
||||
collection: string;
|
||||
|
||||
@@ -11,8 +11,8 @@ import { ForbiddenException, InvalidPayloadException } from '../exceptions';
|
||||
import { translateDatabaseError } from '../exceptions/database/translate';
|
||||
import { ItemsService } from '../services/items';
|
||||
import { PayloadService } from '../services/payload';
|
||||
import { AbstractServiceOptions, Accountability, FieldMeta, SchemaOverview, types } from '../types';
|
||||
import { Field } from '../types/field';
|
||||
import { AbstractServiceOptions, Accountability, SchemaOverview } from '../types';
|
||||
import { Field, FieldMeta, Type } from '@directus/shared/types';
|
||||
import getDefaultValue from '../utils/get-default-value';
|
||||
import getLocalType from '../utils/get-local-type';
|
||||
import { toArray } from '../utils/to-array';
|
||||
@@ -21,7 +21,7 @@ import { RelationsService } from './relations';
|
||||
import Keyv from 'keyv';
|
||||
import { DeepPartial } from '@directus/shared/types';
|
||||
|
||||
export type RawField = DeepPartial<Field> & { field: string; type: typeof types[number] };
|
||||
export type RawField = DeepPartial<Field> & { field: string; type: Type };
|
||||
|
||||
export class FieldsService {
|
||||
knex: Knex;
|
||||
@@ -214,7 +214,7 @@ export class FieldsService {
|
||||
|
||||
async createField(
|
||||
collection: string,
|
||||
field: Partial<Field> & { field: string; type: typeof types[number] | null },
|
||||
field: Partial<Field> & { field: string; type: Type | null },
|
||||
table?: Knex.CreateTableBuilder // allows collection creation to
|
||||
): Promise<void> {
|
||||
if (this.accountability && this.accountability.admin !== true) {
|
||||
@@ -435,6 +435,9 @@ export class FieldsService {
|
||||
public addColumnToTable(table: Knex.CreateTableBuilder, field: RawField | Field, alter: Column | null = null): void {
|
||||
let column: Knex.ColumnBuilder;
|
||||
|
||||
// Don't attempt to add a DB column for alias / corrupt fields
|
||||
if (field.type === 'alias' || field.type === 'unknown') return;
|
||||
|
||||
if (field.schema?.has_auto_increment) {
|
||||
column = table.increments(field.field);
|
||||
} else if (field.type === 'string') {
|
||||
|
||||
@@ -7,16 +7,8 @@ import { OpenAPIObject, OperationObject, PathItemObject, SchemaObject, TagObject
|
||||
import { version } from '../../package.json';
|
||||
import getDatabase from '../database';
|
||||
import env from '../env';
|
||||
import {
|
||||
AbstractServiceOptions,
|
||||
Accountability,
|
||||
Collection,
|
||||
Field,
|
||||
Permission,
|
||||
Relation,
|
||||
SchemaOverview,
|
||||
types,
|
||||
} from '../types';
|
||||
import { AbstractServiceOptions, Accountability, Collection, Permission, Relation, SchemaOverview } from '../types';
|
||||
import { Field, Type } from '@directus/shared/types';
|
||||
import { getRelationType } from '../utils/get-relation-type';
|
||||
import { CollectionsService } from './collections';
|
||||
import { FieldsService } from './fields';
|
||||
@@ -459,20 +451,33 @@ class OASSpecsService implements SpecificationSubService {
|
||||
}
|
||||
|
||||
private fieldTypes: Record<
|
||||
typeof types[number],
|
||||
Type,
|
||||
{
|
||||
type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'integer' | 'null' | undefined;
|
||||
format?: string;
|
||||
items?: any;
|
||||
}
|
||||
> = {
|
||||
alias: {
|
||||
type: 'string',
|
||||
},
|
||||
bigInteger: {
|
||||
type: 'integer',
|
||||
format: 'int64',
|
||||
},
|
||||
binary: {
|
||||
type: 'string',
|
||||
format: 'binary',
|
||||
},
|
||||
boolean: {
|
||||
type: 'boolean',
|
||||
},
|
||||
csv: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
date: {
|
||||
type: 'string',
|
||||
format: 'date',
|
||||
@@ -488,6 +493,9 @@ class OASSpecsService implements SpecificationSubService {
|
||||
type: 'number',
|
||||
format: 'float',
|
||||
},
|
||||
hash: {
|
||||
type: 'string',
|
||||
},
|
||||
integer: {
|
||||
type: 'integer',
|
||||
},
|
||||
@@ -511,23 +519,13 @@ class OASSpecsService implements SpecificationSubService {
|
||||
type: 'string',
|
||||
format: 'timestamp',
|
||||
},
|
||||
binary: {
|
||||
type: 'string',
|
||||
format: 'binary',
|
||||
unknown: {
|
||||
type: undefined,
|
||||
},
|
||||
uuid: {
|
||||
type: 'string',
|
||||
format: 'uuid',
|
||||
},
|
||||
csv: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
hash: {
|
||||
type: 'string',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user