Skip to content

Commit

Permalink
added pool on relationship hierarchical
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalabbad committed Mar 3, 2025
1 parent d571110 commit c1c72e8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { POOLS_PEER } from "@/entities/ipam/constants";
import { RelationshipNode } from "@/entities/nodes/relationships/domain/types";
import {
RelationshipHierarchicalInput,
RelationshipHierarchicalManyInput,
} from "@/entities/nodes/relationships/ui/relationship-hierarchical-input";
import { useSchema } from "@/entities/schema/ui/hooks/useSchema";
import { DEFAULT_FORM_FIELD_VALUE } from "@/shared/components/form/constants";
import { LabelFormField } from "@/shared/components/form/fields/common";
import { PoolValue } from "@/shared/components/form/pool-selector";
import {
DynamicRelationshipFieldProps,
FormRelationshipValue,
} from "@/shared/components/form/type";
import { updateRelationshipFieldValue } from "@/shared/components/form/utils/updateFormFieldValue";
import { PoolSelect } from "@/shared/components/inputs/pool-select";
import { FormField, FormInput, FormMessage } from "@/shared/components/ui/form";

export interface RelationshipHierarchicalFieldProps
Expand All @@ -32,6 +36,16 @@ export default function RelationshipHierarchicalField({
render={({ field }) => {
const fieldData: FormRelationshipValue = field.value;

const peer = props.relationship.peer;
const { schema, isNode } = useSchema(peer);
const canSelectFromPool =
isNode && !!schema.inherit_from?.some((from) => POOLS_PEER.includes(from));
const selectedPoolId = fieldData?.source?.type === "pool" ? fieldData.source.id : null;

const onChange = (newValue: RelationshipNode | RelationshipNode[] | PoolValue | null) => {
field.onChange(updateRelationshipFieldValue(newValue, defaultValue));
};

return (
<div className="flex flex-col gap-2">
<LabelFormField
Expand All @@ -42,27 +56,28 @@ export default function RelationshipHierarchicalField({
fieldData={fieldData}
/>

<FormInput>
{props.relationship.cardinality === "many" ? (
<RelationshipHierarchicalManyInput
{...field}
peer={props.relationship.peer}
value={fieldData.value as RelationshipNode[] | null}
onChange={(newValue) => {
field.onChange(updateRelationshipFieldValue(newValue, defaultValue));
}}
/>
) : (
<RelationshipHierarchicalInput
{...field}
peer={props.relationship.peer}
value={fieldData.value as RelationshipNode | null}
onChange={(newValue) => {
field.onChange(updateRelationshipFieldValue(newValue, defaultValue));
}}
/>
<div className="flex gap-2">
<FormInput>
{props.relationship.cardinality === "many" ? (
<RelationshipHierarchicalManyInput
{...field}
peer={peer}
value={fieldData.value as RelationshipNode[] | null}
onChange={onChange}
/>
) : (
<RelationshipHierarchicalInput
{...field}
peer={props.relationship.peer}
value={fieldData.value as RelationshipNode | null}
onChange={onChange}
/>
)}
</FormInput>
{canSelectFromPool && (
<PoolSelect peer={peer} selectedPoolId={selectedPoolId} onChange={onChange} />
)}
</FormInput>
</div>

<FormMessage />
</div>
Expand Down
1 change: 1 addition & 0 deletions frontend/app/tests/e2e/objects/object-groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ test.describe("Object groups update", () => {
await page.getByLabel("Add groups *").click(); // to close the combobox
await page.getByRole("button", { name: "Save" }).click();
await expect(page.getByText("2 groups added")).toBeVisible();
await expect(page.getByText("2 groups added")).toBeHidden();
});

await test.step("auto-generated toggle button not visible if there is no auto-generated groups", async () => {
Expand Down

0 comments on commit c1c72e8

Please sign in to comment.