-
-
Notifications
You must be signed in to change notification settings - Fork 346
Set document titles from current page content #1848
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
Open
rahulbsw
wants to merge
7
commits into
kafbat:main
Choose a base branch
from
rahulbsw:issue-324-page-titles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b412068
Set document titles from current page content
dfd64f9
Merge branch 'main' into issue-324-page-titles
rahulbsw d6ad557
Merge branch 'main' into issue-324-page-titles
rahulbsw a40ce01
Merge branch 'main' into issue-324-page-titles
rahulbsw 8deddc2
Restore original title in PageHeading tests
24b31ec
Merge branch 'main' into issue-324-page-titles
rahulbsw 016925c
Merge branch 'main' into issue-324-page-titles
rahulbsw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
frontend/src/components/common/PageHeading/__tests__/PageHeading.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import React from 'react'; | ||
| import { render } from 'lib/testHelpers'; | ||
| import PageHeading from 'components/common/PageHeading/PageHeading'; | ||
|
|
||
| const originalTitle = document.title; | ||
|
|
||
| describe('PageHeading', () => { | ||
| afterEach(() => { | ||
| document.title = originalTitle; | ||
| }); | ||
|
|
||
| it('sets the browser title from heading content by default', () => { | ||
| render(<PageHeading text="Topics" title="local" />); | ||
|
|
||
| expect(document.title).toBe('Topics | local | Kafbat UI'); | ||
| }); | ||
|
|
||
| it('uses an explicit browser title override when provided', () => { | ||
| render( | ||
| <PageHeading | ||
| text="orders" | ||
| title="local" | ||
| documentTitle="Messages | orders | local | Kafbat UI" | ||
| /> | ||
| ); | ||
|
|
||
| expect(document.title).toBe('Messages | orders | local | Kafbat UI'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { | ||
| clusterConnectConnectorConfigPath, | ||
| clusterConnectorsRelativePath, | ||
| clusterKsqlDbQueryPath, | ||
| clusterTopicMessagesPath, | ||
| } from 'lib/paths'; | ||
| import { | ||
| buildPageTitle, | ||
| getConnectDetailsPageTitle, | ||
| getKafkaConnectPageTitle, | ||
| getKsqlDbPageTitle, | ||
| getTopicPageTitle, | ||
| } from 'lib/pageTitles'; | ||
|
|
||
| describe('pageTitles', () => { | ||
| it('builds titles from non-empty parts', () => { | ||
| expect(buildPageTitle('Messages', '', 'orders')).toBe( | ||
| 'Messages | orders | Kafbat UI' | ||
| ); | ||
| }); | ||
|
|
||
| it('maps topic detail routes to section titles', () => { | ||
| expect( | ||
| getTopicPageTitle( | ||
| clusterTopicMessagesPath('local', 'orders'), | ||
| 'local', | ||
| 'orders' | ||
| ) | ||
| ).toBe('Messages | orders | local | Kafbat UI'); | ||
| }); | ||
|
|
||
| it('maps connector detail routes to section titles', () => { | ||
| expect( | ||
| getConnectDetailsPageTitle( | ||
| clusterConnectConnectorConfigPath('local', 'main-connect', 'sink-a'), | ||
| 'local', | ||
| 'main-connect', | ||
| 'sink-a' | ||
| ) | ||
| ).toBe('Config | sink-a | local | Kafbat UI'); | ||
| }); | ||
|
|
||
| it('maps kafka connect list routes to page titles', () => { | ||
| expect( | ||
| getKafkaConnectPageTitle(clusterConnectorsRelativePath, 'local') | ||
| ).toBe('Connectors | Kafka Connect | local | Kafbat UI'); | ||
| }); | ||
|
|
||
| it('maps ksqldb routes to page titles', () => { | ||
| expect(getKsqlDbPageTitle(clusterKsqlDbQueryPath('local'), 'local')).toBe( | ||
| 'Query | KSQL DB | local | Kafbat UI' | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import { | ||
| clusterConnectConnectorConfigPath, | ||
| clusterConnectConnectorPath, | ||
| clusterConnectConnectorTopicsPath, | ||
| clusterConnectConnectorTasksPath, | ||
| clusterKsqlDbPath, | ||
| clusterKsqlDbQueryPath, | ||
| clusterKsqlDbStreamsPath, | ||
| clusterKsqlDbTablesPath, | ||
| clusterTopicAclsRelativePath, | ||
| clusterTopicConnectorsRelativePath, | ||
| clusterTopicConsumerGroupsPath, | ||
| clusterTopicEditPath, | ||
| clusterTopicMessagesPath, | ||
| clusterTopicPath, | ||
| clusterTopicSettingsPath, | ||
| clusterTopicStatisticsPath, | ||
| kafkaConnectClustersRelativePath, | ||
| } from 'lib/paths'; | ||
|
|
||
| const APP_NAME = 'Kafbat UI'; | ||
|
|
||
| export const buildPageTitle = (...parts: Array<string | undefined | null>) => | ||
| [...parts.filter((part): part is string => !!part?.trim()), APP_NAME].join( | ||
| ' | ' | ||
| ); | ||
|
|
||
| export const getKafkaConnectPageTitle = ( | ||
| currentPath: string | undefined, | ||
| clusterName: string | ||
| ) => { | ||
| if (currentPath === kafkaConnectClustersRelativePath) { | ||
| return buildPageTitle('Clusters', 'Kafka Connect', clusterName); | ||
| } | ||
|
|
||
| return buildPageTitle('Connectors', 'Kafka Connect', clusterName); | ||
| }; | ||
|
|
||
| export const getKsqlDbPageTitle = (pathname: string, clusterName: string) => { | ||
| if (pathname === clusterKsqlDbQueryPath(clusterName)) { | ||
| return buildPageTitle('Query', 'KSQL DB', clusterName); | ||
| } | ||
|
|
||
| if (pathname === clusterKsqlDbStreamsPath(clusterName)) { | ||
| return buildPageTitle('Streams', 'KSQL DB', clusterName); | ||
| } | ||
|
|
||
| if ( | ||
| pathname === clusterKsqlDbTablesPath(clusterName) || | ||
| pathname === clusterKsqlDbPath(clusterName) | ||
| ) { | ||
| return buildPageTitle('Tables', 'KSQL DB', clusterName); | ||
| } | ||
|
|
||
| return buildPageTitle('Tables', 'KSQL DB', clusterName); | ||
| }; | ||
|
|
||
| export const getConnectDetailsPageTitle = ( | ||
| pathname: string, | ||
| clusterName: string, | ||
| connectName: string, | ||
| connectorName: string | ||
| ) => { | ||
| if ( | ||
| pathname === | ||
| clusterConnectConnectorConfigPath(clusterName, connectName, connectorName) | ||
| ) { | ||
| return buildPageTitle('Config', connectorName, clusterName); | ||
| } | ||
|
|
||
| if ( | ||
| pathname === | ||
| clusterConnectConnectorTopicsPath(clusterName, connectName, connectorName) | ||
| ) { | ||
| return buildPageTitle('Topics', connectorName, clusterName); | ||
| } | ||
|
|
||
| if ( | ||
| pathname === | ||
| clusterConnectConnectorTasksPath( | ||
| clusterName, | ||
| connectName, | ||
| connectorName | ||
| ) || | ||
| pathname === | ||
| clusterConnectConnectorPath(clusterName, connectName, connectorName) | ||
| ) { | ||
| return buildPageTitle('Tasks', connectorName, clusterName); | ||
| } | ||
|
|
||
| return buildPageTitle(connectorName, clusterName); | ||
| }; | ||
|
|
||
| export const getTopicPageTitle = ( | ||
| pathname: string, | ||
| clusterName: string, | ||
| topicName: string | ||
| ) => { | ||
| if (pathname === clusterTopicMessagesPath(clusterName, topicName)) { | ||
| return buildPageTitle('Messages', topicName, clusterName); | ||
| } | ||
|
|
||
| if (pathname === clusterTopicSettingsPath(clusterName, topicName)) { | ||
| return buildPageTitle('Settings', topicName, clusterName); | ||
| } | ||
|
|
||
| if (pathname === clusterTopicConsumerGroupsPath(clusterName, topicName)) { | ||
| return buildPageTitle('Consumers', topicName, clusterName); | ||
| } | ||
|
|
||
| if (pathname === clusterTopicStatisticsPath(clusterName, topicName)) { | ||
| return buildPageTitle('Statistics', topicName, clusterName); | ||
| } | ||
|
|
||
| if ( | ||
| pathname === | ||
| `${clusterTopicPath(clusterName, topicName)}/${clusterTopicAclsRelativePath}` | ||
| ) { | ||
| return buildPageTitle('ACLs', topicName, clusterName); | ||
| } | ||
|
|
||
| if ( | ||
| pathname === | ||
| `${clusterTopicPath(clusterName, topicName)}/${clusterTopicConnectorsRelativePath}` | ||
| ) { | ||
| return buildPageTitle('Connectors', topicName, clusterName); | ||
| } | ||
|
|
||
| if (pathname === clusterTopicEditPath(clusterName, topicName)) { | ||
| return buildPageTitle('Edit', topicName, clusterName); | ||
| } | ||
|
|
||
| return buildPageTitle(topicName, clusterName); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.