57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import { INDICATOR_REGISTRY } from './indicatorRegistry';
|
|
import { getOrderedMainIndicatorTypes } from './indicatorMainTabOrder';
|
|
import type { IndicatorCustomTab } from './indicatorCustomTabsStorage';
|
|
|
|
export type IndicatorTabApplySource =
|
|
| { kind: 'main' }
|
|
| { kind: 'custom'; tab: IndicatorCustomTab };
|
|
|
|
export function resolveIndicatorTabApplyTypes(source: IndicatorTabApplySource): string[] {
|
|
if (source.kind === 'main') {
|
|
return getOrderedMainIndicatorTypes().filter(
|
|
type => INDICATOR_REGISTRY.some(d => d.type === type),
|
|
);
|
|
}
|
|
return source.tab.indicatorTypes.filter(
|
|
type => INDICATOR_REGISTRY.some(d => d.type === type),
|
|
);
|
|
}
|
|
|
|
export function resolveIndicatorTabApplyLabel(source: IndicatorTabApplySource): string {
|
|
if (source.kind === 'main') return '주요지표';
|
|
return source.tab.name;
|
|
}
|
|
|
|
/** 지표 탭 전체 적용 — 기존 보조지표 제거 후 탭 지표만 추가 (확인 없음) */
|
|
export function applyIndicatorTab(
|
|
source: IndicatorTabApplySource,
|
|
onAddMany: ((types: string[]) => void) | undefined,
|
|
onAdd?: (type: string) => void,
|
|
): boolean {
|
|
const validTypes = resolveIndicatorTabApplyTypes(source);
|
|
if (validTypes.length === 0) return false;
|
|
if (onAddMany) {
|
|
onAddMany(validTypes);
|
|
} else {
|
|
validTypes.forEach(type => onAdd?.(type));
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/** 지표 탭 전체 적용 — 확인 후 적용 (지표 추가 팝업용) */
|
|
export function confirmAndApplyIndicatorTab(
|
|
source: IndicatorTabApplySource,
|
|
onAddMany: ((types: string[]) => void) | undefined,
|
|
onAdd?: (type: string) => void,
|
|
): void {
|
|
const validTypes = resolveIndicatorTabApplyTypes(source);
|
|
if (validTypes.length === 0) {
|
|
window.alert('추가할 지표가 없습니다.');
|
|
return;
|
|
}
|
|
const label = resolveIndicatorTabApplyLabel(source);
|
|
const msg = `기존 보조지표를 모두 제거하고 ${label} 탭의 지표 ${validTypes.length}개로 교체하시겠습니까?`;
|
|
if (!window.confirm(msg)) return;
|
|
applyIndicatorTab(source, onAddMany, onAdd);
|
|
}
|