fix. 컴포넌트 dataUtil 통일
This commit is contained in:
@@ -7,13 +7,9 @@ import type {
|
||||
PageDataValue,
|
||||
PageDataResourceContainer,
|
||||
PageDataTemplateComponents,
|
||||
PageDataTemplateComponentSet,
|
||||
PageDataResourceGroupType,
|
||||
} from '#layers/types/api/pageData'
|
||||
import type {
|
||||
OperateComponents,
|
||||
OperateGroupItem,
|
||||
} from '#layers/types/api/resourcesData'
|
||||
import type { OperateComponents } from '#layers/types/api/resourcesData'
|
||||
|
||||
/**
|
||||
* 페이지 데이터를 기반으로 레이아웃 타입을 결정합니다.
|
||||
@@ -64,24 +60,6 @@ export const isTypeButton = (type: PageDataResourceGroupType): boolean => {
|
||||
return type === 'BTN'
|
||||
}
|
||||
|
||||
/**
|
||||
* 컴포넌트 컨테이너를 반환합니다.
|
||||
* @param components props.components
|
||||
* @param componentName 컴포넌트 이름
|
||||
* @param options 옵션 (maxLength: 최대 길이)
|
||||
* @returns 컴포넌트 컨테이너
|
||||
*/
|
||||
export const getComponentContainer = (
|
||||
components: PageDataTemplateComponents | OperateComponents,
|
||||
componentName: string,
|
||||
{ maxLength }: { maxLength?: number } = {}
|
||||
) => {
|
||||
if (!components) return []
|
||||
|
||||
const container = components[componentName] || []
|
||||
return maxLength ? container.slice(0, maxLength) : container
|
||||
}
|
||||
|
||||
/**
|
||||
* 컴포넌트 그룹에 데이터가 존재하는지 확인합니다.
|
||||
* @param components props.components 또는 group 객체
|
||||
@@ -98,6 +76,45 @@ export const hasComponentGroup = (
|
||||
return component?.groups && component.groups.length > 0
|
||||
}
|
||||
|
||||
/**
|
||||
* 컴포넌트 컨테이너를 반환합니다.
|
||||
* @param components props.components
|
||||
* @param componentName 컴포넌트 이름
|
||||
* @param options 옵션
|
||||
* - hasGroup: groups 속성에서 데이터 가져오기 (기본값: false)
|
||||
* - maxLength: 최대 길이 제한
|
||||
* - minLength: 최소 길이 보장 (데이터 반복)
|
||||
* @returns 컴포넌트 컨테이너 배열
|
||||
*/
|
||||
export const getComponentContainer = (
|
||||
components: PageDataTemplateComponents | OperateComponents,
|
||||
componentName: string,
|
||||
options: { hasGroup?: boolean; maxLength?: number; minLength?: number } = {}
|
||||
) => {
|
||||
if (!components) return []
|
||||
|
||||
const { hasGroup = false, maxLength, minLength } = options
|
||||
|
||||
// 1. 초기 컨테이너 가져오기
|
||||
const component = components[componentName]
|
||||
if (!component) return []
|
||||
|
||||
let result = hasGroup && 'groups' in component ? component.groups : component
|
||||
|
||||
// 2. 최소 길이 보장 (데이터 복제)
|
||||
if (minLength && result.length > 1 && result.length < minLength) {
|
||||
const repeatTimes = Math.ceil(minLength / result.length)
|
||||
result = Array(repeatTimes).fill(result).flat()
|
||||
}
|
||||
|
||||
// 3. 최대 길이 제한
|
||||
if (maxLength && result.length > maxLength) {
|
||||
return result.slice(0, maxLength)
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* 컴포넌트 그룹의 첫 번째 데이터를 반환합니다.
|
||||
* @param components props.components 또는 group 객체
|
||||
@@ -128,52 +145,6 @@ export const getComponentGroupAry = (
|
||||
return components[componentName]?.groups || []
|
||||
}
|
||||
|
||||
/**
|
||||
* 슬라이드 데이터를 최소 개수로 보장합니다. (페이지 데이터용)
|
||||
* @param components 원본 데이터 배열 또는 객체
|
||||
* @param minCount 최소 보장할 개수 (기본값: 3)
|
||||
* @returns 최소 개수가 보장된 데이터 배열
|
||||
*/
|
||||
export const ensureMinimumSlideData = (
|
||||
components: PageDataTemplateComponents,
|
||||
minCount: number = 4
|
||||
): PageDataTemplateComponentSet[] => {
|
||||
if (!components) return []
|
||||
|
||||
const arrayData = Array.isArray(components.group_sets)
|
||||
? components.group_sets
|
||||
: []
|
||||
|
||||
// 빈 배열이거나 이미 최소 개수를 만족하면 그대로 반환
|
||||
if (arrayData.length <= 1 || arrayData.length >= minCount) {
|
||||
return arrayData
|
||||
}
|
||||
|
||||
// 최소 개수를 보장하기 위해 데이터 반복
|
||||
const repeatTimes = Math.ceil(minCount / arrayData.length)
|
||||
return Array(repeatTimes).fill(arrayData).flat()
|
||||
}
|
||||
|
||||
/**
|
||||
* 슬라이드 데이터를 최소 개수로 보장합니다. (운영 그룹용)
|
||||
* @param data 원본 데이터 배열
|
||||
* @param minCount 최소 보장할 개수 (기본값: 3)
|
||||
* @returns 최소 개수가 보장된 데이터 배열
|
||||
*/
|
||||
export const ensureMinimumSlideOperateData = (
|
||||
data: OperateGroupItem[],
|
||||
minCount: number = 4
|
||||
): OperateGroupItem[] => {
|
||||
// 빈 배열이거나 이미 최소 개수를 만족하면 그대로 반환
|
||||
if (data.length <= 1 || data.length >= minCount) {
|
||||
return data
|
||||
}
|
||||
|
||||
// 최소 개수를 보장하기 위해 데이터 반복
|
||||
const repeatTimes = Math.ceil(minCount / data.length)
|
||||
return Array(repeatTimes).fill(data).flat()
|
||||
}
|
||||
|
||||
/**
|
||||
* 현재 시간의 타임스탬프를 반환합니다.
|
||||
* @param unit 단위 ('ms' | 's') - 밀리초 또는 초
|
||||
|
||||
Reference in New Issue
Block a user