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

(web) add a console component that allows running sql in the context of an env #293

Merged
merged 7 commits into from
Jul 8, 2024

Conversation

joewagner
Copy link
Contributor

No description provided.

Copy link

vercel bot commented Jun 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 3, 2024 8:00pm


// splitting on "/" means there is always an empty string as the first
// element in the Array since pathname always starts with /
const isConsole = pathParts.length === 5 && pathParts.pop() === "console";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asutula curious if you have any thoughts what to do here?

The url /joe/foo/default/console could be a table page or the console page (or really any url with 4 parts). We could refactor our url scheme to allow for unique page urls regardless of name, or add console as a reserved word. Using a reserved word feels wrong to me. If we do that it would mean that anyone with an already existing def called console would have a broken project.

Copy link
Contributor

Choose a reason for hiding this comment

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

I do have a suggestion that is a bit cleaner:

You can rely on the values returned by useParams above to distinguish between the console part of the route and any table name. If the user is visiting the console page, defSlug will be undefined. So this give us most of the information we need to make sure we're not viewing a table (def), but we still need to distinguish between the overview page and console page which both match the case !!envSlug && !defSlug. We can use the hook useSelectedLayoutSegments to get a nice array of url segments below the layout without needing to split the pathname string on / etc (as you complain about below). So the final calculation of isConsole would be:

const isConsole =
    !!envSlug && !defSlug && selectedLayoutSegments.slice(-1)[0] === "console";

Copy link
Contributor

Choose a reason for hiding this comment

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

We should, for now at least, just go with the restricted slug approach. There is no table def named console yet (I checked using your console!), so we can implement that restriction with no problem currently.

Screenshot 2024-07-02 at 4 15 32 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can use the hook useSelectedLayoutSegments to get a nice array of url segments below the layout without needing to split the pathname string on / etc (as you complain about below). So the final calculation of isConsole would be:

const isConsole =
    !!envSlug && !defSlug && selectedLayoutSegments.slice(-1)[0] === "console";

The useSelectedSegments hook works well, I'll switch to that.

We should, for now at least, just go with the restricted slug approach. There is no table def named console yet (I checked using your console!), so we can implement that restriction with no problem currently.

I'll set it up so that "console" is a reserved word within the context of defs. A similar problem exists if you create an environment called "settings". should I work on fixing that here, or leave it for another PR?

hightlightWithLineNumbers(
code,
(languages as any).sql,
props.hideLineNumbers,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left the line numbers feature mostly in place, but hard coded it to hide the line numbers. If we want to show line numbers we will need to include the css the old console was using, or convert it to tailwind and add the classes.

@joewagner joewagner marked this pull request as ready for review July 1, 2024 21:12
@asutula
Copy link
Contributor

asutula commented Jul 2, 2024

Just saw this @joewagner. Sorry for the delay. Will answer your questions this afternoon asap.

@joewagner joewagner requested a review from asutula July 2, 2024 20:40
@joewagner
Copy link
Contributor Author

Just saw this @joewagner. Sorry for the delay. Will answer your questions this afternoon asap.

No worries, I think I forgot to request a review

Copy link
Contributor

@asutula asutula left a comment

Choose a reason for hiding this comment

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

This is awesome! So cool to see and use this. Requests some changes, then we can get this merged.

Comment on lines 18 to 22
if (!environment) {
throw new TRPCError({
code: "NOT_FOUND",
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You don't need this because the environmentBySlug helper does this internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh perfect!

@@ -57,7 +57,9 @@
"keccak": "^3.0.3",
"lucide-react": "^0.354.0",
"next": "^14.2.3",
"prismjs": "^1.28.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this used anywhere since it appears we just copied some source code from it into our own repo. Should we uninstall this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. I tried to use npm and avoid including the prismjs source, but when that didn't work I forgot to remove the dep here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious why we copied this code (and the CSS) vs importing from the npm package?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prismjs seems to be optimized to be downloaded and used in this way. The npm package only include a few types of highlighting/formatting. Since we want sql highlighting I had to download the specific theme and formatting.


// splitting on "/" means there is always an empty string as the first
// element in the Array since pathname always starts with /
const isConsole = pathParts.length === 5 && pathParts.pop() === "console";
Copy link
Contributor

Choose a reason for hiding this comment

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

I do have a suggestion that is a bit cleaner:

You can rely on the values returned by useParams above to distinguish between the console part of the route and any table name. If the user is visiting the console page, defSlug will be undefined. So this give us most of the information we need to make sure we're not viewing a table (def), but we still need to distinguish between the overview page and console page which both match the case !!envSlug && !defSlug. We can use the hook useSelectedLayoutSegments to get a nice array of url segments below the layout without needing to split the pathname string on / etc (as you complain about below). So the final calculation of isConsole would be:

const isConsole =
    !!envSlug && !defSlug && selectedLayoutSegments.slice(-1)[0] === "console";


// splitting on "/" means there is always an empty string as the first
// element in the Array since pathname always starts with /
const isConsole = pathParts.length === 5 && pathParts.pop() === "console";
Copy link
Contributor

Choose a reason for hiding this comment

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

We should, for now at least, just go with the restricted slug approach. There is no table def named console yet (I checked using your console!), so we can implement that restriction with no problem currently.

Screenshot 2024-07-02 at 4 15 32 PM

Comment on lines +151 to 156
<SidebarLink
icon={Terminal}
title="Console"
href={`/${teamQuery.data.slug}/${projectQuery.data.slug}/${linkEnv.slug}/console`}
selected={isConsole}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

This SidebarLink should go in the SidebarSection above along with the link for Overview. You can then delete this section.

@joewagner
Copy link
Contributor Author

@asutula I believe I got all the change requests in here. Have another look when you get time.

@joewagner joewagner merged commit 685c686 into main Jul 8, 2024
4 checks passed
@joewagner joewagner deleted the joe/web-console branch July 8, 2024 16:58
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.

2 participants