mirror of https://github.com/buster-so/buster.git
category an x axis cannot conflict
This commit is contained in:
parent
8d02bc7594
commit
17b11d452b
|
@ -73,7 +73,7 @@ const EmptyDropZone: React.FC<{
|
||||||
'rounded transition-all duration-100 ease-in-out',
|
'rounded transition-all duration-100 ease-in-out',
|
||||||
className ? className : 'border-border border border-dashed bg-transparent'
|
className ? className : 'border-border border border-dashed bg-transparent'
|
||||||
)}>
|
)}>
|
||||||
<span className="text-text-tertiary text-sm select-none">Drag column here</span>
|
<span className="text-sm select-none">Drag column here</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -129,8 +129,9 @@ export const useDropzonesInternal = ({
|
||||||
|
|
||||||
const targetZone = findZoneById(targetZoneId as string);
|
const targetZone = findZoneById(targetZoneId as string);
|
||||||
const sourceZoneId = findZoneContainingItem(active);
|
const sourceZoneId = findZoneContainingItem(active);
|
||||||
|
const sourceZone = findZoneById(sourceZoneId as string);
|
||||||
|
|
||||||
onDragOverCheckErrorZone(targetZone, sourceZoneId, active);
|
onDragOverCheckErrorZone(targetZone, sourceZone, active);
|
||||||
});
|
});
|
||||||
|
|
||||||
const cleanupDraggingItem = useMemoizedFn(() => {
|
const cleanupDraggingItem = useMemoizedFn(() => {
|
||||||
|
|
|
@ -22,15 +22,17 @@ export const useErrorZones = () => {
|
||||||
const onDragOverCheckErrorZone = useMemoizedFn(
|
const onDragOverCheckErrorZone = useMemoizedFn(
|
||||||
(
|
(
|
||||||
targetZone: DropZoneInternal | null,
|
targetZone: DropZoneInternal | null,
|
||||||
sourceZoneId: SelectAxisContainerId | null,
|
sourceZone: DropZoneInternal | null,
|
||||||
activeItem: Active
|
activeItem: Active
|
||||||
) => {
|
) => {
|
||||||
|
const sourceZoneId = sourceZone?.id;
|
||||||
if (targetZone && sourceZoneId) {
|
if (targetZone && sourceZoneId) {
|
||||||
if (sourceZoneId !== targetZone.id) {
|
if (sourceZoneId !== targetZone.id) {
|
||||||
const originalItemId = activeItem.data?.current?.item.originalId;
|
const originalItemId = activeItem.data?.current?.item.originalId;
|
||||||
const columnLabelFormat = columnLabelFormats[originalItemId];
|
const columnLabelFormat = columnLabelFormats[originalItemId];
|
||||||
const zoneError = checkForError(
|
const zoneError = checkForError(
|
||||||
targetZone,
|
targetZone,
|
||||||
|
sourceZone,
|
||||||
originalItemId,
|
originalItemId,
|
||||||
columnLabelFormat,
|
columnLabelFormat,
|
||||||
selectedChartType,
|
selectedChartType,
|
||||||
|
@ -61,9 +63,11 @@ const zoneErrorRecord: Record<
|
||||||
SelectAxisContainerId,
|
SelectAxisContainerId,
|
||||||
(
|
(
|
||||||
targetZone: DropZoneInternal,
|
targetZone: DropZoneInternal,
|
||||||
|
sourceZone: DropZoneInternal,
|
||||||
columnLabelFormat: Required<IColumnLabelFormat>,
|
columnLabelFormat: Required<IColumnLabelFormat>,
|
||||||
selectedChartType: ChartType,
|
selectedChartType: ChartType,
|
||||||
axis: Parameters<typeof checkForError>[4]
|
axis: Parameters<typeof checkForError>[5],
|
||||||
|
activeItemOriginalId: string
|
||||||
) => {
|
) => {
|
||||||
error: boolean;
|
error: boolean;
|
||||||
reason: string;
|
reason: string;
|
||||||
|
@ -71,12 +75,32 @@ const zoneErrorRecord: Record<
|
||||||
> = {
|
> = {
|
||||||
[SelectAxisContainerId.Available]: () => null,
|
[SelectAxisContainerId.Available]: () => null,
|
||||||
[SelectAxisContainerId.Metric]: () => null,
|
[SelectAxisContainerId.Metric]: () => null,
|
||||||
[SelectAxisContainerId.XAxis]: (targetZone, columnLabelFormat, selectedChartType, axis) => {
|
[SelectAxisContainerId.XAxis]: (
|
||||||
console.log(targetZone, axis);
|
targetZone,
|
||||||
|
sourceZone,
|
||||||
|
columnLabelFormat,
|
||||||
|
selectedChartType,
|
||||||
|
axis,
|
||||||
|
activeItemOriginalId
|
||||||
|
) => {
|
||||||
|
console.log(targetZone, sourceZone, axis);
|
||||||
|
const isInCategoryAxis =
|
||||||
|
axis !== null &&
|
||||||
|
'category' in axis &&
|
||||||
|
axis.category?.includes(activeItemOriginalId) &&
|
||||||
|
!sourceZone?.items.some((item) => item.originalId === activeItemOriginalId);
|
||||||
|
|
||||||
|
if (isInCategoryAxis) {
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
reason: 'Cannot add a column that is already in the category',
|
||||||
|
zoneId: targetZone.id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
[SelectAxisContainerId.YAxis]: (targetZone, columnLabelFormat) => {
|
[SelectAxisContainerId.YAxis]: (targetZone, sourceZone, columnLabelFormat) => {
|
||||||
const isNumericType = isNumericColumnType(columnLabelFormat.columnType);
|
const isNumericType = isNumericColumnType(columnLabelFormat.columnType);
|
||||||
if (!isNumericType) {
|
if (!isNumericType) {
|
||||||
return {
|
return {
|
||||||
|
@ -97,7 +121,7 @@ const zoneErrorRecord: Record<
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
[SelectAxisContainerId.Y2Axis]: (targetZone, columnLabelFormat) => {
|
[SelectAxisContainerId.Y2Axis]: (targetZone, sourceZone, columnLabelFormat) => {
|
||||||
const isNumericType = isNumericColumnType(columnLabelFormat.columnType);
|
const isNumericType = isNumericColumnType(columnLabelFormat.columnType);
|
||||||
if (!isNumericType) {
|
if (!isNumericType) {
|
||||||
return {
|
return {
|
||||||
|
@ -118,7 +142,30 @@ const zoneErrorRecord: Record<
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
[SelectAxisContainerId.CategoryAxis]: () => null,
|
[SelectAxisContainerId.CategoryAxis]: (
|
||||||
|
targetZone,
|
||||||
|
sourceZone,
|
||||||
|
columnLabelFormat,
|
||||||
|
selectedChartType,
|
||||||
|
axis,
|
||||||
|
activeItemOriginalId
|
||||||
|
) => {
|
||||||
|
const isInCategoryAxis =
|
||||||
|
axis !== null &&
|
||||||
|
'category' in axis &&
|
||||||
|
axis.category?.includes(activeItemOriginalId) &&
|
||||||
|
!sourceZone?.items.some((item) => item.originalId === activeItemOriginalId);
|
||||||
|
|
||||||
|
if (isInCategoryAxis) {
|
||||||
|
return {
|
||||||
|
error: true,
|
||||||
|
reason: 'Cannot add a column that is already in the x-axis',
|
||||||
|
zoneId: targetZone.id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
},
|
||||||
[SelectAxisContainerId.SizeAxis]: (targetZone) => {
|
[SelectAxisContainerId.SizeAxis]: (targetZone) => {
|
||||||
if (targetZone.items.length >= 1) {
|
if (targetZone.items.length >= 1) {
|
||||||
return {
|
return {
|
||||||
|
@ -133,6 +180,7 @@ const zoneErrorRecord: Record<
|
||||||
|
|
||||||
const checkForError = (
|
const checkForError = (
|
||||||
targetZone: DropZoneInternal,
|
targetZone: DropZoneInternal,
|
||||||
|
sourceZone: DropZoneInternal,
|
||||||
activeItemOriginalId: string,
|
activeItemOriginalId: string,
|
||||||
columnLabelFormat: Required<IColumnLabelFormat>,
|
columnLabelFormat: Required<IColumnLabelFormat>,
|
||||||
selectedChartType: ChartType,
|
selectedChartType: ChartType,
|
||||||
|
@ -151,9 +199,11 @@ const checkForError = (
|
||||||
const targetZoneId = targetZone.id;
|
const targetZoneId = targetZone.id;
|
||||||
const zoneError = zoneErrorRecord[targetZoneId](
|
const zoneError = zoneErrorRecord[targetZoneId](
|
||||||
targetZone,
|
targetZone,
|
||||||
|
sourceZone,
|
||||||
columnLabelFormat,
|
columnLabelFormat,
|
||||||
selectedChartType,
|
selectedChartType,
|
||||||
axis
|
axis,
|
||||||
|
activeItemOriginalId
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!zoneError) return null;
|
if (!zoneError) return null;
|
||||||
|
|
Loading…
Reference in New Issue