Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/5868 right sidebar #5930

Merged
merged 28 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0f622e3
add right sidebar
matborowczyk Aug 30, 2024
6b95c8e
Merge branch 'master' of github.com:inmanta/web-console into issue/58…
matborowczyk Sep 2, 2024
04c3484
e2e + test fix + improvements
matborowczyk Sep 3, 2024
cb1ee3b
e2e fix
matborowczyk Sep 3, 2024
c6c187a
test fix
matborowczyk Sep 4, 2024
bd49654
tsc fix
matborowczyk Sep 5, 2024
8bf5c32
add rendering of parents from the children perspective + block editin…
matborowczyk Sep 5, 2024
3bcf106
Merge branch 'master' of github.com:inmanta/web-console into issue/58…
matborowczyk Sep 5, 2024
e6c6f02
Merge branch 'issue/composer-v2' of github.com:inmanta/web-console in…
matborowczyk Sep 5, 2024
96225d6
e2e + tests + fixes
matborowczyk Sep 10, 2024
12fc477
test fix
matborowczyk Sep 10, 2024
4b1b27f
fix
matborowczyk Sep 10, 2024
8760013
test + initial remarks
matborowczyk Sep 23, 2024
3550374
Merge branch 'issue/composer-v2' of github.com:inmanta/web-console in…
matborowczyk Sep 23, 2024
fac2192
Merge branch 'master' of github.com:inmanta/web-console into issue/58…
matborowczyk Sep 27, 2024
9c2bb5b
add back the lacking logic for parent-children relations, path-to-reg…
matborowczyk Oct 7, 2024
c9f8676
remarks + improvements
matborowczyk Oct 7, 2024
2d2b34f
Merge branch 'issue/composer-v2' of github.com:inmanta/web-console in…
matborowczyk Oct 9, 2024
588bde2
Merge branch 'issue/composer-v2' of github.com:inmanta/web-console in…
matborowczyk Oct 11, 2024
5386b55
tsc fix
matborowczyk Oct 11, 2024
b41550e
improve docstrings
matborowczyk Oct 14, 2024
68fe7cb
improve comments/docstrings
matborowczyk Oct 15, 2024
dede34a
test improvement, fix relations render
matborowczyk Oct 15, 2024
8b7fc7d
fix e2e doubling connections
matborowczyk Oct 15, 2024
19f813c
test fix
matborowczyk Oct 15, 2024
710a5ba
Update cypress/e2e/scenario-8-instance-composer.cy.js
matborowczyk Oct 15, 2024
5043a03
Update cypress/e2e/scenario-8-instance-composer.cy.js
matborowczyk Oct 15, 2024
7a64451
Update cypress/e2e/scenario-8-instance-composer.cy.js
matborowczyk Oct 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelogs/unreleased/5938-dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
change-type: patch
description: 'Build(deps-dev): Bump eslint-plugin-testing-library from 6.2.2 to 6.3.0'
destination-branches:
- master
sections: {}
1,197 changes: 437 additions & 760 deletions cypress/e2e/scenario-8-instance-composer.cy.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"eslint-plugin-prettier": "5.2.1",
"eslint-plugin-react": "^7.35.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-testing-library": "^6.2.2",
"eslint-plugin-testing-library": "^6.3.0",
"fetch-mock": "^9.11.0",
"file-loader": "^6.2.0",
"git-revision-webpack-plugin": "^5.0.0",
Expand Down
1 change: 1 addition & 0 deletions src/Core/Domain/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type FieldLikeWithFormState = Field;
interface BaseField {
name: string;
description?: string;
id?: string;
isOptional: boolean;
isDisabled: boolean;
suggestion?: FormSuggestion | null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { UseQueryResult, useQuery } from "@tanstack/react-query";
import { ServiceInstanceModel } from "@/Core";
import {
EmbeddedEntity,
InstanceAttributeModel,
ServiceInstanceModel,
ServiceModel,
} from "@/Core";
import { PrimaryBaseUrlManager } from "@/UI";
import { useFetchHelpers } from "../helpers";

Expand Down Expand Up @@ -28,6 +33,7 @@ interface GetInstanceWithRelationsHook {
*/
export const useGetInstanceWithRelations = (
instanceId: string,
serviceModel: ServiceModel | undefined,
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
environment: string,
): GetInstanceWithRelationsHook => {
//extracted headers to avoid breaking rules of Hooks
Expand Down Expand Up @@ -61,6 +67,63 @@ export const useGetInstanceWithRelations = (
return await response.json();
};

const getAllRelations = (
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
serviceModel: ServiceModel | EmbeddedEntity,
): string[] => {
const relations =
serviceModel.inter_service_relations?.map((relation) => relation.name) ||
[];

const nestedRelations = serviceModel.embedded_entities?.flatMap((entity) =>
getAllRelations(entity),
);

return [...relations, ...nestedRelations];
};

const getAllEmbeddedEntities = (
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
serviceModel: ServiceModel | EmbeddedEntity,
): string[] => {
const embedded = serviceModel.embedded_entities.map(
(entity) => entity.name,
);
const nestedEmbedded = serviceModel.embedded_entities?.flatMap((entity) =>
getAllEmbeddedEntities(entity),
);

return [...embedded, ...nestedEmbedded];
};

const findAllRelatedIds = (
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
attributes: InstanceAttributeModel,
relationNames: string[],
embeddedNames: string[],
): string[] => {
const relationIDs = relationNames.map(
(relationName) => (attributes[relationName] as string) || "",
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
);

const embeddedRelationsIDs = embeddedNames.flatMap((embeddedName) => {
if (!attributes[embeddedName]) {
return "";
}
if (Array.isArray(attributes[embeddedName])) {
return (attributes[embeddedName] as InstanceAttributeModel[]).flatMap(
(embedded) =>
findAllRelatedIds(embedded, relationNames, embeddedNames),
);
} else {
return findAllRelatedIds(
attributes[embeddedName] as InstanceAttributeModel,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid repetitive casting, you can assign the value to a variable and type the variable instead.

relationNames,
embeddedNames,
);
}
});

return [...relationIDs, ...embeddedRelationsIDs];
};

/**
* Fetches a service instance with its related instances.
* @param {string} id - The ID of the instance to fetch.
Expand All @@ -70,21 +133,38 @@ export const useGetInstanceWithRelations = (
const fetchInstances = async (id: string): Promise<InstanceWithRelations> => {
const relatedInstances: ServiceInstanceModel[] = [];
const instance = (await fetchInstance(id)).data;
let serviceIDs: string[] = [];
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved

if (instance.referenced_by !== null) {
await Promise.all(
instance.referenced_by.map(async (relatedId) => {
const relatedInstance = await fetchInstance(relatedId);

if (relatedInstance) {
relatedInstances.push(relatedInstance.data);
}
if (serviceModel) {
const whatAttributesToFetch = getAllRelations(serviceModel);
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
const uniqueAttributes = [...new Set(whatAttributesToFetch)];
const allEmbedded = getAllEmbeddedEntities(serviceModel);
const attributes =
instance.active_attributes || instance.candidate_attributes || {}; //we don't operate on rollback attributes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have a reason why, I personally don't remember why we don't operate on the rollback attributes in the composer, while we do in the expert mode or form for example

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point it was told by Bart that there is no need to display rollback attributes, that's why don't have icon for them as well


return relatedInstance;
}),
);
serviceIDs = [
...new Set(
findAllRelatedIds(attributes, uniqueAttributes, allEmbedded),
),
].filter((id) => id !== "");
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
}

const allIDs = [
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
...new Set([...serviceIDs, ...(instance.referenced_by || [])]),
];

await Promise.all(
allIDs.map(async (relatedId) => {
const relatedInstance = await fetchInstance(relatedId);

if (relatedInstance) {
relatedInstances.push(relatedInstance.data);
}

return relatedInstance;
}),
);

return {
instance,
relatedInstances,
Expand All @@ -105,6 +185,7 @@ export const useGetInstanceWithRelations = (
],
queryFn: () => fetchInstances(instanceId),
retry: false,
enabled: serviceModel !== undefined,
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
}),
useContinuous: (): UseQueryResult<InstanceWithRelations, Error> =>
useQuery({
Expand All @@ -115,6 +196,7 @@ export const useGetInstanceWithRelations = (
],
queryFn: () => fetchInstances(instanceId),
refetchInterval: 5000,
enabled: serviceModel !== undefined,
matborowczyk marked this conversation as resolved.
Show resolved Hide resolved
}),
};
};
2 changes: 1 addition & 1 deletion src/Slices/CompileDetails/Core/Mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const data: CompileDetails = {
started: "2021-09-10T09:05:25.000000",
completed: "2021-09-10T09:05:30.000000",
command:
"/opt/inmanta/bin/python3 -m inmanta.app -vvv export -X -e f7e84432-855c-4d04-b422-50c3ab925a4a",
"/opt/inmanta/bin/python3 -m inmanta.app -vvv export -e f7e84432-855c-4d04-b422-50c3ab925a4a",
name: "Recompiling configuration model",
errstream: "error",
outstream: "success",
Expand Down
16 changes: 7 additions & 9 deletions src/UI/Components/Diagram/Canvas.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ const setup = (
instance: instance || null,
serviceModels,
mainService: mainService,
relatedInventories: {} as UseQueryResult<Inventories, Error>,
relatedInventories: { data: {} } as UseQueryResult<
Inventories,
Error
>,
}}
>
<CanvasProvider>
Expand Down Expand Up @@ -284,16 +287,12 @@ beforeAll(() => {
// });

it("renders shapes dict Value that can be viewed in dict Modal", async () => {
const component = setup(mockedInstanceTwoServiceModel, mockedInstanceTwo, []);
const component = setup(mockedInstanceTwoServiceModel, mockedInstanceTwo, [
mockedInstanceTwoServiceModel,
]);

render(component);

const button = await screen.findByJointSelector("toggleButton");

await act(async () => {
await user.click(button);
});

const dictValue = await screen.findByJointSelector("itemLabel_dictOne_value");

await act(async () => {
Expand Down Expand Up @@ -324,7 +323,6 @@ it("renders shapes dict Value that can be viewed in dict Modal", async () => {
const blob = await clipboardItems[0].getType(clipboardItems[0].types[0]);
const clipboardText = await blob.text();

console.log(clipboardText);
expect(clipboardText).toEqual("{}");

const closeButton = await screen.findByLabelText("Close");
Expand Down
Loading