44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import type { FormScreenField } from '../../../api/types';
|
|
|
|
export const isCategoryColumn = (colId: string, colName: string = '') => {
|
|
const idLower = colId.toLowerCase();
|
|
const nameLower = colName.toLowerCase();
|
|
return idLower.includes('category') || nameLower.includes('category');
|
|
};
|
|
|
|
export const isProductColumn = (colId: string, colName: string = '') => {
|
|
if (isCategoryColumn(colId, colName)) return false;
|
|
const idLower = colId.toLowerCase();
|
|
const nameLower = colName.toLowerCase();
|
|
return (
|
|
idLower.includes('product_name') ||
|
|
idLower === 'product' ||
|
|
idLower === 'name' ||
|
|
nameLower.includes('product name') ||
|
|
nameLower === 'product' ||
|
|
(nameLower.includes('product') && !nameLower.includes('category'))
|
|
);
|
|
};
|
|
|
|
export const findColumn = (columns: FormScreenField[], ...aliases: string[]) => {
|
|
const getBaseId = (id: string) => id.replace(/_\d+$/, '');
|
|
return columns.find((c) => {
|
|
const idLower = c.id.toLowerCase();
|
|
const nameLower = (c.name || '').toLowerCase();
|
|
const mappedLower = (c.mapped_workflow_field || '').toLowerCase();
|
|
const baseIdLower = getBaseId(c.id).toLowerCase();
|
|
|
|
return aliases.some((alias) => {
|
|
const a = alias.toLowerCase();
|
|
return (
|
|
idLower === a ||
|
|
nameLower === a ||
|
|
mappedLower === a ||
|
|
baseIdLower === a ||
|
|
idLower.includes(a) ||
|
|
nameLower.includes(a)
|
|
);
|
|
});
|
|
});
|
|
};
|