Skip to content

Commit

Permalink
front: remove unnecessary type assertions
Browse files Browse the repository at this point in the history
Generated via eslint --fix, then fixed up two issues in:

- src/utils/mapHelper.ts
- src/common/Map/WarpedMap/core/projection.ts

Signed-off-by: Simon Ser <[email protected]>
  • Loading branch information
emersion committed Sep 10, 2024
1 parent b1b0bd1 commit 08f26b3
Show file tree
Hide file tree
Showing 32 changed files with 48 additions and 57 deletions.
7 changes: 1 addition & 6 deletions front/src/applications/editor/components/EntitySumUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,7 @@ const EntitySumUp = ({ entity, id, objType, classes, status, error }: EntitySumU
setState({ type: 'loading' });

if (!entity) {
entity = await getEntity(
infraID as number,
id as string,
objType as EditoastType,
dispatch
);
entity = await getEntity(infraID as number, id, objType as EditoastType, dispatch);
}

const additionalEntities = await getAdditionalEntities(infraID as number, entity, dispatch);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const IntervalEditorComponent = (props: FieldProps) => {
setHovered(null);
}
setClickPrevent(false);
}, 150) as number;
}, 150);
setClickTimeout(timer);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const BasePointEditionLayers = ({
const renderedEntity = useMemo(() => {
let res: EditorEntity | null = null;
if (entity.geometry && !isEqual(entity.geometry, NULL_GEOMETRY)) {
res = entity as EditorEntity;
res = entity;
} else if (nearestPoint) {
if (mergeEntityWithNearestPoint) {
res = mergeEntityWithNearestPoint(entity, nearestPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const PointEditionLeftPanel = <Entity extends EditorEntity>({
)}
<EditorForm
key={formKey}
data={state.entity as Entity}
data={state.entity}
overrideUiSchema={{
logical_signals: {
items: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ const RangeEditionLeftPanel = () => {
useState<AvailableSwitchPositions>({});

// The 2 main checkboxes
const isPermanentSpeedLimit = speedSectionIsPsl(entity as SpeedSectionEntity);
const isSpeedRestriction = speedSectionIsSpeedRestriction(entity as SpeedSectionEntity);
const isPermanentSpeedLimit = speedSectionIsPsl(entity);
const isSpeedRestriction = speedSectionIsSpeedRestriction(entity);

const isNew = entity.properties.id === NEW_ENTITY_ID;
const infraID = useInfraID();
const entityIsSpeedSection = entity.objType === 'SpeedSection';

/** Reset both highlighted and selected track_ranges, route ids and switches lists */
const resetSpeedRestrictionSelections = () => {
const newEntity = cloneDeep(entity) as SpeedSectionEntity;
const newEntity = cloneDeep(entity);
newEntity.properties.on_routes = [];
newEntity.properties.track_ranges = [];
setState({
Expand All @@ -81,7 +81,7 @@ const RangeEditionLeftPanel = () => {

const toggleSpeedRestriction = () => {
const selectiontype = isSpeedRestriction ? 'idle' : 'selectSwitch';
const newEntity = cloneDeep(entity) as SpeedSectionEntity;
const newEntity = cloneDeep(entity);
newEntity.properties.extensions = undefined;
newEntity.properties.track_ranges = [];
if (isSpeedRestriction) {
Expand Down Expand Up @@ -123,7 +123,7 @@ const RangeEditionLeftPanel = () => {
const updateSpeedSectionExtensions = (
extensions: SpeedSectionEntity['properties']['extensions']
) => {
const newEntity = cloneDeep(entity) as SpeedSectionEntity;
const newEntity = cloneDeep(entity);
newEntity.properties.extensions = extensions;
setState({
entity: newEntity,
Expand All @@ -144,7 +144,7 @@ const RangeEditionLeftPanel = () => {
if (isEmpty(routeElements)) {
return;
}
const newEntity = cloneDeep(entity) as SpeedSectionEntity;
const newEntity = cloneDeep(entity);
const { properties } = newEntity;
if (select) {
properties.on_routes = toggleElement(properties.on_routes || [], routeId);
Expand Down Expand Up @@ -195,7 +195,7 @@ const RangeEditionLeftPanel = () => {
}).unwrap();
const { routes, available_node_positions } = routesAndNodesPositions;

const newEntity = cloneDeep(entity) as SpeedSectionEntity;
const newEntity = cloneDeep(entity);
if (isSpeedRestriction) {
newEntity.properties.on_routes = [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ const PslSignCard = ({
type="button"
className="btn btn-danger btn-sm px-2 ml-2"
aria-label={t('Editor.tools.speed-edition.sign-remove')}
onClick={() =>
removeSign(signInfo as Exclude<PslSignInformation, { signType: PSL_SIGN_TYPES.Z }>)
}
onClick={() => removeSign(signInfo)}
>
<Trash />
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const SpeedSectionEditionLayers = () => {
setState,
} = useContext(EditorContext) as ExtendedEditorContextType<RangeEditionState<SpeedSectionEntity>>;
const isPermanentSpeedLimit = speedSectionIsPsl(entity);
const isSpeedRestriction = speedSectionIsSpeedRestriction(entity as SpeedSectionEntity);
const isSpeedRestriction = speedSectionIsSpeedRestriction(entity);

const { mapStyle, layersSettings, issuesSettings, showIGNBDORTHO } = useSelector(getMap);
const infraID = useInfraID();
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/editor/tools/rangeEdition/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function getTrackRangeFeatures(
itemType: 'TrackRange',
rangeIndex,
}),
point(track.geometry.coordinates[0] as Position, {
point(track.geometry.coordinates[0], {
...properties,
id: `speedSectionRangeExtremity::${rangeIndex}::${begin}`,
track: range.track,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const RouteEditionPanel = () => {
.map((str) => chroma(str).hex());

const features = await getRouteGeometries(
infraID as number,
infraID,
route.properties.entry_point,
route.properties.exit_point,
candidates,
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/editor/tools/routeEdition/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async function getRouteGeometryByRoute(
): Promise<Feature<LineString, { id: string }>> {
const trackRangesResp = dispatch(
osrdEditoastApi.endpoints.getInfraByInfraIdRoutesTrackRanges.initiate({
infraId: infra as number,
infraId: infra,
routes: route.properties.id,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const SwitchEditionLeftPanel = () => {
SchemaField: CustomSchemaField,
}}
onSubmit={async (flatSwitch) => {
const entityToSave = flatSwitchToSwitch(switchType, flatSwitch as FlatSwitchEntity);
const entityToSave = flatSwitchToSwitch(switchType, flatSwitch);

const res = await dispatch(
save(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ const AttachedRangesItemsList = ({ id, itemType }: AttachedRangesItemsListProps)
if (entity.objType === 'SpeedSection') {
switchTool({
toolType: TOOL_NAMES.SPEED_SECTION_EDITION,
toolState: getEditSpeedSectionState(entity as SpeedSectionEntity),
toolState: getEditSpeedSectionState(entity),
});
} else
switchTool({
toolType: TOOL_NAMES.ELECTRIFICATION_EDITION,
toolState: getEditElectrificationState(entity as ElectrificationEntity),
toolState: getEditElectrificationState(entity),
});
}}
>
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/editor/tools/translationTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function translateDefinitions(
return Object.keys(defsList).reduce<{
[key: string]: JSONSchema7;
}>((acc, defName) => {
const currentEntity = defsList![defName] as JSONSchema7;
const currentEntity = defsList[defName] as JSONSchema7;
const properties =
currentEntity.properties && translateProperties(currentEntity.properties, defName, t);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,10 @@ const importTimetable = async (
}

const node = {
id: id!,
id,
betriebspunktName: trigram || '',
fullName: fullName || '',
positionX: positionX!,
positionX,
positionY: positionY || 0,
ports: [],
transitions: [],
Expand Down Expand Up @@ -356,7 +356,7 @@ const importTimetable = async (
// convert them.
let prevPort: Port | null = null;
return pathNodeIds.slice(0, -1).map((sourceNodeId, i) => {
const targetNodeId = pathNodeIds[i + 1]!;
const targetNodeId = pathNodeIds[i + 1];

const sourcePort = createPort(trainrunSectionId);
const targetPort = createPort(trainrunSectionId);
Expand Down
4 changes: 2 additions & 2 deletions front/src/applications/operationalStudies/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ export const preparePathPropertiesData = (
const electrificationsRanges = transformBoundariesDataToRangesData(
electrifications as NonNullable<PathProperties['electrifications']>,
pathLength
) as ElectricalRangesData<ElectrificationValue>[];
);

const electricalProfilesRanges = transformBoundariesDataToRangesData(
electricalProfiles,
pathLength
) as ElectricalRangesData<ElectricalProfileValue>[];
);

const electrificationRanges = formatElectrificationRanges(
electrificationsRanges,
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/operationalStudies/views/Study.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default function Study() {
} else if (sortOption === 'NameAsc') {
filteredScenarios = [...filteredScenarios].sort((a, b) => a.name.localeCompare(b.name));
}
setScenariosList(filteredScenarios as ScenarioWithDetails[]);
setScenariosList(filteredScenarios);
} catch (error) {
console.error(error);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const Scenario = () => {
handleOperation({
event,
dispatch,
timeTableId: scenarioData!.scenario.timetable_id,
timeTableId: scenarioData.scenario.timetable_id,
netzgrafikDto,
addUpsertedTrainSchedules: (upsertedTrainSchedules: TrainScheduleResult[]) => {
setNgeUpsertedTrainSchedules((prev) =>
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/referenceMap/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const HomeReferenceMap = () => {
useEffect(() => {
if (infraID) {
// if the infra in the store is not found, then we set it to undefined
getInfraByInfraId({ infraId: infraID as number }).then((resp) => {
getInfraByInfraId({ infraId: infraID }).then((resp) => {
if (resp.error && 'status' in resp.error && resp.error.status === 404) {
dispatch(updateInfraID(undefined));
}
Expand Down
2 changes: 1 addition & 1 deletion front/src/common/IntervalsDataViz/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ export function entityDoUpdate<T extends EditorEntity>(entity: T, sourceLine: Li
newProps[name] = value;
}
});
newProps.length = getLineStringDistance(entity.geometry as LineString);
newProps.length = getLineStringDistance(entity.geometry);
return { ...entity, properties: newProps };
}
return entity;
Expand Down
2 changes: 1 addition & 1 deletion front/src/common/IntervalsEditor/IntervalsEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const IntervalsEditor = (props: IntervalsEditorProps) => {
setHovered(null);
}
setClickPrevent(false);
}, 50) as number;
}, 50);
setClickTimeout(timer);
}
if (selectedTool === INTERVALS_EDITOR_TOOLS.CUT_TOOL) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const IntervalsEditorMarginForm = ({
const result = cloneDeep(data);
if (result && result[selectedIntervalIndex]) {
result[selectedIntervalIndex].value = parseFloat(e.target.value);
setData(result as IntervalItem[]);
setData(result);
}
}}
value={(interval.value as number) || 0}
Expand Down
2 changes: 1 addition & 1 deletion front/src/common/Map/WarpedMap/DataLoader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const DataLoader = ({ bbox, getGeoJSONs, layers }: DataLoaderProps) => {

useEffect(() => {
if (state === 'render' && mapRef) {
const m = mapRef as MapRef;
const m = mapRef;

const querySources = () => {
// Retrieve OSRD data:
Expand Down
5 changes: 2 additions & 3 deletions front/src/common/Map/WarpedMap/core/projection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,8 @@ export function clipAndProjectGeoJSON<T extends Geometry | Feature | FeatureColl
};

if (geojson.type === 'Feature') {
const clippedFeature = shouldClip
? (clip(geojson, zone) as Feature | null)
: (geojson as Feature);
const feature: Feature = geojson;
const clippedFeature = shouldClip ? clip(feature, zone) : feature;

if (clippedFeature) {
const newGeometry = projectGeometry(clippedFeature.geometry, projection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default function AddOrEditProjectModal({
} else {
try {
if (tempProjectImage) {
const imageId = await uploadImage(tempProjectImage as Blob);
const imageId = await uploadImage(tempProjectImage);
if (imageId) currentProject.image = imageId;
}
const request = postProject({
Expand Down Expand Up @@ -165,7 +165,7 @@ export default function AddOrEditProjectModal({
let imageId = currentProject.image;

if (tempProjectImage) {
imageId = await uploadImage(tempProjectImage as Blob);
imageId = await uploadImage(tempProjectImage);
// if the upload of the new image fails, keep the old one
if (!imageId && currentProject.image) {
imageId = currentProject.image;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function useCompleteRollingStockSchemasProperties(): readonly SchemaProperty[] {
const completeRsSchemaProperties = useMemo(() => {
const sigSystemsIndex = RS_SCHEMA_PROPERTIES.findIndex(
(s) => s.title === 'supportedSignalingSystems'
)!;
);
const completeSigSystemsSchema = {
...RS_SCHEMA_PROPERTIES[sigSystemsIndex],
enum: supportedSignalingSystems || [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const Project2Image = ({ project }: { project: ProjectWithStudies }) => {
useMemo(async () => {
if (!project || !project.image) return;
try {
const blobImage = await getDocument(project.image as number);
const blobImage = await getDocument(project.image);
if (blobImage) setImageUrl(URL.createObjectURL(blobImage));
} catch (error: unknown) {
console.error(error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const updateChart = <

chart.xAxisGrid.call(gridX(newX, chart.height));
chart.yAxisGrid.call(gridY(newY, chart.width));
if (chart.y2AxisGrid) chart.y2AxisGrid.call(gridY2(newY2 as SimulationD3Scale, chart.width));
if (chart.y2AxisGrid) chart.y2AxisGrid.call(gridY2(newY2, chart.width));

// * update lines, areas, rects by aiming their specific class.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import along from '@turf/along';
import { lineString } from '@turf/helpers';
import type { Feature, LineString } from 'geojson';

import type { PositionSpeedTime, PositionsSpeedTimes } from 'reducers/osrdsimulation/types';
import type { PositionsSpeedTimes } from 'reducers/osrdsimulation/types';

import type { TrainPosition } from './types';

Expand All @@ -18,7 +18,7 @@ import type { TrainPosition } from './types';

function getPosition(positionValues: PositionsSpeedTimes<Date>, baseKey?: string) {
const key = baseKey as keyof PositionsSpeedTimes<Date>;
return positionValues[key] as PositionSpeedTime<Date>;
return positionValues[key];
}

// TODO: fix warped map - probably remove this function and use finalOutput as key ?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ const SpaceCurvesSlopesV2 = ({
const operationalPointsZone = chartLocal.drawZone
.append('g')
.attr('id', 'gev-operationalPointsZone');
operationalPoints!.forEach((op) => {
operationalPoints.forEach((op) => {
operationalPointsZone
.append('line')
.datum(mmToM(op.position))
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/timesStops/TimesStops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const TimesStops = ({
if (!rowData.stopFor && op.fromRowIndex !== allWaypoints.length - 1) {
rowData.onStopSignal = false;
}
if (rowData.theoreticalMargin && !marginRegExValidation.test(rowData.theoreticalMargin!)) {
if (rowData.theoreticalMargin && !marginRegExValidation.test(rowData.theoreticalMargin)) {
rowData.isMarginValid = false;
setRows(row);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { useOsrdConfSelectors } from 'common/osrdContext';
import { useStoreDataForRollingStockSelector } from 'modules/rollingStock/components/RollingStockSelector/useStoreDataForRollingStockSelector';
import checkCurrentConfig from 'modules/trainschedule/components/ManageTrainSchedule/helpers/checkCurrentConfig';
import { setFailure, setSuccess } from 'reducers/main';
import { type OsrdConfState } from 'reducers/osrdconf/types';
import { updateSelectedTrainId } from 'reducers/osrdsimulation/actions';
import { useAppDispatch } from 'store';
import { formatToIsoDate } from 'utils/date';
Expand All @@ -33,7 +32,7 @@ const useUpdateTrainSchedule = (

return async function submitConfUpdateTrainSchedules() {
const formattedSimulationConf = checkCurrentConfig(
simulationConf as OsrdConfState,
simulationConf,
t,
dispatch,
rollingStock?.name
Expand Down
Loading

0 comments on commit 08f26b3

Please sign in to comment.