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: replaced layout context to zustand layout store #38

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

void-hr
Copy link
Contributor

@void-hr void-hr commented Oct 16, 2024

This PR resolves issue #31

  • removed layout.ts from hooks
  • changed are made only for zustand layout store

Let me know, if this will work or I'll ammend changes as mentioned

@gvieira18 gvieira18 requested a review from Daniel-Boll October 16, 2024 12:29
Copy link
Collaborator

@Daniel-Boll Daniel-Boll left a comment

Choose a reason for hiding this comment

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

It LGTM, I'll clone and run to test it out in a minute. Then I'll approve.

@Daniel-Boll Daniel-Boll added good first issue Good for newcomers hacktoberfest-accepted Hacktoberfest-able PR refactor Refactoring existing code labels Oct 16, 2024
@DanielHe4rt DanielHe4rt self-requested a review October 16, 2024 13:56
Copy link
Contributor

@DanielHe4rt DanielHe4rt left a comment

Choose a reason for hiding this comment

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

There's probably a simple bug there to solve. All the other features works smoothly!

Btw, thanks for the contribution.

Comment on lines 34 to 42
const keyspaces = useLayout((state) => state.keyspaces);
const connections = useLayout((state) => state.connections);
const setSelectedConnection = useLayout(
(state) => state.setSelectedConnection,
);
const selectedConnection = useLayout((state) => state.selectedConnection);
Copy link
Contributor

Choose a reason for hiding this comment

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

Somehow this feature isn't working for me.

I took a look on the CQL Editor and how it's currently being used and I saw that maybe your implementation didn't fulfilled the feature needs.

At the Result Filters (result-filters.tsx), you can fetch all the data and pass it to the Select Input but the same isn't true for Connections Menu List.

const fetchConnectionsAction = useAction(fetchConnections, {
    onSuccess: ({ data }) => {
      setAvailableConnections(data ?? []);
      setCurrentConnection(data?.[0] ?? null);
    },
    onError: ({ error }) => {
      console.error("[ResultFilters.fetchConnectionsAction]", error);
    },
  });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking forward to actively contribute. Actually I do not have clear idea about the web app or our scylla studio yet.

I'll try to figure out what's going wrong 👀

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DanielHe4rt, continuing to the expected behaviour basically it should show list of all connection in menu select ?

Like this?
image

Copy link
Contributor

Choose a reason for hiding this comment

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

Just like that!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can you confirm this feature is working after adding connection followed by page refresh?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Daniel-Boll could you please check it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was in high demands. I will try to give it a look tomorrow guys.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll give it a look now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry by the delay on the feedback. So:

Now that you probably have a ScyllaDB Database running in your local environment, would be a good thing if you check-out and see the default behavior.

What we expect is that the connection selected triggers the Database SubMenus loading, not pop the update modal.

@void-hr
Copy link
Contributor Author

void-hr commented Oct 17, 2024

Hey, can we update the docs for local setup via docker ? And at unable to access connection.db is it related to my local setup ?

@Daniel-Boll
Copy link
Collaborator

After pruning my Docker images and following the steps in the README again, I managed to run it successfully. What issues are you encountering?

@void-hr
Copy link
Contributor Author

void-hr commented Oct 17, 2024

Just trying this command to run scylla studio via docker

 docker run --name scylla --network ws-scylla -p "9042:9042" -d scylladb/scylla:6.1.2 \
  --overprovisioned 1 \
  --smp 1

localhost:3000 shows This site can't be reached

@Daniel-Boll
Copy link
Collaborator

Daniel-Boll commented Oct 17, 2024

Just trying this command to run scylla studio via docker

 docker run --name scylla --network ws-scylla -p "9042:9042" -d scylladb/scylla:6.1.2 \
  --overprovisioned 1 \
  --smp 1

localhost:3000 shows This site can't be reached

Oh, no. This docker command is to run a local ScyllaDB instance (which you also need). The Scylla Studio docker command itself may be found a little bellow in the README.

docker run --rm --name scylla-studio --network="host" ghcr.io/basementdevs/scylla-studio:latest

@void-hr
Copy link
Contributor Author

void-hr commented Oct 17, 2024

Just trying this command to run scylla studio via docker

 docker run --name scylla --network ws-scylla -p "9042:9042" -d scylladb/scylla:6.1.2 \
  --overprovisioned 1 \
  --smp 1

localhost:3000 shows This site can't be reached

Oh, no. This docker command is to run a local ScyllaDB instance (which you also need). The Scylla Studio docker command itself may be found a little bellow in the README.

docker run --rm --name scylla-studio --network="host" ghcr.io/basementdevs/scylla-studio:latest

Sorry, I was pasting the later one the command that you have shared but ended up pasting the above one (by mistake).

image
localhost:3000
image

@void-hr
Copy link
Contributor Author

void-hr commented Oct 17, 2024

Also I am on windows, also tried it on wsl but getting same res localhost refused to connect

@Daniel-Boll
Copy link
Collaborator

Try changing the command to something like this:

docker run --rm -p 3000:3000 --name scylla-studio --network="ws-scylla" ghcr.io/basementdevs/scylla-studio:latest

Directly connection to scylla's db may help, but you will have to add a connection based on the IP of the ws-scylla docker network to the container of scylladb.

docker network inspect ws-scylla | jq ".[0].Containers"

find the scylla container and get it's ip e.g. 172.19.0.2 then you call add a connection to the DB using something like: 172.19.0.2:9042

