Skip to content

Commit

Permalink
fix (#7457)
Browse files Browse the repository at this point in the history
* fix

* rebuild backend

* revert

* resolve processDefinitionData reference issue

* remove FE sorting of processDefinitionData

* Sort classes on BE

---------

Co-authored-by: Łukasz Bigorajski <[email protected]>
  • Loading branch information
Dzuming and Łukasz Bigorajski authored Jan 18, 2025
1 parent 0ff5d03 commit 0a840b4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getProcessDefinitionData } from "../../../../reducers/selectors/setting
import { MapVariableProps } from "../MapVariable";
import { NodeCommonDetailsDefinition } from "../NodeCommonDetailsDefinition";
import { FieldsSelect } from "./FieldsSelect";
import { find, head, orderBy } from "lodash";
import { find, head } from "lodash";
import { getDefaultFields } from "./item/utils";
import { FragmentInputParameter } from "./item";

Expand All @@ -26,11 +26,9 @@ export function useFragmentInputDefinitionTypeOptions() {
[definitionData?.classes],
);

const orderedTypeOptions = useMemo(() => orderBy(typeOptions, (item) => [item.label, item.value], ["asc"]), [typeOptions]);

const defaultTypeOption = useMemo(() => find(typeOptions, { label: "String" }) || head(typeOptions), [typeOptions]);
return {
orderedTypeOptions,
typeOptions,
defaultTypeOption,
};
}
Expand All @@ -40,7 +38,7 @@ export default function FragmentInputDefinition(props: Props): JSX.Element {
const { node, setProperty, isEditMode, showValidation } = passProps;

const readOnly = !isEditMode;
const { orderedTypeOptions, defaultTypeOption } = useFragmentInputDefinitionTypeOptions();
const { typeOptions, defaultTypeOption } = useFragmentInputDefinitionTypeOptions();

const addField = useCallback(() => {
addElement("parameters", getDefaultFields(defaultTypeOption.value));
Expand All @@ -57,7 +55,7 @@ export default function FragmentInputDefinition(props: Props): JSX.Element {
removeField={removeElement}
namespace={"parameters"}
fields={fields}
options={orderedTypeOptions}
options={typeOptions}
showValidation={showValidation}
readOnly={readOnly}
variableTypes={variableTypes}
Expand Down
11 changes: 8 additions & 3 deletions designer/client/src/reducers/selectors/settings.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { createSelector } from "reselect";
import { createSelector, createSelectorCreator, defaultMemoize } from "reselect";
import { MetricsType } from "../../actions/nk";
import { DynamicTabData } from "../../containers/DynamicTab";
import { ComponentGroup, ProcessDefinitionData } from "../../types";
import { RootState } from "../index";
import { AuthenticationSettings, SettingsState } from "../settings";
import { uniqBy } from "lodash";
import { isEqual, uniqBy } from "lodash";

const createDeepEqualSelector = createSelectorCreator(defaultMemoize, isEqual);

export const getSettings = (state: RootState): SettingsState => state.settings;

Expand All @@ -17,7 +19,10 @@ export const getSurveySettings = createSelector(getFeatureSettings, (s) => s?.su
export const getStickyNotesSettings = createSelector(getFeatureSettings, (s) => s?.stickyNotesSettings);
export const getLoggedUser = createSelector(getSettings, (s) => s.loggedUser);
export const getLoggedUserId = createSelector(getLoggedUser, (s) => s.id);
export const getProcessDefinitionData = createSelector(getSettings, (s) => s.processDefinitionData || ({} as ProcessDefinitionData));
export const getProcessDefinitionData = createDeepEqualSelector(
getSettings,
(s) => s.processDefinitionData || ({} as ProcessDefinitionData),
);
export const getComponentGroups = createSelector(getProcessDefinitionData, (p) => p.componentGroups || ({} as ComponentGroup[]));
export const getCategories = createSelector(getLoggedUser, (u) => u.categories || []);
export const getWritableCategories = createSelector(getLoggedUser, getCategories, (user, categories) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import pl.touk.nussknacker.engine.definition.component.{ComponentStaticDefinitio
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap
import pl.touk.nussknacker.engine.ModelData
import pl.touk.nussknacker.engine.api.TemplateEvaluationResult
import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypingResult}
import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypedClass, TypingResult}
import pl.touk.nussknacker.restmodel.definition._
import pl.touk.nussknacker.ui.definition.DefinitionsService.{
ComponentUiConfigMode,
Expand Down Expand Up @@ -106,7 +106,13 @@ class DefinitionsService(
UIDefinitions(
componentGroups = ComponentGroupsPreparer.prepareComponentGroups(components),
components = components.map(component => component.component.id -> createUIComponentDefinition(component)).toMap,
classes = modelData.modelDefinitionWithClasses.classDefinitions.all.toList.map(_.clazzName),
classes = modelData.modelDefinitionWithClasses.classDefinitions.all.toList
.map(_.clazzName)
.filter {
case t: TypedClass if t.klass.isArray => false
case _ => true
}
.sortBy(_.display.toLowerCase),
scenarioProperties = {
if (forFragment) {
createUIProperties(FragmentPropertiesConfig.properties ++ fragmentPropertiesConfig, fragmentPropertiesDocsUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.scalatest.{BeforeAndAfterAll, BeforeAndAfterEach, OptionValues}
import pl.touk.nussknacker.engine.api.CirceUtil.RichACursor
import pl.touk.nussknacker.engine.api.definition.FixedExpressionValue
import pl.touk.nussknacker.engine.api.parameter.{ParameterName, ValueInputWithFixedValuesProvided}
import pl.touk.nussknacker.engine.api.typed.typing.{Typed, TypingResult, Unknown}
import pl.touk.nussknacker.engine.api.{FragmentSpecificData, MetaData}
import pl.touk.nussknacker.engine.canonicalgraph.canonicalnode.FlatNode
import pl.touk.nussknacker.engine.canonicalgraph.{CanonicalProcess, canonicalnode}
Expand Down Expand Up @@ -103,6 +104,20 @@ class DefinitionResourcesSpec
}
}

it("should return definition sorted data for allowed classes - skipping array because list should be uses instead") {
getProcessDefinitionData() ~> check {
status shouldBe StatusCodes.OK

val allowedClasses = responseAs[Json].hcursor.downField("classes").focus.value.asArray.value
val allowedClassesRefClazzNames = allowedClasses.flatMap(_.hcursor.downField("refClazzName").focus.value.asString)
val allowedClassesDisplay = allowedClasses.flatMap(_.hcursor.downField("display").focus.value.asString)

allowedClassesRefClazzNames should contain("java.util.List")
allowedClassesRefClazzNames should not contain (Array().getClass.getName)
allowedClassesDisplay shouldBe allowedClassesDisplay.sortBy(_.toLowerCase)
}
}

it("should return info about editor based on fragment parameter definition") {
val fragmentWithFixedValuesEditor = {
CanonicalProcess(
Expand Down

0 comments on commit 0a840b4

Please sign in to comment.