Skip to content

Commit

Permalink
Merge pull request #2001 from Heigvd/dev
Browse files Browse the repository at this point in the history
Release v3.2.7 (2024.12)
  • Loading branch information
SandraMonnier authored Dec 17, 2024
2 parents ed90c4c + 79a4552 commit 967fb0f
Show file tree
Hide file tree
Showing 31 changed files with 505 additions and 80 deletions.
46 changes: 42 additions & 4 deletions wegas-app/src/main/node/wegas-react/src/API/gameModel.api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
import { managedModeRequest, rest } from './rest';

/** PatchDiff and changes */
interface LineChange {
lineNumber: number;
tag: string;
content: string;
}

interface SideBySideChange {
oldValue: string;
newValue: string;
}

type Change = LineChange | SideBySideChange;

interface DiffCollection {
title: string;
diffs: PatchDiff[];
}

interface PrimitiveDiff {
title: string;
changes: Change[];
}

export type PatchDiff = DiffCollection | PrimitiveDiff;

export const GameModelApi = {
get(gameModelId: number | string) {
return managedModeRequest('/GameModel/' + gameModelId);
Expand All @@ -25,10 +51,22 @@ export const GameModelApi = {
);
},
createExtraTestPlayer(gameModelId: number) {
return managedModeRequest(`/GameModel/${gameModelId}/ExtraTestPlayer`, {
method: 'POST',
});
},
getModelDiff(gameModelId: number | string): Promise<PatchDiff> {
return managedModeRequest(`/GameModel/${gameModelId}/Diff`).then(
res => res.updatedEntities[0] as Promise<PatchDiff>,
);
},
propagateModel(gameModelId: number) {
return managedModeRequest(
`/GameModel/${ gameModelId}/ExtraTestPlayer`,
`/GameModel/${gameModelId}/Propagate`,
{
method: 'POST',
});
}
method: 'PUT',
},
false,
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import * as React from 'react';
import { commonTranslations } from '../../i18n/common/common';
import { useInternalTranslate } from '../../i18n/internalTranslator';
import { CheckBox } from '../Inputs/Boolean/CheckBox';
import {GameModel} from "../../data/selectors";

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

export const defaultFeatures: FeaturesSelecta = {
DEFAULT: true,
ADVANCED: false,
INTERNAL: false,
MODELER: false,
};

export interface FeatureContext {
Expand Down Expand Up @@ -75,6 +77,12 @@ function FeaturesContext({
};
}, [listener]);

React.useEffect(() => {
if (GameModel.selectCurrent().type === 'MODEL') {
toggleFeature('MODELER');
}
}, []);

return (
<featuresCTX.Provider
value={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function ajustVertically(values: ContainerValues) {
return newValues;
}

function ajustVerticalOverlap(values: ContainerValues, parent: HTMLElement) {
function adjustVerticalOverlap(values: ContainerValues, parent: HTMLElement) {
let newTopUp = parent.getBoundingClientRect().top - values.height;
const newTopDown =
parent.getBoundingClientRect().top + parent.getBoundingClientRect().height;
Expand Down Expand Up @@ -127,7 +127,7 @@ function ajustVerticalOverlap(values: ContainerValues, parent: HTMLElement) {
}
}

function ajustHorizontalOverlap(values: ContainerValues, parent: HTMLElement) {
function adjustHorizontalOverlap(values: ContainerValues, parent: HTMLElement) {
let newLeftUp = parent.getBoundingClientRect().left - values.width;
const newLeftDown =
parent.getBoundingClientRect().left + parent.getBoundingClientRect().width;
Expand Down Expand Up @@ -250,9 +250,9 @@ export function justifyDropMenu(
values = ajustVertically(values);

if (vertical && isOverlappingVertically(values, selector)) {
values = ajustVerticalOverlap(values, selector);
values = adjustVerticalOverlap(values, selector);
} else if (!vertical && isOverlappingHorizontally(values, selector)) {
values = ajustHorizontalOverlap(values, selector);
values = adjustHorizontalOverlap(values, selector);
}

menu.style.setProperty('left', values.left + 'px');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const loadingStyle = cx(
);

export const buttonStyle = css({
position: 'relative',
display: 'flex',
alignItems: 'center',
backgroundColor: themeVar.colors.PrimaryColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ interface PlayerSelectInputProps extends WegasComponentProps {
* choices - the allowed choices
*/
choices?: Choice[] | IScript;
/**
* placeholder - the grey text inside the box when nothing is selected
*/
placeholder?: IScript;
/**
* noOptionsMessage - the text to inform that there is no available choice
*/
noOptionsMessage?: IScript;
onVariableChange?: OnVariableChange;
}

Expand All @@ -50,6 +58,8 @@ function PlayerSelectInput({
onVariableChange,
pageId,
path,
placeholder,
noOptionsMessage,
}: PlayerSelectInputProps) {
const { somethingIsUndefined } = useInternalTranslate(commonTranslations);
const descriptor = useScript<SStringDescriptor | SNumberDescriptor | string>(
Expand All @@ -62,15 +72,19 @@ function PlayerSelectInput({
context,
);

const value = useStore(
() =>
(descriptor != null && typeof descriptor === 'object'
const value = useStore(() => {
const v =
descriptor != null && typeof descriptor === 'object'
? descriptor.getValue(Player.self())
: descriptor) || '',
);
: descriptor;
return v == undefined ? '' : v;
});

const { lang } = React.useContext(languagesCTX);
const { handleOnChange } = useOnVariableChange(onVariableChange, context);
const placeholderText = useScript<string>(placeholder, context) || undefined;
const noOptionsMessageText =
useScript<string>(noOptionsMessage, context) || undefined;

if (descriptor == null) {
return (
Expand Down Expand Up @@ -106,6 +120,8 @@ function PlayerSelectInput({
id={id}
value={String(value)}
choices={computedChoices}
placeholder={placeholderText}
noOptionsMessage={noOptionsMessageText}
onChange={v => {
const newValue = v;
if (handleOnChange) {
Expand Down Expand Up @@ -154,16 +170,27 @@ registerComponent(
label: 'Choices',
scriptProps: {
language: 'TypeScript',
returnType: ['{label:string, value: string}[]'],
returnType: [
'{label:string, value: string, disabled?: boolean}[] | undefined',
],
},
literalSchema: schemaProps.array({
itemSchema: {
label: schemaProps.string({ label: 'Label' }),
value: schemaProps.string({ label: 'Value' }),
disabled: schemaProps.boolean({ label: 'Disabled' }),
},
}),
},
},
placeholder: schemaProps.scriptString({
label: 'Placeholder',
richText: false,
}),
noOptionsMessage: schemaProps.scriptString({
label: 'No options message',
richText: false,
}),
onVariableChange: onVariableChangeSchema('On text change action'),
...classStyleIdSchema,
},
Expand Down
24 changes: 19 additions & 5 deletions wegas-app/src/main/node/wegas-react/src/Components/Selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as React from 'react';
import Select from 'react-select';
import CreatableSelect from 'react-select/creatable';
import { classNameOrEmpty } from '../Helper/className';
import { commonTranslations } from '../i18n/common/common';
import { componentsTranslations } from '../i18n/components/components';
import { useInternalTranslate } from '../i18n/internalTranslator';
import { inputStyleCSS } from './Inputs/SimpleInput';
import { themeVar } from './Theme/ThemeVars';
Expand All @@ -18,6 +18,7 @@ export interface Choice {
};
children?: Choice[];
}

export type Choices = (string | Choice)[];

const selectStyle = css({
Expand Down Expand Up @@ -134,6 +135,13 @@ export const selectStyles: SelectProps['styles'] = {
return { ...provided };
}
},
placeholder: (provided) => {
return {
...provided,
color: themeVar.colors.DarkTextColor,
opacity: '0.3',
}
}
};

// interface SelectorProps extends ClassStyleId, DisabledReadonly {
Expand All @@ -151,6 +159,8 @@ interface SelectorProps<
DisabledReadonly {
choices: Choices;
value: string | undefined;
placeholder?: string | undefined;
noOptionsMessage?: string | undefined;
onChange?: (value: R) => void;
allowUndefined?: T;
allowAnyValue?: boolean;
Expand All @@ -163,15 +173,16 @@ export function Selector<T extends true | false>({
className,
/*style,*/
value,
placeholder,
noOptionsMessage,
onChange,
allowUndefined,
clearable,
allowAnyValue = false,
readOnly,
disabled,
}: SelectorProps<T>): JSX.Element {
const i18nValues = useInternalTranslate(commonTranslations);
const placeholder = i18nValues.plzChooseValue;
const i18nValues = useInternalTranslate(componentsTranslations).select;

const options = buildOptions(choices);

Expand Down Expand Up @@ -201,10 +212,13 @@ export function Selector<T extends true | false>({
id={id}
isDisabled={readOnly || disabled}
className={selectStyle + classNameOrEmpty(className)}
classNamePrefix={'wegas-select'}
isClearable={clearable}
options={options}
placeholder={placeholder}
value={currentOption}
placeholder={placeholder ?? i18nValues.plzChooseValue}
noOptionsMessage={() => noOptionsMessage ?? i18nValues.noChoiceInfo}
// Providing an empty object overrides the placeholder
value={currentOption.value?.length === 0 ? null : currentOption}
onChange={onChangeCb}
styles={selectStyles}
menuPosition="fixed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ export function WindowedEditor<T extends IMergeable>({
? (entity as { editorTag?: string }).editorTag
: undefined,
name: getClassLabel(pathEntity),
index: entity
? (entity as { index?: string }).index
: undefined,
})}
</>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ export function CustomFileSelector<T extends keyof AllowedTypes>({
inputId,
labelNode,
}: CustomFileSelectProps<T>) {
const [currentPath, setCurrentPath] = React.useState<string | undefined>(
value
const [currentPath, setCurrentPath] = React.useState<string | undefined>(undefined);
const [showBrowser, setShowBrowser] = React.useState(false);

React.useEffect(() => {
setCurrentPath(value
? valueType === 'string'
? (value as string)
: generateAbsolutePath(value as IAbstractContentDescriptor)
: undefined,
);
const [showBrowser, setShowBrowser] = React.useState(false);
: undefined);
}, [value, valueType]);

return (
<>
Expand Down
Loading

0 comments on commit 967fb0f

Please sign in to comment.