fix bug
This commit is contained in:
@@ -5,35 +5,35 @@ import { getFieldObj } from './helper';
|
||||
// conditionValue = '' | 'eq' | 'ne'
|
||||
// conditionItem = { value: 'eq', label: '=(等しい)', type: 'input', func: (a: string, b: string) => a === b }
|
||||
// = conditionMap[conditionValue]
|
||||
export type ConditionValue = ""| "="
|
||||
| "!="
|
||||
| ">="
|
||||
| "<="
|
||||
| "<"
|
||||
| ">"
|
||||
| "like"
|
||||
| "not like"
|
||||
| "in"
|
||||
| "not in";
|
||||
export type ConditionValue = '' | '=' | '!=' | '>=' | '<=' | '<' | '>' | 'like' | 'not like' | 'in' | 'not in';
|
||||
|
||||
type ConditionItem = {
|
||||
value: ConditionValue;
|
||||
label: string | ((field: OneOf) => string);
|
||||
type: ComponentType; // | ((field: OneOf) => ComponentType);
|
||||
type: ComponentType | ((field: OneOf) => ComponentType);
|
||||
};
|
||||
|
||||
export const conditionList: ConditionItem[] = [
|
||||
{ value: '=', label: '=(等しい)', type: 'input' },
|
||||
{ value: '!=', label: '≠ (等しくない)', type: 'input' },
|
||||
{ value: '<=', label: (field) => isDateTimeType(field) ? '≦ (以前)' : '≦ (以下)', type: 'input' },
|
||||
{ value: '=', label: '=(等しい)', type: (field) => dateTimeComponent[field.type] || 'input' },
|
||||
{ value: '!=', label: '≠ (等しくない)', type: (field) => dateTimeComponent[field.type] || 'input' },
|
||||
{
|
||||
value: '<=',
|
||||
label: (field) => (isDateTimeType(field) ? '≦ (以前)' : '≦ (以下)'),
|
||||
type: (field) => dateTimeComponent[field.type] || 'input',
|
||||
},
|
||||
{ value: '<', label: '< (より前)', type: 'input' },
|
||||
{
|
||||
value: '>=',
|
||||
label: (field) => (isDateTimeType(field) ? '≧ (以降)' : '≧ (以上)'),
|
||||
type: (field) => dateTimeComponent[field.type] || 'input',
|
||||
},
|
||||
{ value: '>', label: '> (より後)', type: 'input' },
|
||||
{ value: '>=', label: (field) => isDateTimeType(field) ? '≧ (以降)' : '≧ (以上)', type: 'input' },
|
||||
{ value: 'like', label: '次のキーワードを含む', type: 'input' },
|
||||
{ value: 'not like', label: '次のキーワードを含まない', type: 'input' },
|
||||
{ value: 'in', label: '次のいずれかを含む', type: 'input' },
|
||||
{ value: 'not in', label: '次のいずれも含まない', type: 'input' },
|
||||
];
|
||||
|
||||
// search from conditionList
|
||||
// conditionItem = conditionMap[conditionValue]
|
||||
export const conditionMap: Record<ConditionValue, ConditionItem> = conditionList.reduce(
|
||||
@@ -45,7 +45,7 @@ export const conditionMap: Record<ConditionValue, ConditionItem> = conditionList
|
||||
);
|
||||
|
||||
type FieldConditions = Partial<Record<FieldType, ConditionValue[]>>;
|
||||
const textCondition: ConditionValue[] = ['=', '!=', 'in', 'like','not like'];
|
||||
const textCondition: ConditionValue[] = ['=', '!=', 'in', 'like', 'not like'];
|
||||
const numberCondition: ConditionValue[] = ['=', '!=', '<=', '>='];
|
||||
const timeCondition: ConditionValue[] = ['=', '!=', '<=', '>=', '<', '>'];
|
||||
const containsCondition: ConditionValue[] = ['in', 'not in'];
|
||||
@@ -83,7 +83,7 @@ export const getAvailableCondition = (fieldCode: string, fieldsInfo: FieldsInfo,
|
||||
if (!fieldObj) return;
|
||||
const conditions = fieldConditions[fieldObj.type] || textCondition; // TODO a fallback here
|
||||
return conditions.map((condition) => {
|
||||
const res = {...conditionMap[condition]}
|
||||
const res = { ...conditionMap[condition] };
|
||||
res.label = typeof res.label === 'function' ? res.label(fieldObj) : res.label;
|
||||
return res;
|
||||
});
|
||||
@@ -99,19 +99,53 @@ const component = {
|
||||
|
||||
export const isDateTimeType = (field: OneOf) => {
|
||||
return field.type in dateTimeComponent;
|
||||
}
|
||||
};
|
||||
|
||||
const dateTimeComponent: Partial<Record<FieldType, ComponentType>> = {
|
||||
TIME: 'time',
|
||||
DATE: 'date',
|
||||
DATETIME: 'datetime',
|
||||
CREATED_TIME: 'datetime',
|
||||
UPDATED_TIME: 'datetime',
|
||||
}
|
||||
// DATE: 'date',
|
||||
// DATETIME: 'datetime',
|
||||
// CREATED_TIME: 'datetime',
|
||||
// UPDATED_TIME: 'datetime',
|
||||
};
|
||||
|
||||
export type ComponentType = keyof typeof component;
|
||||
export const getComponent = (value: ConditionValue, fieldObj: OneOf) => {
|
||||
if (!value) return;
|
||||
if (!value || !fieldObj) return;
|
||||
const condition = conditionMap[value].type;
|
||||
return component[typeof condition === 'function' ? condition(fieldObj) : condition];
|
||||
};
|
||||
|
||||
type DateFuncItem = {
|
||||
value: string;
|
||||
label: string | ((isTime: boolean) => string);
|
||||
condition?: 'datetime' | 'date';
|
||||
key: DateFuncKey;
|
||||
};
|
||||
|
||||
export type DateFuncKey = '' | 'FROM_TODAY' | 'NOW' | 'TODAY' | 'THIS_WEEK' | 'THIS_MONTH';
|
||||
|
||||
export const dateFuncList: DateFuncItem[] = [
|
||||
{ key: '', value: '%s', label: (isTime) => (isTime ? '日時を指定' : '日付を指定') },
|
||||
{ key: 'FROM_TODAY', value: 'FROM_TODAY(%s)', label: '今日から' },
|
||||
{ key: 'NOW', value: 'NOW()', label: '当時刻', condition: 'datetime' },
|
||||
{ key: 'TODAY', value: 'TODAY()', label: '今日' },
|
||||
{ key: 'THIS_WEEK', value: 'THIS_WEEK(%s)', label: '今週' },
|
||||
{ key: 'THIS_MONTH', value: 'THIS_MONTH(%s)', label: '今月' },
|
||||
];
|
||||
|
||||
// search from dateFuncList
|
||||
// DateFuncItem = dateFuncMap[DateFuncKey]
|
||||
export const dateFuncMap: Record<DateFuncKey, DateFuncItem> = dateFuncList.reduce(
|
||||
(map, item) => {
|
||||
map[item.key] = item;
|
||||
return map;
|
||||
},
|
||||
{} as Record<DateFuncKey, DateFuncItem>,
|
||||
);
|
||||
|
||||
export const getDateFuncList = (hasTime: boolean) => {
|
||||
return dateFuncList.filter((item) => {
|
||||
return item.condition ? item.condition === (hasTime ? 'datetime' : 'date') : true;
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user