Skip to content

Commit 967fb0f

Browse files
Merge pull request #2001 from Heigvd/dev
Release v3.2.7 (2024.12)
2 parents ed90c4c + 79a4552 commit 967fb0f

31 files changed

+505
-80
lines changed

wegas-app/src/main/node/wegas-react/src/API/gameModel.api.ts

+42-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
import { managedModeRequest, rest } from './rest';
22

3+
/** PatchDiff and changes */
4+
interface LineChange {
5+
lineNumber: number;
6+
tag: string;
7+
content: string;
8+
}
9+
10+
interface SideBySideChange {
11+
oldValue: string;
12+
newValue: string;
13+
}
14+
15+
type Change = LineChange | SideBySideChange;
16+
17+
interface DiffCollection {
18+
title: string;
19+
diffs: PatchDiff[];
20+
}
21+
22+
interface PrimitiveDiff {
23+
title: string;
24+
changes: Change[];
25+
}
26+
27+
export type PatchDiff = DiffCollection | PrimitiveDiff;
28+
329
export const GameModelApi = {
430
get(gameModelId: number | string) {
531
return managedModeRequest('/GameModel/' + gameModelId);
@@ -25,10 +51,22 @@ export const GameModelApi = {
2551
);
2652
},
2753
createExtraTestPlayer(gameModelId: number) {
54+
return managedModeRequest(`/GameModel/${gameModelId}/ExtraTestPlayer`, {
55+
method: 'POST',
56+
});
57+
},
58+
getModelDiff(gameModelId: number | string): Promise<PatchDiff> {
59+
return managedModeRequest(`/GameModel/${gameModelId}/Diff`).then(
60+
res => res.updatedEntities[0] as Promise<PatchDiff>,
61+
);
62+
},
63+
propagateModel(gameModelId: number) {
2864
return managedModeRequest(
29-
`/GameModel/${ gameModelId}/ExtraTestPlayer`,
65+
`/GameModel/${gameModelId}/Propagate`,
3066
{
31-
method: 'POST',
32-
});
33-
}
67+
method: 'PUT',
68+
},
69+
false,
70+
);
71+
},
3472
};

wegas-app/src/main/node/wegas-react/src/Components/Contexts/FeaturesProvider.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ import * as React from 'react';
22
import { commonTranslations } from '../../i18n/common/common';
33
import { useInternalTranslate } from '../../i18n/internalTranslator';
44
import { CheckBox } from '../Inputs/Boolean/CheckBox';
5+
import {GameModel} from "../../data/selectors";
56

67
const availableFeatures: FeatureLevel[] = ['ADVANCED', 'INTERNAL'];
78

89
export const defaultFeatures: FeaturesSelecta = {
910
DEFAULT: true,
1011
ADVANCED: false,
1112
INTERNAL: false,
13+
MODELER: false,
1214
};
1315

1416
export interface FeatureContext {
@@ -75,6 +77,12 @@ function FeaturesContext({
7577
};
7678
}, [listener]);
7779