This is a solution I think may work, but it's pretty much a workaround the default way as I cannot understand why it's not working in your case.

@void-hr
Copy link
Contributor Author

void-hr commented Oct 17, 2024

Also I am on windows, also tried it on wsl but getting same res localhost refused to connect

Update : I mapped port manually in the command itself and now it is working fine!

docker run --rm --name scylla-studio -p 3000:3000 ghcr.io/basementdevs/scylla-studio:latest

docker network inspect ws-scylla | jq ".[0].Containers"

If i only talk about localhost:3000 manually mapping port in existing command is working fine! Thanks a lot

@void-hr
Copy link
Contributor Author

void-hr commented Oct 17, 2024

@Daniel-Boll thanks, this look cool

image

@DanielHe4rt
Copy link
Contributor

@void-hr Did you pushed the latest changes?

@void-hr
Copy link
Contributor Author

void-hr commented Oct 22, 2024

@void-hr Did you pushed the latest changes?

No, I was waiting for confirmation if on hard refresh it is showing all connection in menu lists, so no need to push latest changes since it is of no use. Actually menu list should update without hard refresh when adding connection but I am not able to figure out how we can achieve that. Used useEffect also with dependencies like connections and all but it is not working as expected.

I am not sure but maybe we have to update the state on adding connection in modal.tsx

const handleSave = (data: z.infer<typeof formSchema>) => {
    startTransition(async () => {
      await onSave(data);
      setOpen(false);
    });
  };

@DanielHe4rt
Copy link
Contributor

@void-hr push a wip so we can help you with that. Maybe @Matozinho or @Daniel-Boll could help you with that.

@void-hr
Copy link
Contributor Author

void-hr commented Oct 22, 2024

@void-hr push a wip so we can help you with that. Maybe @Matozinho or @Daniel-Boll could help you with that.

Sure!

@Matozinho
Copy link
Collaborator

Hey @void-hr. I tested the code here and I found some issues.

  • The NewConnectionModal is opening in weird moments
  • The New Connection button opens the modal with the data to edit, so we couldn't add a new connection.
  • The keyspaces are not fetched due to the queryKeyspace being called nowhere
problems_demo.mp4

And I was running at the latest commit on your main:
image

Comment on lines 67 to 77
useEffect(() => {
if (selectedConnection) {
queryKeyspace.execute({
fetchInitialConnections: async () => {
try {
const initialConnections = await fetchConnections();
if (
JSON.stringify(get().connections) !== JSON.stringify(initialConnections)
) {
startTransition(() => {
set({ connections: initialConnections });
});
}
} catch (error) {
console.error("Error fetching connections:", error);
toast.error("Failed to fetch connections.");
}
},

queryKeyspace: async (selectedConnection) => {
try {
const queryKeyspace = await queryKeyspaceAction({
host: selectedConnection.host,
port: selectedConnection.port,
password: selectedConnection.password,
username: selectedConnection.username,
});
return queryKeyspace;
} catch (error) {
console.error(error);
toast.error("Failed to query keyspaces.");
get().setSelectedConnection(undefined);
throw error;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [queryKeyspace.execute, selectedConnection]);
Copy link
Collaborator

@Matozinho Matozinho Oct 26, 2024

Choose a reason for hiding this comment

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

The problem of removing the useEffect is that the keyspaces are not fetched anymore. Neither the initial connections (the useEffect above this one)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure will let you know!

@void-hr
Copy link
Contributor Author

void-hr commented Oct 26, 2024

Noted! Work is in progress, trying to debug. Also can you please confirm that adding console log statements are working or not.

@Matozinho
Copy link
Collaborator

Noted! Work is in progress, trying to debug. Also can you please confirm that adding console log statements are working or not.

They are, but depending on the file they will appear on the terminal, not the browser.

@void-hr
Copy link
Contributor Author

void-hr commented Oct 28, 2024

@Matozinho can you take a look again?

@DanielHe4rt
Copy link
Contributor

@Matozinho can you take a look again?

We will take a look on that today after our working hours. Thanks again for keep the contributions!

Btw, we added an Discord Channel recently. If you have any interest, feel free to join us: https://discord.gg/ShwwggRU

Copy link
Contributor

@DanielHe4rt DanielHe4rt left a comment

Choose a reason for hiding this comment

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

I just fully tested it and seems to work flawlessly! Thanks @void-hr for the contribution.

In order to merge, I'll need a code review from one of the FE devs to make sure that has nothing missing.

@Daniel-Boll
Copy link
Collaborator

Code-wise is looking good, as @DanielHe4rt already tested it LGTM to be merged

@DanielHe4rt DanielHe4rt merged commit 504d946 into basementdevs:main Oct 29, 2024
3 checks passed
@Daniel-Boll
Copy link
Collaborator

Thank you for your contribution @void-hr, I'm sorry for the time it took and the lack of support by my part which was the responsible for the issue.

I'd like to extend my gratitude for the team @Matozinho @gvieira18 @DanielHe4rt @diegoreis42 for taking care of the issue and being able to help everyone, thanks guys.

@void-hr
Copy link
Contributor Author

void-hr commented Oct 29, 2024

@Daniel-Boll it was a nice experience, main reason was different timezone i guess. I thankyou all of you (@Matozinho @gvieira18 @DanielHe4rt @diegoreis42 @Daniel-Boll ) to guide me through!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers hacktoberfest-accepted Hacktoberfest-able PR refactor Refactoring existing code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants