fix: make name required on field types (#337)
* fix: make name required on field types * fix: improve typescript types
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import React, { Suspense, lazy } from 'react';
|
||||
import Loading from '../../../elements/Loading';
|
||||
import { Props } from './types';
|
||||
|
||||
const Code = lazy(() => import('./Code'));
|
||||
|
||||
const CodeField: React.FC = (props) => (
|
||||
const CodeField: React.FC<Props> = (props) => (
|
||||
<Suspense fallback={<Loading />}>
|
||||
<Code {...props} />
|
||||
</Suspense>
|
||||
|
||||
@@ -8,7 +8,7 @@ const withCondition = <P extends Record<string, unknown>>(Field: React.Component
|
||||
admin: {
|
||||
condition,
|
||||
} = {},
|
||||
} = props as FieldBase;
|
||||
} = props as Partial<FieldBase>;
|
||||
|
||||
if (condition) {
|
||||
return <WithCondition {...props} />;
|
||||
@@ -24,7 +24,7 @@ const withCondition = <P extends Record<string, unknown>>(Field: React.Component
|
||||
admin: {
|
||||
condition,
|
||||
} = {},
|
||||
} = props as FieldBase & {
|
||||
} = props as Partial<FieldBase> & {
|
||||
path?: string
|
||||
};
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ describe('Cell Types', () => {
|
||||
describe('Select', () => {
|
||||
const fieldWithOptionsObject: SelectField = {
|
||||
type: 'select',
|
||||
name: 'selectObject',
|
||||
options: [{
|
||||
value: 'one',
|
||||
label: 'One',
|
||||
@@ -129,6 +130,7 @@ describe('Cell Types', () => {
|
||||
};
|
||||
const fieldWithStringsOptions: SelectField = {
|
||||
type: 'select',
|
||||
name: 'selectString',
|
||||
options: ['blue', 'green', 'yellow'],
|
||||
};
|
||||
it('renders options objects', () => {
|
||||
|
||||
@@ -35,7 +35,7 @@ export default function registerCollections(ctx: Payload): void {
|
||||
};
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
schema.methods.incLoginAttempts = function (this: mongoose.Document<any> & LoginSchema, cb) {
|
||||
schema.methods.incLoginAttempts = function (this: mongoose.Document & LoginSchema, cb) {
|
||||
// Expired lock, restart count at 1
|
||||
if (this.lockUntil && this.lockUntil < Date.now()) {
|
||||
return this.updateOne({
|
||||
@@ -49,7 +49,7 @@ export default function registerCollections(ctx: Payload): void {
|
||||
if (this.loginAttempts + 1 >= maxLoginAttempts && !this.isLocked) {
|
||||
updates.$set = { lockUntil: Date.now() + lockTime };
|
||||
}
|
||||
return this.updateOne(updates, cb);
|
||||
return this.updateOne(updates as mongoose.Document, cb);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line func-names
|
||||
|
||||
@@ -57,7 +57,7 @@ export type OptionObject = {
|
||||
export type Option = OptionObject | string
|
||||
|
||||
export interface FieldBase {
|
||||
name?: string;
|
||||
name: string;
|
||||
label?: string | false;
|
||||
required?: boolean;
|
||||
unique?: boolean;
|
||||
@@ -146,6 +146,7 @@ export type RowAdmin = Omit<Admin, 'description'> & {
|
||||
};
|
||||
|
||||
export type RowField = Omit<FieldBase, 'admin'> & {
|
||||
name?: string;
|
||||
admin?: RowAdmin;
|
||||
type: 'row';
|
||||
fields: Field[];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import express, { Express, Router } from 'express';
|
||||
import crypto from 'crypto';
|
||||
import { Document, Model } from 'mongoose';
|
||||
import { Document } from 'mongoose';
|
||||
import {
|
||||
SanitizedConfig,
|
||||
EmailOptions,
|
||||
@@ -36,13 +36,13 @@ import { encrypt, decrypt } from './auth/crypto';
|
||||
import { BuildEmailResult, Message } from './email/types';
|
||||
import { PayloadRequest } from './express/types';
|
||||
import sendEmail from './email/sendEmail';
|
||||
import { Preferences } from './preferences/types';
|
||||
|
||||
import { Options as CreateOptions } from './collections/operations/local/create';
|
||||
import { Options as FindOptions } from './collections/operations/local/find';
|
||||
import { Options as FindByIDOptions } from './collections/operations/local/findByID';
|
||||
import { Options as UpdateOptions } from './collections/operations/local/update';
|
||||
import { Options as DeleteOptions } from './collections/operations/local/delete';
|
||||
import { Preference } from './preferences/types';
|
||||
|
||||
require('isomorphic-fetch');
|
||||
|
||||
@@ -58,7 +58,7 @@ export class Payload {
|
||||
resolvers: GraphQLResolvers
|
||||
};
|
||||
|
||||
preferences: { Model: Model<Document<Preference>> };
|
||||
preferences: Preferences;
|
||||
|
||||
globals: Globals;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import mongoose, { Schema } from 'mongoose';
|
||||
import { Preference } from './types';
|
||||
|
||||
const Model = mongoose.model('_preferences', new Schema({
|
||||
const Model = mongoose.model<Preference>('_preferences', new Schema({
|
||||
user: {
|
||||
type: Schema.Types.ObjectId,
|
||||
refPath: 'userCollection',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Request } from 'express';
|
||||
import { Model } from 'mongoose';
|
||||
import { User } from '../auth';
|
||||
|
||||
export type Preference = {
|
||||
@@ -10,6 +11,10 @@ export type Preference = {
|
||||
updatedAt?: Date;
|
||||
};
|
||||
|
||||
export type Preferences = {
|
||||
Model: Model<Preference>
|
||||
}
|
||||
|
||||
export type PreferenceRequest = {
|
||||
overrideAccess?: boolean;
|
||||
req: Request;
|
||||
|
||||
Reference in New Issue
Block a user