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: editor: fixes #6439 #6440

Merged
merged 1 commit into from
Jan 25, 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 @@ -78,6 +78,7 @@ const SpeedSectionMetadataForm: FC = () => {
<div key={key} className="form-group field field-string">
<div className="d-flex flex-row align-items-center">
<input
required
className="form-control flex-grow-2 flex-shrink-1 mr-2 px-2"
placeholder=""
type="text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ interface RangeEditionToolParams<T extends EditorRange> {
messagesComponent: ComponentType;
layersComponent: ComponentType<{ map: Map }>;
leftPanelComponent: ComponentType;
canSave?: (state: RangeEditionState<T>) => boolean;
}

function getRangeEditionTool<T extends EditorRange>({
Expand All @@ -57,6 +58,7 @@ function getRangeEditionTool<T extends EditorRange>({
messagesComponent,
layersComponent,
leftPanelComponent,
canSave,
}: RangeEditionToolParams<T>): Tool<RangeEditionState<T>> {
const layersEntity = getNewEntity();
function getInitialState(): RangeEditionState<T> {
Expand Down Expand Up @@ -91,8 +93,10 @@ function getRangeEditionTool<T extends EditorRange>({
id: `save-${objectTypeAction}`,
icon: AiFillSave,
labelTranslationKey: `Editor.tools.${objectTypeEdition}-edition.actions.save-${objectTypeAction}`,
isDisabled({ isLoading }) {
return isLoading || false;
isDisabled({ isLoading, state }) {
if (isLoading) return true;
if (canSave) return !canSave(state);
return false;
},
async onClick({ state, setState, dispatch, infraID }) {
const { initialEntity, entity } = state;
Expand Down
5 changes: 5 additions & 0 deletions front/src/applications/editor/tools/rangeEdition/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export const SpeedEditionTool = getRangeEditionTool<SpeedSectionEntity | SpeedSe
messagesComponent: SpeedSectionMessages,
layersComponent: SpeedSectionEditionLayers,
leftPanelComponent: RangeEditionLeftPanel,
canSave(state) {
const records = state.entity.properties.speed_limit_by_tag || {};
const compositionCodes = Object.keys(records);
return compositionCodes.every((code) => !!code);
},
});

export const ElectrificationEditionTool = getRangeEditionTool<ElectrificationEntity>({
Expand Down
Loading