Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: transform some RTK mutations into queries to prevent useless requests #9831

Merged
merged 4 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const RouteEditionPanel = () => {
const { t } = useTranslation();
const infraID = useInfraID();
const dispatch = useAppDispatch();
const [postPathfinding] = osrdEditoastApi.endpoints.postInfraByInfraIdPathfinding.useMutation();
const [postPathfinding] = osrdEditoastApi.endpoints.postInfraByInfraIdPathfinding.useLazyQuery();
const { state, setState, isFormSubmited, setIsFormSubmited } = useContext(
EditorContext
) as ExtendedEditorContextType<RouteEditionState>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default function useCachedTrackSections(infraId: number) {
const trackIdsRef = useRef<Set<string>>(new Set());
const trackSectionsRef = useRef<Record<string, TrackSection>>({});
const [loadInfraObject, { isLoading }] =
osrdEditoastApi.endpoints.postInfraByInfraIdObjectsAndObjectType.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdObjectsAndObjectType.useLazyQuery();

const getTrackSectionsByIds = useCallback(
async (requestedTrackIds: string[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ const useSetupItineraryForTrainUpdate = (
const [getRollingStockByName] =
osrdEditoastApi.endpoints.getRollingStockNameByRollingStockName.useLazyQuery();
const [postPathfindingBlocks] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useLazyQuery();
const [postPathProperties] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useLazyQuery();
const { infraId } = useScenarioContext();

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const useStaticPathfinding = (infra?: InfraWithState) => {
const [pathfinding, setPathfinding] = useState<PathfindingResult>();

const [postPathfindingBlocks] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useLazyQuery();

const pathStepsLocations = useMemo(
() =>
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/stdcm/hooks/useStdcmResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const useStdcmResults = (
const selectedTrainId = useSelector(getSelectedTrainId);

const [postPathProperties] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useLazyQuery();

const { data: otherSelectedTrainSchedule } =
osrdEditoastApi.endpoints.getTrainScheduleById.useQuery(
Expand Down
16 changes: 8 additions & 8 deletions front/src/common/api/generatedEditoastApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ const injectedRtkApi = api
query: (queryArg) => ({ url: `/infra/${queryArg.infraId}/lock`, method: 'POST' }),
invalidatesTags: ['infra'],
}),
postInfraByInfraIdObjectsAndObjectType: build.mutation<
postInfraByInfraIdObjectsAndObjectType: build.query<
PostInfraByInfraIdObjectsAndObjectTypeApiResponse,
PostInfraByInfraIdObjectsAndObjectTypeApiArg
>({
Expand All @@ -278,9 +278,9 @@ const injectedRtkApi = api
method: 'POST',
body: queryArg.body,
}),
invalidatesTags: ['infra'],
providesTags: ['infra'],
}),
postInfraByInfraIdPathProperties: build.mutation<
postInfraByInfraIdPathProperties: build.query<
PostInfraByInfraIdPathPropertiesApiResponse,
PostInfraByInfraIdPathPropertiesApiArg
>({
Expand All @@ -290,9 +290,9 @@ const injectedRtkApi = api
body: queryArg.pathPropertiesInput,
params: { props: queryArg.props },
}),
invalidatesTags: ['pathfinding'],
providesTags: ['pathfinding'],
}),
postInfraByInfraIdPathfinding: build.mutation<
postInfraByInfraIdPathfinding: build.query<
PostInfraByInfraIdPathfindingApiResponse,
PostInfraByInfraIdPathfindingApiArg
>({
Expand All @@ -302,9 +302,9 @@ const injectedRtkApi = api
body: queryArg.infraPathfindingInput,
params: { number: queryArg.number },
}),
invalidatesTags: ['infra', 'pathfinding'],
providesTags: ['infra', 'pathfinding'],
}),
postInfraByInfraIdPathfindingBlocks: build.mutation<
postInfraByInfraIdPathfindingBlocks: build.query<
PostInfraByInfraIdPathfindingBlocksApiResponse,
PostInfraByInfraIdPathfindingBlocksApiArg
>({
Expand All @@ -313,7 +313,7 @@ const injectedRtkApi = api
method: 'POST',
body: queryArg.pathfindingInput,
}),
invalidatesTags: ['pathfinding'],
providesTags: ['pathfinding'],
}),
getInfraByInfraIdRailjson: build.query<
GetInfraByInfraIdRailjsonApiResponse,
Expand Down
4 changes: 4 additions & 0 deletions front/src/config/openapi-editoast-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const config: ConfigFile = {
endpointOverrides: [
{
pattern: [
'postInfraByInfraIdObjectsAndObjectType',
'postInfraByInfraIdPathfinding',
'postInfraByInfraIdPathfindingBlocks',
'postInfraByInfraIdPathProperties',
'postTrainSchedule',
'postTrainScheduleSimulationSummary',
'postTrainScheduleProjectPath',
Expand Down
2 changes: 1 addition & 1 deletion front/src/modules/pathfinding/hooks/usePathProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const usePathProperties = (
const [pathProperties, setPathProperties] = useState<PathProperties>();

const [postPathProperties] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useLazyQuery();

useEffect(() => {
const getPathProperties = async () => {
Expand Down
4 changes: 2 additions & 2 deletions front/src/modules/pathfinding/hooks/usePathfinding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,9 @@ export const usePathfinding = (
const [isPathfindingInitialized, setIsPathfindingInitialized] = useState(false);

const [postPathfindingBlocks] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdPathfindingBlocks.useLazyQuery();
const [postPathProperties] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useLazyQuery();

const { updatePathSteps } = useOsrdConfActions();
const { infraId } = useScenarioContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const useGetProjectedTrainOperationalPoints = (
);

const [postPathProperties] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useLazyQuery();

useEffect(() => {
const getOperationalPoints = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const useProjectedConflicts = (
path: PathfindingResultSuccess | undefined
) => {
const [postPathProperties] =
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdPathProperties.useLazyQuery();

const [projectedZones, setProjectedZones] = useState<PathProperties['zones']>();
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function RenderPopup({ pathProperties }: RenderPopupProps) {
const [trackOffset, setTrackOffset] = useState(0);

const [getTrackEntity] =
osrdEditoastApi.endpoints.postInfraByInfraIdObjectsAndObjectType.useMutation();
osrdEditoastApi.endpoints.postInfraByInfraIdObjectsAndObjectType.useLazyQuery();

useEffect(() => {
const calculateOffset = async () => {
Expand Down
Loading