Skip to content

Commit

Permalink
fix: unnecessary refresh when changing url (#7838) (#7841)
Browse files Browse the repository at this point in the history
Co-authored-by: 青湛 <0x1304570@gmail.com>
  • Loading branch information
github-actions[bot] and mintsweet authored Aug 6, 2024
1 parent cd6a80c commit b8eba03
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 42 deletions.
20 changes: 2 additions & 18 deletions config-ui/src/config/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,11 @@ export const PATHS = {
CONNECTIONS: () => `${PATH_PREFIX}/connections`,
CONNECTION: (plugin: string, connectionId: ID) => `${PATH_PREFIX}/connections/${plugin}/${connectionId}`,
PROJECTS: () => `${PATH_PREFIX}/projects`,
PROJECT: (
pname: string,
{ tab, tabId }: { tab?: 'configuration' | 'status'; tabId?: 'blueprint' | 'webhook' | 'settings' } = {},
) => {
let params = '';

if (tab && tabId) {
params = `?tab=${tab}&tabId=${tabId}`;
} else if (tab) {
params = `?tab=${tab}`;
} else if (tabId) {
params = `?tabId=${tabId}`;
}

return `${PATH_PREFIX}/projects/${encodeName(pname)}${params}`;
},
PROJECT: (pname: string) => `${PATH_PREFIX}/projects/${encodeName(pname)}`,
PROJECT_CONNECTION: (pname: string, plugin: string, connectionId: ID) =>
`${PATH_PREFIX}/projects/${encodeName(pname)}/${plugin}-${connectionId}`,
BLUEPRINTS: () => `${PATH_PREFIX}/advanced/blueprints`,
BLUEPRINT: (bid: ID, tab?: 'configuration' | 'status') =>
`${PATH_PREFIX}/advanced/blueprints/${bid}${tab ? `?tab=${tab}` : ''}`,
BLUEPRINT: (bid: ID) => `${PATH_PREFIX}/advanced/blueprints/${bid}`,
BLUEPRINT_CONNECTION: (bid: ID, plugin: string, connectionId: ID) =>
`${PATH_PREFIX}/advanced/blueprints/${bid}/${plugin}-${connectionId}`,
PIPELINES: () => `${PATH_PREFIX}/advanced/pipelines`,
Expand Down
2 changes: 1 addition & 1 deletion config-ui/src/plugins/components/scope-config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const ScopeConfig = ({
});

if (success) {
window.open(PATHS.PROJECT(pname, { tab: 'status' }));
window.open(PATHS.PROJECT(pname));
}
};

Expand Down
14 changes: 10 additions & 4 deletions config-ui/src/routes/blueprint/connection-detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ export const BlueprintConnectionDetailPage = () => {
});

if (success) {
navigate(pname ? PATHS.PROJECT(pname, { tab: 'status' }) : PATHS.BLUEPRINT(blueprint.id, 'status'));
navigate(pname ? PATHS.PROJECT(pname) : PATHS.BLUEPRINT(blueprint.id), {
state: {
activeKey: 'status',
},
});
}
};

Expand Down Expand Up @@ -121,9 +125,11 @@ export const BlueprintConnectionDetailPage = () => {
</div>
),
onCancel: () => {
navigate(
pname ? PATHS.PROJECT(pname, { tab: 'configuration' }) : PATHS.BLUEPRINT(blueprint.id, 'configuration'),
);
navigate(pname ? PATHS.PROJECT(pname) : PATHS.BLUEPRINT(blueprint.id), {
state: {
tab: 'configuration',
},
});
},
});
}
Expand Down
21 changes: 13 additions & 8 deletions config-ui/src/routes/blueprint/detail/blueprint-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*
*/

import { useState } from 'react';
import { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { Tabs } from 'antd';
import useUrlState from '@ahooksjs/use-url-state';

import API from '@/api';
import { PageLoading } from '@/components';
Expand All @@ -37,8 +37,13 @@ interface Props {

export const BlueprintDetail = ({ id, from }: Props) => {
const [version, setVersion] = useState(1);
const [activeKey, setActiveKey] = useState('status');

const [query, setQuery] = useUrlState({ tab: 'status' });
const { state } = useLocation();

useEffect(() => {
setActiveKey(state?.activeKey ?? 'status');
}, [state]);

const { ready, data } = useRefreshData(async () => {
const [bpRes, pipelineRes] = await Promise.all([API.blueprint.get(id), API.blueprint.pipelines(id)]);
Expand All @@ -49,8 +54,8 @@ export const BlueprintDetail = ({ id, from }: Props) => {
setVersion((v) => v + 1);
};

const handleChangeTab = (tab: string) => {
setQuery({ tab });
const handleChangeActiveKey = (activeKey: string) => {
setActiveKey(activeKey);
};

if (!ready || !data) {
Expand Down Expand Up @@ -79,13 +84,13 @@ export const BlueprintDetail = ({ id, from }: Props) => {
from={from}
blueprint={blueprint}
onRefresh={handlRefresh}
onChangeTab={handleChangeTab}
onChangeTab={handleChangeActiveKey}
/>
),
},
]}
activeKey={query.tab}
onChange={(tab) => setQuery({ tab })}
activeKey={activeKey}
onChange={handleChangeActiveKey}
/>
</S.Wrapper>
);
Expand Down
10 changes: 8 additions & 2 deletions config-ui/src/routes/blueprint/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export const BlueprintHomePage = () => {
title: 'Blueprint Name',
key: 'name',
render: (_, { id, name }) => (
<Link to={PATHS.BLUEPRINT(id, 'configuration')} style={{ color: '#292b3f' }}>
<Link to={PATHS.BLUEPRINT(id)} state={{ activeKey: 'configuration' }} style={{ color: '#292b3f' }}>
<TextTooltip content={name}>{name}</TextTooltip>
</Link>
),
Expand Down Expand Up @@ -196,7 +196,13 @@ export const BlueprintHomePage = () => {
type="primary"
icon={<SettingOutlined />}
helptip="Blueprint Configuration"
onClick={() => navigate(PATHS.BLUEPRINT(val, 'configuration'))}
onClick={() =>
navigate(PATHS.BLUEPRINT(val), {
state: {
activeKey: 'configuration',
},
})
}
/>
),
},
Expand Down
16 changes: 10 additions & 6 deletions config-ui/src/routes/project/detail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
*
*/

import { useState } from 'react';
import { useParams } from 'react-router-dom';
import { useEffect, useState } from 'react';
import { useParams, useLocation } from 'react-router-dom';
import { Helmet } from 'react-helmet';
import { Tabs } from 'antd';
import useUrlState from '@ahooksjs/use-url-state';

import API from '@/api';
import { PageHeader, PageLoading } from '@/components';
Expand All @@ -36,14 +35,19 @@ const brandName = import.meta.env.DEVLAKE_BRAND_NAME ?? 'DevLake';

export const ProjectDetailPage = () => {
const [version, setVersion] = useState(1);
const [tabId, setTabId] = useState('blueprint');

const { pname } = useParams() as { pname: string };
const [query, setQuery] = useUrlState({ tabId: 'blueprint' });
const { state } = useLocation();

useEffect(() => {
setTabId(state?.tabId ?? 'blueprint');
}, [state]);

const { ready, data } = useRefreshData(() => API.project.get(pname), [pname, version]);

const handleChangeTabId = (tabId: string) => {
setQuery({ tabId });
setTabId(tabId);
};

const handleRefresh = () => {
Expand Down Expand Up @@ -85,7 +89,7 @@ export const ProjectDetailPage = () => {
children: <SettingsPanel project={data} onRefresh={handleRefresh} />,
},
]}
activeKey={query.tabId}
activeKey={tabId}
onChange={handleChangeTabId}
/>
</S.Wrapper>
Expand Down
6 changes: 5 additions & 1 deletion config-ui/src/routes/project/detail/settings-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ export const SettingsPanel = ({ project, onRefresh }: Props) => {

if (success) {
onRefresh();
navigate(PATHS.PROJECT(name, { tabId: 'settings' }));
navigate(PATHS.PROJECT(name), {
state: {
tabId: 'settings',
},
});
}
};

Expand Down
13 changes: 11 additions & 2 deletions config-ui/src/routes/project/home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ export const ProjectHomePage = () => {
dataIndex: 'name',
key: 'name',
render: (name: string) => (
<Link to={PATHS.PROJECT(name, { tab: 'configuration' })} style={{ color: '#292b3f' }} ref={nameRef}>
<Link
to={PATHS.PROJECT(name)}
state={{ activeKey: 'configuration' }}
style={{ color: '#292b3f' }}
ref={nameRef}
>
{name}
</Link>
),
Expand Down Expand Up @@ -185,7 +190,11 @@ export const ProjectHomePage = () => {
type="primary"
icon={<SettingOutlined />}
helptip="Project Configuration"
onClick={() => navigate(PATHS.PROJECT(name, { tab: 'configuration' }))}
onClick={() =>
navigate(PATHS.PROJECT(name), {
state: { activeKey: 'configuration' },
})
}
/>
),
},
Expand Down

0 comments on commit b8eba03

Please sign in to comment.