fix join UI

This commit is contained in:
2025-01-24 23:17:12 +08:00
parent ba897b00b9
commit ccbcbf5259
10 changed files with 198 additions and 57 deletions

View File

@@ -0,0 +1,58 @@
import { isType, type FieldType, type OneOf } from './kintone-rest-api-client';
type CalcType = 'NUMBER' | 'NUMBER_DIGIT' | 'DATETIME' | 'DATE' | 'TIME' | 'HOUR_MINUTE' | 'DAY_HOUR_MINUTE';
export type LeftCalcJoinType = Record<CalcType, FieldType[]>;
export function isForceDisable(field: OneOf) {
if (isType.CALC(field)) {
return field.format === 'DAY_HOUR_MINUTE' || field.format === 'HOUR_MINUTE';
}
return false;
}
const calcJoinType = {
NUMBER: ['SINGLE_LINE_TEXT', 'NUMBER'],
NUMBER_DIGIT: ['SINGLE_LINE_TEXT', 'NUMBER'],
DATE: ['DATE'],
TIME: ['TIME'],
DATETIME: ['DATETIME'],
HOUR_MINUTE: [],
DAY_HOUR_MINUTE: [],
} as LeftCalcJoinType;
const availableLeftJoinType = {
SINGLE_LINE_TEXT: ['SINGLE_LINE_TEXT'],
NUMBER: ['NUMBER'],
CALC: calcJoinType,
DATE: ['DATE'],
TIME: ['TIME'],
DATETIME: ['DATETIME'],
LINK: ['LINK'],
} as Record<FieldType, FieldType[] | LeftCalcJoinType>;
// undefined means all
export function getRightAvailableJoinType(left?: OneOf | '') {
if (left === undefined) {
return Object.keys(availableRightJoinType) as FieldType[];
}
return left ? availableLeftJoinType[left.type] : [];
}
export type RightCalcJoinType = { type: 'CALC'; format: CalcType[] };
const availableRightJoinType = {
SINGLE_LINE_TEXT: ['SINGLE_LINE_TEXT', { type: 'CALC', format: ['NUMBER', 'NUMBER_DIGIT'] }],
NUMBER: ['NUMBER', { type: 'CALC', format: ['NUMBER', 'NUMBER_DIGIT'] }],
DATE: ['DATE', { type: 'CALC', format: ['DATE'] }],
TIME: ['TIME', { type: 'CALC', format: ['TIME'] }],
DATETIME: ['DATETIME', { type: 'CALC', format: ['DATETIME'] }],
LINK: ['LINK'],
} as Record<FieldType, Array<FieldType | RightCalcJoinType>>;
// undefined means all
export function getLeftAvailableJoinType(right?: OneOf | '') {
if (right === undefined) {
return Object.keys(availableLeftJoinType) as FieldType[];
}
return right ? availableRightJoinType[right.type] : [];
}