80+
React.useEffect(() => {
81+
if (GameModel.selectCurrent().type === 'MODEL') {
82+
toggleFeature('MODELER');
83+
}
84+
}, []);
85+
7886
return (
7987
<featuresCTX.Provider
8088
value={{

wegas-app/src/main/node/wegas-react/src/Components/DropDown.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function ajustVertically(values: ContainerValues) {
9797
return newValues;
9898
}
9999

100-
function ajustVerticalOverlap(values: ContainerValues, parent: HTMLElement) {
100+
function adjustVerticalOverlap(values: ContainerValues, parent: HTMLElement) {
101101
let newTopUp = parent.getBoundingClientRect().top - values.height;
102102
const newTopDown =
103103
parent.getBoundingClientRect().top + parent.getBoundingClientRect().height;
@@ -127,7 +127,7 @@ function ajustVerticalOverlap(values: ContainerValues, parent: HTMLElement) {
127127
}
128128
}
129129

130-
function ajustHorizontalOverlap(values: ContainerValues, parent: HTMLElement) {
130+
function adjustHorizontalOverlap(values: ContainerValues, parent: HTMLElement) {
131131
let newLeftUp = parent.getBoundingClientRect().left - values.width;
132132
const newLeftDown =
133133
parent.getBoundingClientRect().left + parent.getBoundingClientRect().width;
@@ -250,9 +250,9 @@ export function justifyDropMenu(
250250
values = ajustVertically(values);
251251

252252
if (vertical && isOverlappingVertically(values, selector)) {
253-
values = ajustVerticalOverlap(values, selector);
253+
values = adjustVerticalOverlap(values, selector);
254254
} else if (!vertical && isOverlappingHorizontally(values, selector)) {
255-
values = ajustHorizontalOverlap(values, selector);
255+
values = adjustHorizontalOverlap(values, selector);
256256
}
257257

258258
menu.style.setProperty('left', values.left + 'px');

wegas-app/src/main/node/wegas-react/src/Components/Inputs/Buttons/Button.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export const loadingStyle = cx(
4747
);
4848

4949
export const buttonStyle = css({
50+
position: 'relative',
5051
display: 'flex',
5152
alignItems: 'center',
5253
backgroundColor: themeVar.colors.PrimaryColor,

wegas-app/src/main/node/wegas-react/src/Components/PageComponents/Inputs/Select.component.tsx

+33-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ interface PlayerSelectInputProps extends WegasComponentProps {
3636
* choices - the allowed choices
3737
*/
3838
choices?: Choice[] | IScript;
39+
/**
40+
* placeholder - the grey text inside the box when nothing is selected
41+
*/
42+
placeholder?: IScript;
43+
/**
44+
* noOptionsMessage - the text to inform that there is no available choice
45+
*/
46+
noOptionsMessage?: IScript;
3947
onVariableChange?: OnVariableChange;
4048
}
4149

@@ -50,6 +58,8 @@ function PlayerSelectInput({
5058
onVariableChange,
5159
pageId,
5260
path,
61+
placeholder,
62+
noOptionsMessage,
5363
}: PlayerSelectInputProps) {
5464
const { somethingIsUndefined } = useInternalTranslate(commonTranslations);
5565
const descriptor = useScript<SStringDescriptor | SNumberDescriptor | string>(
@@ -62,15 +72,19 @@ function PlayerSelectInput({
6272
context,
6373
);
6474

65-
const value = useStore(
66-
() =>
67-
(descriptor != null && typeof descriptor === 'object'
75+
const value = useStore(() => {
76+
const v =
77+
descriptor != null && typeof descriptor === 'object'
6878
? descriptor.getValue(Player.self())
69-
: descriptor) || '',
70-
);
79+
: descriptor;
80+
return v == undefined ? '' : v;
81+
});
7182

7283
const { lang } = React.useContext(languagesCTX);
7384
const { handleOnChange } = useOnVariableChange(onVariableChange, context);
85+
const placeholderText = useScript<string>(placeholder, context) || undefined;
86+
const noOptionsMessageText =
87+
useScript<string>(noOptionsMessage, context) || undefined;
7488

7589
if (descriptor == null) {
7690
return (
@@ -106,6 +120,8 @@ function PlayerSelectInput({
106120
id={id}
107121
value={String(value)}
108122
choices={computedChoices}
123+
placeholder={placeholderText}
124+
noOptionsMessage={noOptionsMessageText}
109125
onChange={v => {
110126
const newValue = v;
111127
if (handleOnChange) {
@@ -154,16 +170,27 @@ registerComponent(
154170
label: 'Choices',
155171
scriptProps: {
156172
language: 'TypeScript',
157-
returnType: ['{label:string, value: string}[]'],
173+
returnType: [
174+
'{label:string, value: string, disabled?: boolean}[] | undefined',
175+
],
158176
},
159177
literalSchema: schemaProps.array({
160178
itemSchema: {
161179
label: schemaProps.string({ label: 'Label' }),
162180
value: schemaProps.string({ label: 'Value' }),
181+
disabled: schemaProps.boolean({ label: 'Disabled' }),
163182
},
164183
}),
165184
},
166185
},
186+
placeholder: schemaProps.scriptString({
187+
label: 'Placeholder',
188+
richText: false,
189+
}),
190+
noOptionsMessage: schemaProps.scriptString({
191+
label: 'No options message',
192+
richText: false,
193+
}),
167194
onVariableChange: onVariableChangeSchema('On text change action'),
168195
...classStyleIdSchema,
169196
},

wegas-app/src/main/node/wegas-react/src/Components/Selector.tsx

+19-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import Select from 'react-select';
44
import CreatableSelect from 'react-select/creatable';
55
import { classNameOrEmpty } from '../Helper/className';
6-
import { commonTranslations } from '../i18n/common/common';
6+
import { componentsTranslations } from '../i18n/components/components';
77
import { useInternalTranslate } from '../i18n/internalTranslator';
88
import { inputStyleCSS } from './Inputs/SimpleInput';
99
import { themeVar } from './Theme/ThemeVars';
@@ -18,6 +18,7 @@ export interface Choice {
1818
};
1919
children?: Choice[];
2020
}
21+
2122
export type Choices = (string | Choice)[];
2223

2324
const selectStyle = css({
@@ -134,6 +135,13 @@ export const selectStyles: SelectProps['styles'] = {
134135
return { ...provided };
135136
}
136137
},
138+
placeholder: (provided) => {
139+
return {
140+
...provided,
141+
color: themeVar.colors.DarkTextColor,
142+
opacity: '0.3',
143+
}
144+
}
137145
};
138146

139147
// interface SelectorProps extends ClassStyleId, DisabledReadonly {
@@ -151,6 +159,8 @@ interface SelectorProps<
151159
DisabledReadonly {
152160
choices: Choices;
153161
value: string | undefined;
162+
placeholder?: string | undefined;
163+
noOptionsMessage?: string | undefined;
154164
onChange?: (value: R) => void;
155165
allowUndefined?: T;
156166
allowAnyValue?: boolean;
@@ -163,15 +173,16 @@ export function Selector<T extends true | false>({
163173
className,
164174
/*style,*/
165175
value,
176+
placeholder,
177+
noOptionsMessage,
166178
onChange,
167179
allowUndefined,
168180
clearable,
169181
allowAnyValue = false,
170182
readOnly,
171183
disabled,
172184
}: SelectorProps<T>): JSX.Element {
173-
const i18nValues = useInternalTranslate(commonTranslations);
174-
const placeholder = i18nValues.plzChooseValue;
185+
const i18nValues = useInternalTranslate(componentsTranslations).select;
175186

176187
const options = buildOptions(choices);
177188

@@ -201,10 +212,13 @@ export function Selector<T extends true | false>({
201212
id={id}
202213
isDisabled={readOnly || disabled}
203214
className={selectStyle + classNameOrEmpty(className)}
215+
classNamePrefix={'wegas-select'}
204216
isClearable={clearable}
205217
options={options}
206-
placeholder={placeholder}
207-
value={currentOption}
218+
placeholder={placeholder ?? i18nValues.plzChooseValue}
219+
noOptionsMessage={() => noOptionsMessage ?? i18nValues.noChoiceInfo}
220+
// Providing an empty object overrides the placeholder
221+
value={currentOption.value?.length === 0 ? null : currentOption}
208222
onChange={onChangeCb}
209223
styles={selectStyles}
210224
menuPosition="fixed"

wegas-app/src/main/node/wegas-react/src/Editor/Components/EntityEditor.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ export function WindowedEditor<T extends IMergeable>({
248248
? (entity as { editorTag?: string }).editorTag
249249
: undefined,
250250
name: getClassLabel(pathEntity),
251+
index: entity
252+
? (entity as { index?: string }).index
253+
: undefined,
251254
})}
252255
</>
253256
}

wegas-app/src/main/node/wegas-react/src/Editor/Components/FormView/FileSelector.tsx

+7-5
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ export function CustomFileSelector<T extends keyof AllowedTypes>({
4242
inputId,
4343
labelNode,
4444
}: CustomFileSelectProps<T>) {
45-
const [currentPath, setCurrentPath] = React.useState<string | undefined>(
46-
value
45+
const [currentPath, setCurrentPath] = React.useState<string | undefined>(undefined);
46+
const [showBrowser, setShowBrowser] = React.useState(false);
47+
48+
React.useEffect(() => {
49+
setCurrentPath(value
4750
? valueType === 'string'
4851
? (value as string)
4952
: generateAbsolutePath(value as IAbstractContentDescriptor)
50-
: undefined,
51-
);
52-
const [showBrowser, setShowBrowser] = React.useState(false);
53+
: undefined);
54+
}, [value, valueType]);
5355

5456
return (
5557
<>

0 commit comments

Comments
 (0)