Skip to content

Commit

Permalink
[Selection] rename internal SelectionKind -> SelectionMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
HenFo committed Nov 20, 2024
1 parent 706703e commit 0312d19
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
32 changes: 16 additions & 16 deletions src/packages/selection/Selection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ export const Selection: FC<SelectionProps> = (props) => {
const currentSourceStatus = useSourceStatus(currentSource, defaultNotAvailableMessage);

const selectionDefault = "extent";
const [selectionKind, setSelectionKind] = useState<SelectionMethod>(selectionDefault);
const [selectionMethod, setSelectionMethod] = useState<SelectionMethod>(selectionDefault);
useEffect(() => {
let method = selectionMethods ?? selectionDefault;
method = Array.isArray(method) && method.length > 0 ? method[0]! : method as SelectionMethod;
setSelectionKind(method);
setSelectionMethod(method);
}, [selectionMethods]);
const showSelectionButtons = useMemo(() => {
return Boolean(selectionMethods && Array.isArray(selectionMethods) && selectionMethods.length > 1);
Expand All @@ -146,7 +146,7 @@ export const Selection: FC<SelectionProps> = (props) => {
const [isOpenSelect, setIsOpenSelect] = useState(false);

useInteractiveSelection(
selectionKind,
selectionMethod,
mapState.map,
intl,
onExtentSelected,
Expand Down Expand Up @@ -182,18 +182,18 @@ export const Selection: FC<SelectionProps> = (props) => {
return (
<VStack {...containerProps} spacing={2}>
{showSelectionButtons && <FormControl>
<FormLabel>{intl.formatMessage({ id: "selectionKind" })}</FormLabel>
<FormLabel>{intl.formatMessage({ id: "selectionMethod" })}</FormLabel>
<HStack gap={2}>
<ToolButton
icon={<PiSelectionPlusBold />}
label={intl.formatMessage({id: "EXTENT"})}
onClick={() => setSelectionKind("extent")}
isActive={selectionKind === "extent"}/>
onClick={() => setSelectionMethod("extent")}
isActive={selectionMethod === "extent"}/>
<ToolButton
icon={<TbPointerQuestion />}
label={intl.formatMessage({id: "POINT"})}
onClick={() => setSelectionKind("point")}
isActive={selectionKind === "point"}/>
onClick={() => setSelectionMethod("point")}
isActive={selectionMethod === "point"}/>
</HStack>
</FormControl>}
<FormControl>
Expand Down Expand Up @@ -422,24 +422,24 @@ function useSourceStatus(
* Hook to manage map controls and tooltip
*/
function useInteractiveSelection(
selectionKind: SelectionMethod,
selectionMethod: SelectionMethod,
map: MapModel | undefined,
intl: PackageIntl,
onExtentSelected: (geometry: Geometry) => void,
isActive: boolean,
hasSelectedSource: boolean
) {

function selectionKindFactory(
selectionKind: SelectionMethod,
function selectionMethodFactory(
selectionMethod: SelectionMethod,
): ISelectionTypeHandler<DragController | ClickController> {
switch (selectionKind) {
switch (selectionMethod) {
case "extent":
return DragController;
case "point":
return ClickController;
default:
throw new Error(`Unknown selection kind: ${selectionKind}`);
throw new Error(`Unknown selection kind: ${selectionMethod}`);
}
}

Expand All @@ -452,10 +452,10 @@ function useInteractiveSelection(
? intl.formatMessage({ id: "disabledTooltip" })
: intl.formatMessage({ id: "noSourceTooltip" });

const controlerCls = selectionKindFactory(selectionKind);
const controlerCls = selectionMethodFactory(selectionMethod);
const dragController = new controlerCls(
map.olMap,
intl.formatMessage({ id: `tooltip.${selectionKind}` }),
intl.formatMessage({ id: `tooltip.${selectionMethod}` }),
disabledMessage,
onExtentSelected
);
Expand All @@ -464,7 +464,7 @@ function useInteractiveSelection(
return () => {
dragController?.destroy();
};
}, [map, intl, onExtentSelected, isActive, hasSelectedSource, selectionKind]);
}, [map, intl, onExtentSelected, isActive, hasSelectedSource, selectionMethod]);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/packages/selection/i18n/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ messages:
FREEPOLYGON: "Freies Zeichnen"
CIRCLE: "Kreis"
POINT: "Punkt"
selectionKind: "Selektionsart"
selectionMethod: "Selektionsart"
selectSource: "Quelle auswählen"
tooltip:
extent: "Klicken Sie in die Karte, halten Sie die Maustaste gedrückt und ziehen Sie ein Rechteck auf"
Expand Down
2 changes: 1 addition & 1 deletion src/packages/selection/i18n/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ messages:
FREEPOLYGON: "Freies Zeichnen"
CIRCLE: "Kreis"
POINT: "Point"
selectionKind: "Selection type"
selectionMethod: "Selection type"
selectSource: "Select source"
tooltip:
extent: "Click on the map, hold down the mouse button and draw a rectangle"
Expand Down

0 comments on commit 0312d19

Please sign in to comment.