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

refactor(web): use queries to handle iSCSI configuration #1598

Merged
merged 17 commits into from
Sep 13, 2024

Conversation

imobachgs
Copy link
Contributor

@imobachgs imobachgs commented Sep 12, 2024

Trello: https://trello.com/c/MsGbqiwA/

This is a follow-up of #1585 which adapts the iSCSI-related code to use queries instead of the regular Agama client. Additionally, it converts a good share of the code to TypeScript and adds some iSCSI tests, that were not included in the first version.

@coveralls
Copy link

coveralls commented Sep 12, 2024

Coverage Status

coverage: 71.796% (-0.007%) from 71.803%
when pulling 684d796 on iscsi-queries
into 8900663 on master.

@imobachgs imobachgs marked this pull request as ready for review September 12, 2024 15:41
* Sets the startup status of the connection
*
* @param node - ISCSI node
* @param startup - startup status
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, startup is string, so it can accept any value? or is it kind of enum with limited statuses?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a generic string. I do not like it that much, but I decided to keep it as it was, considering it was out of this PR's scope. But sure we should improve how we handle the staus.

}));

jest.mock("~/api/storage/iscsi", () => ({
...jest.requireActual("~/queries/storage/iscsi"),
Copy link
Contributor

Choose a reason for hiding this comment

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

is there reason to load rest of queries? Cannot it do some backend communication? I am asking this in all those mock that include also requireActual

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For no particular reason. I like to keep the original mode and mock only those functions that the test will use.

Copy link
Contributor

Choose a reason for hiding this comment

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

The part that worry me is that it can cause accidental communication with backend...if it is not there, it will immediatelly fail in test, not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the test will fail in either case.

export default function TargetsSection() {
const [isDiscoverFormOpen, setIsDiscoverFormOpen] = useState<boolean>(false);
const nodes = useNodes();
useNodesChanges();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there some changes done in changes queries? Previously it returns query. So it can be written like const nodes = useNodesChanges(); . And it is still done this way e.g. in DASD, but in others where it was before I do not see it anymore. ( e.g. https://github.com/openSUSE/agama/blob/master/web/src/queries/dasd.ts#L121 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, that's an interesting topic. We usually have separate hooks for retrieving the query and subscribing to changes. DASD handling is the only place where is done differently. DASD hooks 1) retrieve the value and 2) subscribe to the changes. So, if you use the useDASDFormatJobsChanges in more than one place, you are subscribing twice. In this particular case, the JobAdded event will not be handled correctly (that's easy to fix).

Let's consider that our DASD formats progress is not blocking (we discussed that during the review), and you want to add a counter to the pending jobs. Then you might want to access that query from your counter, too. And then, you will find the problem mentioned above.

Having two different hooks (useIssues and useIssuesChanges) might be a problem too. You need to be sure that the changes hooks are used at least at the same level as the query hook. That's why most changes hooks are called from the App component.

Finally, something we need to fix, is adapting all those changes queries to not update the query if it is not defined. I did that correctly (I think) in this pull request, but we might need to fix others.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps I should move the call to useNodesChanges to the App level.

web/src/api/storage.ts Outdated Show resolved Hide resolved
web/src/api/storage/iscsi.ts Outdated Show resolved Hide resolved
web/src/components/storage/iscsi/InitiatorPresenter.tsx Outdated Show resolved Hide resolved
web/src/components/storage/iscsi/TargetsSection.tsx Outdated Show resolved Hide resolved
web/src/queries/storage/iscsi.ts Outdated Show resolved Hide resolved
imobachgs and others added 2 commits September 13, 2024 06:07
Co-authored-by: David Díaz <1691872+dgdavid@users.noreply.github.com>
Copy link
Contributor

@dgdavid dgdavid left a comment

Choose a reason for hiding this comment

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

👍

@imobachgs imobachgs merged commit 04bd65a into master Sep 13, 2024
3 checks passed
@imobachgs imobachgs deleted the iscsi-queries branch September 13, 2024 09:02
@imobachgs imobachgs mentioned this pull request Sep 20, 2024
imobachgs added a commit that referenced this pull request Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants