Skip to content

Commit

Permalink
Fix: #2521 - Ad owner support for all services and database
Browse files Browse the repository at this point in the history
  • Loading branch information
darth-coder00 committed Feb 19, 2022
1 parent a8990b9 commit e1d7550
Show file tree
Hide file tree
Showing 16 changed files with 555 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import { AxiosResponse } from 'axios';
import { ServiceOption } from 'Models';
import { getURLWithQueryFields } from '../utils/APIUtils';
import APIClient from './index';

export const getServiceDetails: Function = (): Promise<AxiosResponse> => {
Expand All @@ -34,9 +35,15 @@ export const getServiceById: Function = (

export const getServiceByFQN: Function = (
serviceName: string,
fqn: string
fqn: string,
arrQueryFields = ''
): Promise<AxiosResponse> => {
return APIClient.get(`/services/${serviceName}/name/${fqn}`);
const url = getURLWithQueryFields(
`/services/${serviceName}/name/${fqn}`,
arrQueryFields
);

return APIClient.get(url);
};

export const postService: Function = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ const DashboardDetails = ({
value:
owner?.type === 'team'
? getTeamDetailsPath(owner?.name || '')
: owner?.name || '',
placeholderText: owner?.displayName || '',
: owner?.displayName || owner?.name || '',
placeholderText: owner?.displayName || owner?.name || '',
isLink: owner?.type === 'team',
openInNewTab: false,
},
Expand Down Expand Up @@ -202,12 +202,7 @@ const DashboardDetails = ({
: dashboardDetails.tags;
const updatedDashboardDetails = {
...dashboardDetails,
owner: newOwner
? {
...dashboardDetails.owner,
...newOwner,
}
: dashboardDetails.owner,
owner: newOwner ? newOwner : dashboardDetails.owner,
tags: tierTag,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,8 @@ const DatasetDetails: React.FC<DatasetDetailsProps> = ({
title: 'Manage',
selectedName: 'icon-managecolor',
},
isProtected: true,
isProtected: false,
isHidden: deleted,
protectedState: !owner || hasEditAccess(),
position: 6,
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Loader from '../Loader/Loader';
type Props = {
currentTier?: string;
currentUser?: string;
hideTier?: boolean;
onSave: (
owner: TableDetail['owner'],
tier: TableDetail['tier']
Expand All @@ -43,6 +44,7 @@ type Props = {
const ManageTab: FunctionComponent<Props> = ({
currentTier = '',
currentUser = '',
hideTier = false,
onSave,
hasEditAccess,
}: Props) => {
Expand Down Expand Up @@ -133,6 +135,11 @@ const ManageTab: FunctionComponent<Props> = ({
setActiveTier(cardId);
};

const setInitialLoadingState = () => {
setStatus('initial');
setLoading(false);
};

const handleSave = () => {
setLoading(true);
setStatus('waiting');
Expand All @@ -146,11 +153,20 @@ const ManageTab: FunctionComponent<Props> = ({
| 'team',
}
: undefined;
const newTier = activeTier !== currentTier ? activeTier : undefined;
onSave(newOwner, newTier).catch(() => {
setStatus('initial');
setLoading(false);
});
if (hideTier) {
if (newOwner) {
onSave(newOwner, '').catch(() => {
setInitialLoadingState();
});
} else {
setInitialLoadingState();
}
} else {
const newTier = activeTier !== currentTier ? activeTier : undefined;
onSave(newOwner, newTier).catch(() => {
setInitialLoadingState();
});
}
};

const handleCancel = () => {
Expand Down Expand Up @@ -188,7 +204,9 @@ const ManageTab: FunctionComponent<Props> = ({
const ownerName = getOwnerById();

useEffect(() => {
getTierData();
if (!hideTier) {
getTierData();
}
}, []);

useEffect(() => {
Expand Down Expand Up @@ -229,13 +247,15 @@ const ManageTab: FunctionComponent<Props> = ({
<p>You do not have permissions to update the owner.</p>
</>
}
isOwner={hasEditAccess || Boolean(owner)}
isOwner={hasEditAccess || !currentUser}
permission={Operation.UpdateOwner}
position="left">
<Button
className={classNames('tw-underline', {
'tw-opacity-40':
!userPermissions[Operation.UpdateOwner] && !isAuthDisabled,
!userPermissions[Operation.UpdateOwner] &&
!isAuthDisabled &&
!(hasEditAccess || !currentUser),
})}
data-testid="owner-dropdown"
disabled={!listOwners.length}
Expand Down Expand Up @@ -275,31 +295,32 @@ const ManageTab: FunctionComponent<Props> = ({
)}
</span>
</div>
{isLoadingTierData ? (
<Loader />
) : (
<div className="tw-flex tw-flex-col" data-testid="cards">
{tierData.map((card, i) => (
<NonAdminAction
html={
<>
<p>You need to be owner to perform this action</p>
<p>Claim ownership from above </p>
</>
}
isOwner={hasEditAccess || Boolean(owner)}
key={i}
permission={Operation.UpdateTags}
position="left">
<CardListItem
card={card}
isActive={activeTier === card.id}
onSelect={handleCardSelection}
/>
</NonAdminAction>
))}
</div>
)}
{!hideTier &&
(isLoadingTierData ? (
<Loader />
) : (
<div className="tw-flex tw-flex-col" data-testid="cards">
{tierData.map((card, i) => (
<NonAdminAction
html={
<>
<p>You need to be owner to perform this action</p>
<p>Claim ownership from above </p>
</>
}
isOwner={hasEditAccess || Boolean(owner && !currentUser)}
key={i}
permission={Operation.UpdateTags}
position="left">
<CardListItem
card={card}
isActive={activeTier === card.id}
onSelect={handleCardSelection}
/>
</NonAdminAction>
))}
</div>
))}
<div className="tw-mt-6 tw-text-right" data-testid="buttons">
<Button
size="regular"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ const PipelineDetails = ({
value:
owner?.type === 'team'
? getTeamDetailsPath(owner?.name || '')
: owner?.name || '',
placeholderText: owner?.displayName || '',
: owner?.displayName || owner?.name || '',
placeholderText: owner?.displayName || owner?.name || '',
isLink: owner?.type === 'team',
openInNewTab: false,
},
Expand Down Expand Up @@ -196,12 +196,7 @@ const PipelineDetails = ({
: pipelineDetails.tags;
const updatedPipelineDetails = {
...pipelineDetails,
owner: newOwner
? {
...pipelineDetails.owner,
...newOwner,
}
: pipelineDetails.owner,
owner: newOwner ? newOwner : pipelineDetails.owner,
tags: tierTag,
};

Expand Down
19 changes: 15 additions & 4 deletions openmetadata-ui/src/main/resources/ui/src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const ROUTES = {
FEEDS: '/feeds',
DUMMY: '/dummy',
SERVICE: `/service/${PLACEHOLDER_ROUTE_SERVICE_CAT}/${PLACEHOLDER_ROUTE_SERVICE_TYPE}/${PLACEHOLDER_ROUTE_SERVICE_FQN}`,
SERVICE_WITH_TAB: `/service/${PLACEHOLDER_ROUTE_SERVICE_CAT}/${PLACEHOLDER_ROUTE_SERVICE_TYPE}/${PLACEHOLDER_ROUTE_SERVICE_FQN}/${PLACEHOLDER_ROUTE_TAB}`,
SERVICES: '/services',
USERS: '/users',
SCORECARD: '/scorecard',
Expand All @@ -148,6 +149,7 @@ export const ROUTES = {
DASHBOARD_DETAILS: `/dashboard/${PLACEHOLDER_ROUTE_DASHBOARD_FQN}`,
DASHBOARD_DETAILS_WITH_TAB: `/dashboard/${PLACEHOLDER_ROUTE_DASHBOARD_FQN}/${PLACEHOLDER_ROUTE_TAB}`,
DATABASE_DETAILS: `/database/${PLACEHOLDER_ROUTE_DATABASE_FQN}`,
DATABASE_DETAILS_WITH_TAB: `/database/${PLACEHOLDER_ROUTE_DATABASE_FQN}/${PLACEHOLDER_ROUTE_TAB}`,
PIPELINE_DETAILS: `/pipeline/${PLACEHOLDER_ROUTE_PIPELINE_FQN}`,
PIPELINE_DETAILS_WITH_TAB: `/pipeline/${PLACEHOLDER_ROUTE_PIPELINE_FQN}/${PLACEHOLDER_ROUTE_TAB}`,
USER_LIST: '/user-list',
Expand Down Expand Up @@ -194,14 +196,19 @@ export const getTableTabPath = (tableFQN: string, tab = 'schema') => {
export const getServiceDetailsPath = (
serviceFQN: string,
serviceType: string,
serviceCat: string
serviceCat: string,
tab?: string
) => {
let path = ROUTES.SERVICE;
let path = tab ? ROUTES.SERVICE_WITH_TAB : ROUTES.SERVICE;
path = path
.replace(PLACEHOLDER_ROUTE_SERVICE_CAT, serviceCat)
.replace(PLACEHOLDER_ROUTE_SERVICE_TYPE, serviceType)
.replace(PLACEHOLDER_ROUTE_SERVICE_FQN, serviceFQN);

if (tab) {
path = path.replace(PLACEHOLDER_ROUTE_TAB, tab);
}

return path;
};

Expand All @@ -214,10 +221,14 @@ export const getExplorePathWithSearch = (searchQuery = '', tab = 'tables') => {
return path;
};

export const getDatabaseDetailsPath = (databaseFQN: string) => {
let path = ROUTES.DATABASE_DETAILS;
export const getDatabaseDetailsPath = (databaseFQN: string, tab?: string) => {
let path = tab ? ROUTES.DATABASE_DETAILS_WITH_TAB : ROUTES.DATABASE_DETAILS;
path = path.replace(PLACEHOLDER_ROUTE_DATABASE_FQN, databaseFQN);

if (tab) {
path = path.replace(PLACEHOLDER_ROUTE_TAB, tab);
}

return path;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ import {
} from '../../utils/DashboardDetailsUtils';
import { getEntityLineage } from '../../utils/EntityUtils';
import { serviceTypeLogo } from '../../utils/ServiceUtils';
import {
getOwnerFromId,
getTagsWithoutTier,
getTierTags,
} from '../../utils/TableUtils';
import { getTagsWithoutTier, getTierTags } from '../../utils/TableUtils';
type ChartType = {
displayName: string;
} & Chart;
Expand Down Expand Up @@ -240,7 +236,7 @@ const DashboardDetailsPage = () => {
setDashboardId(id);
setDescription(description ?? '');
setFollowers(followers);
setOwner(getOwnerFromId(owner?.id));
setOwner(owner);
setTier(getTierTags(tags));
setTags(getTagsWithoutTier(tags));
setServiceType(serviceType);
Expand Down Expand Up @@ -391,7 +387,7 @@ const DashboardDetailsPage = () => {
.then((res) => {
setDashboardDetails(res.data);
setCurrentVersion(res.data.version);
setOwner(getOwnerFromId(res.data.owner?.id));
setOwner(res.data.owner);
setTier(getTierTags(res.data.tags));
resolve();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {
} from '../../utils/DatasetDetailsUtils';
import { getEntityLineage } from '../../utils/EntityUtils';
import { serviceTypeLogo } from '../../utils/ServiceUtils';
import { getOwnerFromId, getTierTags } from '../../utils/TableUtils';
import { getTierTags } from '../../utils/TableUtils';
import { getTableTags } from '../../utils/TagsUtils';

const DatasetDetailsPage: FunctionComponent = () => {
Expand Down Expand Up @@ -186,7 +186,7 @@ const DatasetDetailsPage: FunctionComponent = () => {
setTableId(id);
setCurrentVersion(version);
setTier(getTierTags(tags));
setOwner(getOwnerFromId(owner?.id));
setOwner(owner);
setFollowers(followers);
setDeleted(deleted);
setSlashedTableName([
Expand Down Expand Up @@ -349,7 +349,7 @@ const DatasetDetailsPage: FunctionComponent = () => {
const { version, owner, tags } = res.data;
setCurrentVersion(version);
setTableDetails(res.data);
setOwner(getOwnerFromId(owner?.id));
setOwner(owner);
setTier(getTierTags(tags));
resolve();
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ import {
pipelineDetailsTabs,
} from '../../utils/PipelineDetailsUtils';
import { serviceTypeLogo } from '../../utils/ServiceUtils';
import {
getOwnerFromId,
getTagsWithoutTier,
getTierTags,
} from '../../utils/TableUtils';
import { getTagsWithoutTier, getTierTags } from '../../utils/TableUtils';

const PipelineDetailsPage = () => {
const USERId = getCurrentUserId();
Expand Down Expand Up @@ -190,7 +186,7 @@ const PipelineDetailsPage = () => {
setPipelineId(id);
setDescription(description ?? '');
setFollowers(followers);
setOwner(getOwnerFromId(owner?.id));
setOwner(owner);
setTier(getTierTags(tags));
setTags(getTagsWithoutTier(tags));
setServiceType(serviceType);
Expand Down Expand Up @@ -319,7 +315,7 @@ const PipelineDetailsPage = () => {
.then((res) => {
setPipelineDetails(res.data);
setCurrentVersion(res.data.version);
setOwner(getOwnerFromId(res.data.owner?.id));
setOwner(res.data.owner);
setTier(getTierTags(res.data.tags));
resolve();
})
Expand Down

0 comments on commit e1d7550

Please sign in to comment.