Skip to content

Commit 1cbd1e4

Browse files
committed
front: source extension for editor
* remove source edition if object has no source data * if object has source data, on form, source are readonly * add source data on entity sumup See message in #384 Fix #7314
1 parent c2a5fa9 commit 1cbd1e4

File tree

7 files changed

+78
-4
lines changed

7 files changed

+78
-4
lines changed

front/public/locales/en/infraEditor.json

+12
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,18 @@
582582
}
583583
}
584584
},
585+
"TrackSectionSourceExtension": {
586+
"properties": {
587+
"name": {
588+
"title": "Source",
589+
"description": "Name of the source"
590+
},
591+
"id": {
592+
"title": "Source ID",
593+
"description": "ID of the element within the source"
594+
}
595+
}
596+
},
585597
"TvmSystem": {
586598
"properties": {
587599
"next_signaling_systems": {

front/public/locales/en/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@
394394
"of-type": "of type",
395395
"selection": "{{count}} item selected",
396396
"selection_plural": "{{count}} items selected",
397+
"sources": "Sources",
397398
"title": "Select",
398399
"unselect": "Deselect"
399400
},

front/public/locales/fr/infraEditor.json

+12
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,18 @@
582582
}
583583
}
584584
},
585+
"TrackSectionSourceExtension": {
586+
"properties": {
587+
"name": {
588+
"title": "Source",
589+
"description": "Nom de la source"
590+
},
591+
"id": {
592+
"title": "Source ID",
593+
"description": "Identifiant de l'élément dans la source"
594+
}
595+
}
596+
},
585597
"TvmSystem": {
586598
"properties": {
587599
"next_signaling_systems": {

front/public/locales/fr/translation.json

+1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@
377377
"of-type": "de type",
378378
"selection": "{{count}} élément sélectionné",
379379
"selection_plural": "{{count}} éléments sélectionnés",
380+
"sources": "Sources",
380381
"title": "Sélection",
381382
"unselect": "Désélectionner"
382383
},

front/src/applications/editor/components/EntitySumUp.tsx

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { type FC, useEffect, useState } from 'react';
1+
import React, { type FC, useEffect, useState, Fragment } from 'react';
22

33
import cx from 'classnames';
44
import type { TFunction } from 'i18next';
@@ -113,6 +113,7 @@ function getSumUpContent(
113113
let text = '';
114114
const subtexts: (string | JSX.Element)[] = [];
115115
const classes = { ...DEFAULT_CLASSES, ...(classesOverride || {}) };
116+
const sources: string[] = [];
116117

117118
switch (entity.objType) {
118119
case 'TrackSection': {
@@ -125,6 +126,10 @@ function getSumUpContent(
125126
text = trackSection.properties.id;
126127
}
127128
if (attrs.line_name) subtexts.unshift(attrs.line_name);
129+
const source = trackSection.properties.extensions?.source;
130+
if (source) {
131+
sources.push(`${source.name} ${source.id}`);
132+
}
128133
break;
129134
}
130135
// @ts-expect-error: Here we only deal with the installation_type, the rest is handled with BufferStop and Detector.
@@ -280,6 +285,14 @@ function getSumUpContent(
280285
{s}
281286
</div>
282287
))}
288+
{sources.length > 0 && (
289+
<div>
290+
<span className={cx(classes.strong, 'mr-2')}>
291+
{t(`Editor.tools.select-items.sources`)}
292+
</span>
293+
{sources.join(', ')}
294+
</div>
295+
)}
283296
</div>
284297
);
285298
}

front/src/applications/editor/tools/trackEdition/components/TrackEditionLeftPanel.tsx

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
1-
import React, { useContext, useEffect, useRef } from 'react';
1+
import React, { useContext, useEffect, useRef, useMemo } from 'react';
22

33
import type { WidgetProps } from '@rjsf/utils';
4+
import { isNil, omit } from 'lodash';
45
import { useTranslation } from 'react-i18next';
56

67
import EditorForm from 'applications/editor/components/EditorForm';
78
import EntityError from 'applications/editor/components/EntityError';
89
import EditorContext from 'applications/editor/context';
9-
import { NEW_ENTITY_ID } from 'applications/editor/data/utils';
10+
import {
11+
NEW_ENTITY_ID,
12+
getJsonSchemaForLayer,
13+
getLayerForObjectType,
14+
} from 'applications/editor/data/utils';
1015
import type {
1116
TrackEditionState,
1217
TrackSectionEntity,
@@ -32,7 +37,7 @@ const TrackEditionLeftPanel: React.FC = () => {
3237
const dispatch = useAppDispatch();
3338
const { t } = useTranslation();
3439
const infraID = useInfraID();
35-
const { state, setState, isFormSubmited, setIsFormSubmited } = useContext(
40+
const { state, setState, isFormSubmited, setIsFormSubmited, editorState } = useContext(
3641
EditorContext
3742
) as ExtendedEditorContextType<TrackEditionState>;
3843
const submitBtnRef = useRef<HTMLButtonElement>(null);
@@ -49,14 +54,40 @@ const TrackEditionLeftPanel: React.FC = () => {
4954
}
5055
}, [isFormSubmited]);
5156

57+
const schema = useMemo(
58+
() =>
59+
getJsonSchemaForLayer(
60+
editorState.editorSchema,
61+
getLayerForObjectType(editorState.editorSchema, track.objType) || ''
62+
),
63+
[editorState.editorSchema, track.objType]
64+
);
65+
5266
return (
5367
<>
5468
<EditorForm
5569
data={track}
70+
// Remove the source from schema if there is no source in the object
71+
// To avoid to display it on the form
72+
overrideSchema={
73+
isNil(track.properties.extensions?.source)
74+
? omit(schema, ['$defs.TrackSectionExtensions.properties.source'])
75+
: schema
76+
}
5677
overrideUiSchema={{
5778
length: {
5879
'ui:widget': CustomLengthInput,
5980
},
81+
extensions: {
82+
source: {
83+
id: {
84+
'ui:readonly': true,
85+
},
86+
name: {
87+
'ui:readonly': true,
88+
},
89+
},
90+
},
6091
}}
6192
onSubmit={async (savedEntity) => {
6293
// eslint-disable-next-line @typescript-eslint/no-explicit-any

front/src/applications/editor/tools/trackEdition/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export type TrackSectionEntity = EditorEntity<
2121
track_name?: string;
2222
track_number?: number;
2323
};
24+
source?: {
25+
id: string;
26+
name: string;
27+
};
2428
};
2529
}
2630
> & {

0 commit comments

Comments
 (0)