diff --git a/vue-project/my-kintone-plugin/src/js/conditions.ts b/vue-project/my-kintone-plugin/src/js/conditions.ts index 1bf9302..4c28f29 100644 --- a/vue-project/my-kintone-plugin/src/js/conditions.ts +++ b/vue-project/my-kintone-plugin/src/js/conditions.ts @@ -1,24 +1,33 @@ import type { FieldsInfo } from '@/types/model'; -import type { FieldType } from './kintone-rest-api-client'; +import { isType, type FieldType, type OneOf } from './kintone-rest-api-client'; 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 = '' | 'eq' | 'ne' | 'test'; +export type ConditionValue = '' | 'eq' | 'ne' | 'le' | 'lt' | 'gt' | 'ge' | 'contains' | 'not_contain'; type ConditionItem = { value: ConditionValue; - label: string; - type: ComponentType; + label: string | ((field: OneOf) => string); + type: ComponentType; // | ((field: OneOf) => ComponentType); }; export const conditionList: ConditionItem[] = [ { value: 'eq', label: '=(等しい)', type: 'input' }, { value: 'ne', label: '≠ (等しくない)', type: 'input' }, - { value: 'test', label: 'test combobox', type: 'select' }, + { value: 'le', label: (field) => isDateTimeType(field) ? '≦ (以前)' : '≦ (以下)', type: 'input' }, + { value: 'lt', label: '< (より前)', type: 'input' }, + { value: 'gt', label: '> (より後)', type: 'input' }, + { value: 'ge', label: (field) => isDateTimeType(field) ? '≧ (以降)' : '≧ (以上)', type: 'input' }, + { value: 'contains', label: '次のいずれかを含む', type: 'input' }, + { value: 'not_contain', label: '次のいずれも含まない', type: 'input' }, ]; +export const isDateTimeType = (field: OneOf) => { + return isType.DATETIME(field) || isType.TIME(field) || isType.DATE(field) || isType.CREATED_TIME(field) || isType.UPDATED_TIME(field); +} + // search from conditionList // conditionItem = conditionMap[conditionValue] export const conditionMap: Record = conditionList.reduce( @@ -31,10 +40,35 @@ export const conditionMap: Record = conditionList type FieldConditions = Partial>; +const textCondition: ConditionValue[] = ['eq', 'ne', 'contains', 'not_contain']; +const numberCondition: ConditionValue[] = ['eq', 'ne', 'le', 'ge']; +const timeCondition: ConditionValue[] = [...numberCondition, 'lt', 'gt']; +const containsCondition: ConditionValue[] = ['contains', 'not_contain']; + // FieldType -> ConditionValue[] const fieldConditions: FieldConditions = { - SINGLE_LINE_TEXT: ['eq', 'ne'], - NUMBER: ['ne', 'test'], + SINGLE_LINE_TEXT: textCondition, + MULTI_LINE_TEXT: containsCondition, + RICH_TEXT: containsCondition, + NUMBER: numberCondition, + CHECK_BOX: containsCondition, + RADIO_BUTTON: containsCondition, + DROP_DOWN: containsCondition, + MULTI_SELECT: containsCondition, + USER_SELECT: containsCondition, + ORGANIZATION_SELECT: containsCondition, + GROUP_SELECT: containsCondition, + LINK: textCondition, + CALC: numberCondition, + + TIME: timeCondition, + DATE: timeCondition, + DATETIME: timeCondition, + CREATED_TIME: timeCondition, + CREATOR: containsCondition, + UPDATED_TIME: timeCondition, + MODIFIER: containsCondition, + RECORD_NUMBER: numberCondition, } as const; // fieldCode -> conditionList: ConditionItem[] @@ -42,15 +76,30 @@ export const getAvailableCondition = (fieldCode: string, fieldsInfo: FieldsInfo, if (!fieldCode || !fieldsInfo.fields) return; const fieldObj = getFieldObj(fieldCode, fieldsInfo, ''); if (!fieldObj) return; - const conditions = fieldConditions[fieldObj.type] || ['eq']; // TODO a mock here - return conditions.map((condition) => conditionMap[condition]); + const conditions = fieldConditions[fieldObj.type] || textCondition; // TODO a fallback here + return conditions.map((condition) => { + const res = {...conditionMap[condition]} + res.label = typeof res.label === 'function' ? res.label(fieldObj) : res.label; + return res; + }); }; const component = { - '': undefined, input: 'kuc-text', select: 'kuc-combobox', + time: 'time', + date: 'date', + datetime: 'datetime', }; + +const dateTimeComponent: Partial> = { + TIME: 'time', + DATE: 'date', + DATETIME: 'datetime', + CREATED_TIME: 'datetime', + UPDATED_TIME: 'datetime', +} + export type ComponentType = keyof typeof component; export const getComponent = (value: ConditionValue) => { if (!value) return;