Skip to content

Commit 65fa429

Browse files
committed
feat: use relative entity path in schema actions
1 parent 960e97f commit 65fa429

File tree

5 files changed

+61
-26
lines changed

5 files changed

+61
-26
lines changed

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import {ObjectTree} from './ObjectTree';
4444
import {SchemaActions} from './SchemaActions';
4545
import i18n from './i18n';
4646
import {b} from './shared';
47-
import {transformPath} from './transformPath';
47+
import {isDomain, transformPath} from './transformPath';
4848

4949
import './ObjectSummary.scss';
5050

@@ -148,7 +148,11 @@ export function ObjectSummary({
148148

149149
const overview: InfoViewerItem[] = [];
150150

151-
overview.push({label: i18n('field_type'), value: PathType?.replace(/^EPathType/, '')});
151+
const normalizedType = isDomain(path, PathType)
152+
? 'Domain'
153+
: PathType?.replace(/^EPathType/, '');
154+
155+
overview.push({label: i18n('field_type'), value: normalizedType});
152156

153157
if (PathSubType !== EPathSubType.EPathSubTypeEmpty) {
154158
overview.push({
@@ -343,6 +347,8 @@ export function ObjectSummary({
343347
dispatchCommonInfoVisibilityState(PaneVisibilityActionTypes.clear);
344348
};
345349

350+
const relativePath = transformPath(path, tenantName);
351+
346352
const renderCommonInfoControls = () => {
347353
const showPreview = isTableType(type) && !isIndexTableType(subType);
348354
return (
@@ -354,7 +360,7 @@ export function ObjectSummary({
354360
'm',
355361
)(path, 'preview')}
356362
<ClipboardButton
357-
text={path}
363+
text={relativePath}
358364
view="flat-secondary"
359365
title={i18n('action_copySchemaPath')}
360366
/>
@@ -370,15 +376,19 @@ export function ObjectSummary({
370376

371377
const renderEntityTypeBadge = () => {
372378
const {Status, Reason} = currentObjectData ?? {};
379+
if (type) {
380+
let label = type.replace('EPathType', '');
381+
if (isDomain(path, type)) {
382+
label = 'domain';
383+
}
384+
return <div className={b('entity-type')}>{label}</div>;
385+
}
373386

374387
let message;
375-
if (!type && Status && Reason) {
388+
if (Status && Reason) {
376389
message = `${Status}: ${Reason}`;
377390
}
378-
379-
return type ? (
380-
<div className={b('entity-type')}>{type.replace('EPathType', '')}</div>
381-
) : (
391+
return (
382392
<div className={b('entity-type', {error: true})}>
383393
<HelpPopover content={message} offset={{left: 0}} />
384394
</div>
@@ -404,9 +414,7 @@ export function ObjectSummary({
404414
<div className={b('info-header')}>
405415
<div className={b('info-title')}>
406416
{renderEntityTypeBadge()}
407-
<div className={b('path-name')}>
408-
{transformPath(path, tenantName)}
409-
</div>
417+
<div className={b('path-name')}>{relativePath}</div>
410418
</div>
411419
<div className={b('info-controls')}>
412420
{renderCommonInfoControls()}

src/containers/Tenant/ObjectSummary/__test__/transformPath.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describe('transformPath', () => {
99
['/prod/v1/sth', 'prod/v1', 'sth'],
1010
['/dev/v1/sth', '/dev', 'v1/sth'],
1111
['/dev/v1/sth', 'dev', 'v1/sth'],
12-
['/dev', '/dev', '/'],
13-
['/dev', 'dev', '/'],
12+
['/dev', '/dev', '/dev'],
13+
['/dev', 'dev', '/dev'],
1414
['/', '/dev', '/'],
1515
['/', 'dev', '/'],
1616
['', '/dev', '/'],

src/containers/Tenant/ObjectSummary/transformPath.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {EPathType} from '../../../types/api/schema';
2+
13
export function transformPath(path: string, dbName: string): string {
24
// Normalize the path and dbName by removing leading/trailing slashes
35
const normalizedPath = path.replace(/^\/+|\/+$/g, '');
@@ -6,6 +8,9 @@ export function transformPath(path: string, dbName: string): string {
68
if (!normalizedPath.startsWith(normalizedDbName)) {
79
return normalizedPath || '/';
810
}
11+
if (normalizedPath === normalizedDbName) {
12+
return `/${normalizedPath}`;
13+
}
914

1015
let result = normalizedPath.slice(normalizedDbName.length);
1116

@@ -14,3 +19,19 @@ export function transformPath(path: string, dbName: string): string {
1419

1520
return result;
1621
}
22+
23+
export function isDomain(path: string, type?: EPathType) {
24+
if (type !== EPathType.EPathTypeDir) {
25+
return false;
26+
}
27+
let count = 0;
28+
for (let i = 0; i <= path.length; i++) {
29+
if (path[i] === '/') {
30+
count++;
31+
}
32+
if (count > 1) {
33+
return false;
34+
}
35+
}
36+
return count === 1;
37+
}

src/containers/Tenant/Schema/SchemaTree/SchemaTree.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,18 @@ export function SchemaTree(props: SchemaTreeProps) {
110110
collapsed: false,
111111
}}
112112
fetchPath={fetchPath}
113-
getActions={getActions(dispatch, {
114-
setActivePath: onActivePathUpdate,
115-
updateQueryExecutionSettings: (settings) =>
116-
setQueryExecutionSettings({...querySettings, ...settings}),
117-
showCreateDirectoryDialog: createDirectoryFeatureAvailable
118-
? handleOpenCreateDirectoryDialog
119-
: undefined,
120-
})}
113+
getActions={getActions(
114+
dispatch,
115+
{
116+
setActivePath: onActivePathUpdate,
117+
updateQueryExecutionSettings: (settings) =>
118+
setQueryExecutionSettings({...querySettings, ...settings}),
119+
showCreateDirectoryDialog: createDirectoryFeatureAvailable
120+
? handleOpenCreateDirectoryDialog
121+
: undefined,
122+
},
123+
rootPath,
124+
)}
121125
renderAdditionalNodeElements={getSchemaControls(dispatch, {
122126
setActivePath: onActivePathUpdate,
123127
})}

src/containers/Tenant/utils/schemaActions.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {TENANT_PAGES_IDS, TENANT_QUERY_TABS_ID} from '../../../store/reducers/te
66
import {setQueryTab, setTenantPage} from '../../../store/reducers/tenant/tenant';
77
import type {QueryMode, QuerySettings} from '../../../types/store/query';
88
import createToast from '../../../utils/createToast';
9+
import {transformPath} from '../ObjectSummary/transformPath';
910
import i18n from '../i18n';
1011

1112
import {
@@ -33,7 +34,7 @@ interface ActionsAdditionalEffects {
3334
}
3435

3536
const bindActions = (
36-
path: string,
37+
{path, relativePath}: {path: string; relativePath: string},
3738
dispatch: React.Dispatch<any>,
3839
additionalEffects: ActionsAdditionalEffects,
3940
) => {
@@ -45,7 +46,7 @@ const bindActions = (
4546
updateQueryExecutionSettings({queryMode: mode});
4647
}
4748

48-
dispatch(changeUserInput({input: tmpl(path)}));
49+
dispatch(changeUserInput({input: tmpl(relativePath)}));
4950
dispatch(setTenantPage(TENANT_PAGES_IDS.query));
5051
dispatch(setQueryTab(TENANT_QUERY_TABS_ID.newQuery));
5152
setActivePath(path);
@@ -75,7 +76,7 @@ const bindActions = (
7576
dropView: inputQuery(dropViewTemplate, 'script'),
7677
copyPath: () => {
7778
try {
78-
copy(path);
79+
copy(relativePath);
7980
createToast({
8081
name: 'Copied',
8182
title: i18n('actions.copied'),
@@ -95,9 +96,10 @@ const bindActions = (
9596
type ActionsSet = ReturnType<Required<NavigationTreeProps>['getActions']>;
9697

9798
export const getActions =
98-
(dispatch: React.Dispatch<any>, additionalEffects: ActionsAdditionalEffects) =>
99+
(dispatch: React.Dispatch<any>, additionalEffects: ActionsAdditionalEffects, rootPath = '') =>
99100
(path: string, type: NavigationTreeNodeType) => {
100-
const actions = bindActions(path, dispatch, additionalEffects);
101+
const relativePath = transformPath(path, rootPath);
102+
const actions = bindActions({path, relativePath}, dispatch, additionalEffects);
101103
const copyItem = {text: i18n('actions.copyPath'), action: actions.copyPath};
102104

103105
const DIR_SET: ActionsSet = [

0 commit comments

Comments
 (0)