Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Svelte: update navigation bar for dotcom deployment#62682

Merged
camdencheek merged 6 commits into
mainfrom
cc/dotcom-header
May 16, 2024
Merged

Svelte: update navigation bar for dotcom deployment#62682
camdencheek merged 6 commits into
mainfrom
cc/dotcom-header

Conversation

@camdencheek

@camdencheek camdencheek commented May 14, 2024

Copy link
Copy Markdown
Member

This updates the navigation bar in svelte to show the dotcom-specific nav bar on dotcom (whenever svelte is enabled there).

Contributes to https://github.com/sourcegraph/sourcegraph/issues/62390

Test plan

Tested that the links work, the "current active" is accurate, and that everything looks right both in the dotcom version and the non-dotcom version.

Used SOURCEGRAPHDOTCOM_MODE=true sg start enterprise-sveltekit for testing.

One caveat is that the "About sourcegraph" link does not work in this mode locally because that's handled by Cloudflare.

@cla-bot cla-bot Bot added the cla-signed label May 14, 2024

@camdencheek camdencheek May 14, 2024

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Small opinionated change: I think it makes sense for components to live in lib and any static data (like route definitions) to go in routes, so I moved this to routes/navigation.ts (a sibling file to the +layout.svelte which uses it). This keeps lib dotcom-agnostic.

Comment on lines 75 to 70

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was necessary because the "About Sourcegraph" entry links to /, which prefixes every path, so it was always being shown as active. I think this is okay since we do not have sub-paths for these pages. The alternative was to add overridable "isCurrent" logic to every entry, which didn't feel ideal.

screenshot-2024-05-14_19-17-21@2x

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should I be depending on window.context directly here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good question. I know @vovakulikov has some thoughts around keeping dotcom differences managable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we could do it similar to data loading: Pages/components should not access window.context directly. Instead it should only be accessed in data loaders. So in this case the root layout data loader could return the navigation entries.

No idea whether that's good or not.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thinking about this recently: how sourcegraphDotCom checks consumed our codebase and how painful it is working with these conditions in UI when you have to think about different layouts in different environments.

Ideally, I would have a different place, like a dotcom directory, where I keep all specific to dotcom logic/UI.
Then, in the app, I would add some extension points with which we could extend the main app with dotcom logic.

The problem is that this isn't usually trivial. Sometimes, UI and logic are combined and coupled very closely.
In this particular example, it's simple enough because the dotcom difference doesn't have anything with UI, but with the data that we provide, this is the best-case scenario. If some page is very different on dotcom compared to the main app I would redo this page from scratch with some env-agnostic components rather than populate it with checks.

Back to this specific change here, I don't have a clear thought on how exactly we should achieve this clear separation between different environments, I would try to not working with check in the UI (which this PR doesn't do, which is great) and see how other dotcom parts will go into the main app, and then come up with more specific idea

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I like the idea of putting the window.context accesses in the data loaders. It makes sense to me. And separates concerns a little better. It's not obvious to me that window.context will always be the source of this information.

@camdencheek camdencheek requested a review from a team May 15, 2024 00:15
@camdencheek camdencheek marked this pull request as ready for review May 15, 2024 00:15

@fkling fkling left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Accepting to unblock. We probably want to think about the "best" way for accessing this information (see inline comment for a suggestion).

It would also be nice if we could run dotcom mode standalone without a backend. I suspect we can add something like pnpm dev:dotcom, which sets some env variables which in turn could populate window.context. But this doesn't have to be done in this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe we could do it similar to data loading: Pages/components should not access window.context directly. Instead it should only be accessed in data loaders. So in this case the root layout data loader could return the navigation entries.

No idea whether that's good or not.

@camdencheek camdencheek enabled auto-merge (squash) May 16, 2024 16:11

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, I thought we could return the actual navigation entries from here, making the page complete unaware of dotcom mode.
But as Vova said, sometimes it might not be as easy to do (though maybe we should work towards this), so this is probably good enough for now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah! I see. That makes sense. Went ahead and passed the entries here to make the page entirely unaware of dotcom mode.

@camdencheek camdencheek disabled auto-merge May 16, 2024 16:21
@camdencheek camdencheek merged commit 50f13cd into main May 16, 2024
@camdencheek camdencheek deleted the cc/dotcom-header branch May 16, 2024 18:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants