mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-09 16:03:31 +00:00
fix(ui): Tab doesn't represent the page you are on for non-data asset pages (#9468)
This commit is contained in:
parent
76be5173b2
commit
16d3df620f
@ -5,6 +5,7 @@ import UserContextProvider from './context/UserContextProvider';
|
|||||||
import QuickFiltersProvider from '../providers/QuickFiltersProvider';
|
import QuickFiltersProvider from '../providers/QuickFiltersProvider';
|
||||||
import SearchContextProvider from './search/context/SearchContextProvider';
|
import SearchContextProvider from './search/context/SearchContextProvider';
|
||||||
import EntityRegistryProvider from './EntityRegistryProvider';
|
import EntityRegistryProvider from './EntityRegistryProvider';
|
||||||
|
import { BrowserTitleProvider } from './shared/BrowserTabTitleContext';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
@ -15,11 +16,13 @@ export default function AppProviders({ children }: Props) {
|
|||||||
<AppConfigProvider>
|
<AppConfigProvider>
|
||||||
<UserContextProvider>
|
<UserContextProvider>
|
||||||
<EntityRegistryProvider>
|
<EntityRegistryProvider>
|
||||||
|
<BrowserTitleProvider>
|
||||||
<EducationStepsProvider>
|
<EducationStepsProvider>
|
||||||
<QuickFiltersProvider>
|
<QuickFiltersProvider>
|
||||||
<SearchContextProvider>{children}</SearchContextProvider>
|
<SearchContextProvider>{children}</SearchContextProvider>
|
||||||
</QuickFiltersProvider>
|
</QuickFiltersProvider>
|
||||||
</EducationStepsProvider>
|
</EducationStepsProvider>
|
||||||
|
</BrowserTitleProvider>
|
||||||
</EntityRegistryProvider>
|
</EntityRegistryProvider>
|
||||||
</UserContextProvider>
|
</UserContextProvider>
|
||||||
</AppConfigProvider>
|
</AppConfigProvider>
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import {
|
|||||||
} from '../shared/SidebarStyledComponents';
|
} from '../shared/SidebarStyledComponents';
|
||||||
import GroupMembersSideBarSection from './GroupMembersSideBarSection';
|
import GroupMembersSideBarSection from './GroupMembersSideBarSection';
|
||||||
import { useUserContext } from '../../context/useUserContext';
|
import { useUserContext } from '../../context/useUserContext';
|
||||||
|
import { useBrowserTitle } from '../../shared/BrowserTabTitleContext';
|
||||||
import StripMarkdownText, { removeMarkdown } from '../shared/components/styled/StripMarkdownText';
|
import StripMarkdownText, { removeMarkdown } from '../shared/components/styled/StripMarkdownText';
|
||||||
import { Editor } from '../shared/tabs/Documentation/components/editor/Editor';
|
import { Editor } from '../shared/tabs/Documentation/components/editor/Editor';
|
||||||
import EditGroupDescriptionModal from './EditGroupDescriptionModal';
|
import EditGroupDescriptionModal from './EditGroupDescriptionModal';
|
||||||
@ -157,6 +158,22 @@ export default function GroupInfoSidebar({ sideBarData, refetch }: Props) {
|
|||||||
const { url } = useRouteMatch();
|
const { url } = useRouteMatch();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
|
const { updateTitle } = useBrowserTitle();
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
// You can use the title and updateTitle function here
|
||||||
|
// For example, updating the title when the component mounts
|
||||||
|
if(name){
|
||||||
|
updateTitle(`Group | ${name}`);
|
||||||
|
}
|
||||||
|
// // Don't forget to clean up the title when the component unmounts
|
||||||
|
return () => {
|
||||||
|
if(name){ // added to condition for rerendering issue
|
||||||
|
updateTitle('');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [name, updateTitle]);
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/no-unused-vars */
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
const [editGroupModal, showEditGroupModal] = useState(false);
|
const [editGroupModal, showEditGroupModal] = useState(false);
|
||||||
const me = useUserContext();
|
const me = useUserContext();
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Divider, message, Space, Button, Typography, Tag } from 'antd';
|
import { Divider, message, Space, Button, Typography, Tag } from 'antd';
|
||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { EditOutlined, MailOutlined, PhoneOutlined, SlackOutlined } from '@ant-design/icons';
|
import { EditOutlined, MailOutlined, PhoneOutlined, SlackOutlined } from '@ant-design/icons';
|
||||||
import { useUpdateCorpUserPropertiesMutation } from '../../../graphql/user.generated';
|
import { useUpdateCorpUserPropertiesMutation } from '../../../graphql/user.generated';
|
||||||
import { EntityRelationship, DataHubRole } from '../../../types.generated';
|
import { EntityRelationship, DataHubRole } from '../../../types.generated';
|
||||||
@ -21,6 +21,7 @@ import {
|
|||||||
import EntityGroups from '../shared/EntityGroups';
|
import EntityGroups from '../shared/EntityGroups';
|
||||||
import { mapRoleIcon } from '../../identity/user/UserUtils';
|
import { mapRoleIcon } from '../../identity/user/UserUtils';
|
||||||
import { useUserContext } from '../../context/useUserContext';
|
import { useUserContext } from '../../context/useUserContext';
|
||||||
|
import { useBrowserTitle } from '../../shared/BrowserTabTitleContext';
|
||||||
|
|
||||||
const { Paragraph } = Typography;
|
const { Paragraph } = Typography;
|
||||||
|
|
||||||
@ -61,6 +62,22 @@ export default function UserInfoSideBar({ sideBarData, refetch }: Props) {
|
|||||||
const me = useUserContext();
|
const me = useUserContext();
|
||||||
const isProfileOwner = me?.user?.urn === urn;
|
const isProfileOwner = me?.user?.urn === urn;
|
||||||
|
|
||||||
|
const { updateTitle } = useBrowserTitle();
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
// You can use the title and updateTitle function here
|
||||||
|
// For example, updating the title when the component mounts
|
||||||
|
if(name){
|
||||||
|
updateTitle(`User | ${name}`);
|
||||||
|
}
|
||||||
|
// // Don't forget to clean up the title when the component unmounts
|
||||||
|
return () => {
|
||||||
|
if(name){ // added to condition for rerendering issue
|
||||||
|
updateTitle('');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [name, updateTitle]);
|
||||||
|
|
||||||
const getEditModalData = {
|
const getEditModalData = {
|
||||||
urn,
|
urn,
|
||||||
name,
|
name,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import { useHistory, useLocation } from 'react-router';
|
|||||||
import { debounce } from 'lodash';
|
import { debounce } from 'lodash';
|
||||||
import * as QueryString from 'query-string';
|
import * as QueryString from 'query-string';
|
||||||
import { useTheme } from 'styled-components';
|
import { useTheme } from 'styled-components';
|
||||||
|
import { Helmet } from 'react-helmet-async';
|
||||||
import { SearchHeader } from './SearchHeader';
|
import { SearchHeader } from './SearchHeader';
|
||||||
import { useEntityRegistry } from '../useEntityRegistry';
|
import { useEntityRegistry } from '../useEntityRegistry';
|
||||||
import { EntityType, FacetFilterInput } from '../../types.generated';
|
import { EntityType, FacetFilterInput } from '../../types.generated';
|
||||||
@ -19,6 +20,7 @@ import { useQuickFiltersContext } from '../../providers/QuickFiltersContext';
|
|||||||
import { useUserContext } from '../context/useUserContext';
|
import { useUserContext } from '../context/useUserContext';
|
||||||
import { useSelectedSortOption } from './context/SearchContext';
|
import { useSelectedSortOption } from './context/SearchContext';
|
||||||
import { HALF_SECOND_IN_MS } from '../entity/shared/tabs/Dataset/Queries/utils/constants';
|
import { HALF_SECOND_IN_MS } from '../entity/shared/tabs/Dataset/Queries/utils/constants';
|
||||||
|
import { useBrowserTitle } from '../shared/BrowserTabTitleContext';
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
children: {
|
children: {
|
||||||
@ -68,6 +70,28 @@ export const SearchablePage = ({ onSearch, onAutoComplete, children }: Props) =>
|
|||||||
const { user } = userContext;
|
const { user } = userContext;
|
||||||
const viewUrn = userContext.localState?.selectedViewUrn;
|
const viewUrn = userContext.localState?.selectedViewUrn;
|
||||||
|
|
||||||
|
const { title, updateTitle } = useBrowserTitle();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Update the title only if it's not already set and there is a valid pathname
|
||||||
|
if (!title && location.pathname) {
|
||||||
|
const formattedPath = location.pathname
|
||||||
|
.split('/')
|
||||||
|
.filter(word => word !== '')
|
||||||
|
.map(word => word.charAt(0).toUpperCase() + word.slice(1))
|
||||||
|
.join(' | ');
|
||||||
|
|
||||||
|
if (formattedPath) {
|
||||||
|
return updateTitle(formattedPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up the title when the component unmounts
|
||||||
|
return () => {
|
||||||
|
updateTitle('');
|
||||||
|
};
|
||||||
|
}, [location.pathname, title, updateTitle]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (suggestionsData !== undefined) {
|
if (suggestionsData !== undefined) {
|
||||||
setNewSuggestionData(suggestionsData);
|
setNewSuggestionData(suggestionsData);
|
||||||
@ -140,6 +164,9 @@ export const SearchablePage = ({ onSearch, onAutoComplete, children }: Props) =>
|
|||||||
authenticatedUserPictureLink={user?.editableProperties?.pictureLink}
|
authenticatedUserPictureLink={user?.editableProperties?.pictureLink}
|
||||||
entityRegistry={entityRegistry}
|
entityRegistry={entityRegistry}
|
||||||
/>
|
/>
|
||||||
|
<Helmet>
|
||||||
|
<title>{title}</title>
|
||||||
|
</Helmet>
|
||||||
<div style={styles.children}>{children}</div>
|
<div style={styles.children}>{children}</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
30
datahub-web-react/src/app/shared/BrowserTabTitleContext.tsx
Normal file
30
datahub-web-react/src/app/shared/BrowserTabTitleContext.tsx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import React, { createContext, ReactNode, useContext } from 'react';
|
||||||
|
|
||||||
|
interface BrowserTitleContextProps {
|
||||||
|
title: string;
|
||||||
|
updateTitle: (newTitle: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const BrowserTitleContext = createContext<BrowserTitleContextProps | undefined>(undefined);
|
||||||
|
|
||||||
|
export const BrowserTitleProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||||
|
const [title, setTitle] = React.useState<string>('');
|
||||||
|
|
||||||
|
const updateTitle = (newTitle: string) => {
|
||||||
|
setTitle(newTitle);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<BrowserTitleContext.Provider value={{ title, updateTitle }}>
|
||||||
|
{children}
|
||||||
|
</BrowserTitleContext.Provider>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useBrowserTitle = () => {
|
||||||
|
const context = useContext(BrowserTitleContext);
|
||||||
|
if (!context) {
|
||||||
|
throw new Error('useBrowserTitle must be used within a BrowserTitleProvider');
|
||||||
|
}
|
||||||
|
return context;
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user