Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 67 additions & 45 deletions src/containers/Tenants/Tenants.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import {CirclePlus, TrashBin} from '@gravity-ui/icons';
import {CirclePlus, Pencil, TrashBin} from '@gravity-ui/icons';
import type {Column} from '@gravity-ui/react-data-table';
import DataTable from '@gravity-ui/react-data-table';
import type {DropdownMenuItem} from '@gravity-ui/uikit';
Expand All @@ -18,6 +18,7 @@ import {TenantNameWrapper} from '../../components/TenantNameWrapper/TenantNameWr
import {
useCreateDatabaseFeatureAvailable,
useDeleteDatabaseFeatureAvailable,
useEditDatabaseFeatureAvailable,
} from '../../store/reducers/capabilities/hooks';
import {
ProblemFilterValues,
Expand Down Expand Up @@ -70,6 +71,7 @@ export const Tenants = ({additionalTenantsProps}: TenantsProps) => {

const isCreateDBAvailable =
useCreateDatabaseFeatureAvailable() && uiFactory.onCreateDB !== undefined;
const isEditDBAvailable = useEditDatabaseFeatureAvailable() && uiFactory.onEditDB !== undefined;
const isDeleteDBAvailable =
useDeleteDatabaseFeatureAvailable() && uiFactory.onDeleteDB !== undefined;

Expand Down Expand Up @@ -238,51 +240,14 @@ export const Tenants = ({additionalTenantsProps}: TenantsProps) => {
},
];

if (isDeleteDBAvailable) {
columns.push({
name: 'actions',
header: '',
width: 40,
resizeable: false,
align: DataTable.CENTER,
render: ({row}) => {
const databaseId = row.UserAttributes?.database_id;
const databaseName = row.Name;

let menuItems: (DropdownMenuItem | DropdownMenuItem[])[] = [];

if (clusterName && databaseName && databaseId) {
menuItems = [
{
text: i18n('remove'),
iconStart: <TrashBin />,
action: () => {
uiFactory.onDeleteDB?.({
clusterName,
databaseId,
databaseName,
});
},
className: b('remove-db'),
},
];
}

if (!menuItems.length) {
return null;
}
return (
<DropdownMenu
defaultSwitcherProps={{
view: 'flat',
size: 's',
pin: 'brick-brick',
}}
items={menuItems}
/>
);
},
if (clusterName && (isDeleteDBAvailable || isEditDBAvailable)) {
const actionsColumn = getDBActionsColumn({
clusterName,
isDeleteDBAvailable,
isEditDBAvailable,
});

columns.push(actionsColumn);
}

if (filteredTenants.length === 0 && problemFilter !== ProblemFilterValues.ALL) {
Expand Down Expand Up @@ -314,3 +279,60 @@ export const Tenants = ({additionalTenantsProps}: TenantsProps) => {
</div>
);
};

function getDBActionsColumn({
clusterName,
isEditDBAvailable,
isDeleteDBAvailable,
}: {
clusterName: string;
isEditDBAvailable?: boolean;
isDeleteDBAvailable?: boolean;
}) {
return {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, such a column should be sticky.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue for this to discuss and do it later: #2310

  1. I don't want to add any changes to table while Anton is solving performance issues and doing a lot of tables refactoring - it may cause conflicts
  2. I think it should be discussed it with the designer first
  3. For our tables it may require some tricky css, because there are no sticky columns in react-data-table by props. So I'd prefer to do it after our planned tasks will be done

name: 'actions',
header: '',
width: 40,
resizeable: false,
align: DataTable.CENTER,
render: ({row}) => {
const menuItems: (DropdownMenuItem | DropdownMenuItem[])[] = [];

const databaseId = row.UserAttributes?.database_id;
const databaseName = row.Name;

if (clusterName && isEditDBAvailable) {
menuItems.push({
text: i18n('edit'),
iconStart: <Pencil />,
action: () => {
uiFactory.onEditDB?.({
clusterName,
databaseData: row,
});
},
});
}
if (clusterName && isDeleteDBAvailable && databaseName && databaseId) {
menuItems.push({
text: i18n('remove'),
iconStart: <TrashBin />,
action: () => {
uiFactory.onDeleteDB?.({
clusterName,
databaseId,
databaseName,
});
},
className: b('remove-db'),
});
}

if (!menuItems.length) {
return null;
}

return <DropdownMenu items={menuItems} />;
},
} satisfies Column<PreparedTenant>;
}
3 changes: 2 additions & 1 deletion src/containers/Tenants/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"create-database": "Create database",
"remove": "Remove"
"remove": "Remove",
"edit": "Edit"
}
4 changes: 4 additions & 0 deletions src/store/reducers/capabilities/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ export const useCreateDatabaseFeatureAvailable = () => {
return useGetMetaFeatureVersion('/meta/create_database') >= 1;
};

export const useEditDatabaseFeatureAvailable = () => {
return useGetMetaFeatureVersion('/meta/update_database') >= 1;
};

export const useDeleteDatabaseFeatureAvailable = () => {
return useGetMetaFeatureVersion('/meta/delete_database') >= 1;
};
7 changes: 7 additions & 0 deletions src/uiFactory/types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import type {PreparedTenant} from '../store/reducers/tenants/types';
import type {GetLogsLink} from '../utils/logs';
import type {GetMonitoringClusterLink, GetMonitoringLink} from '../utils/monitoring';

export interface UIFactory {
onCreateDB?: HandleCreateDB;
onEditDB?: HandleEditDB;
onDeleteDB?: HandleDeleteDB;

getLogsLink?: GetLogsLink;
Expand All @@ -12,6 +14,11 @@ export interface UIFactory {

export type HandleCreateDB = (params: {clusterName: string}) => Promise<boolean>;

export type HandleEditDB = (params: {
clusterName: string;
databaseData: PreparedTenant;
}) => Promise<boolean>;

export type HandleDeleteDB = (params: {
clusterName: string;
databaseName: string;
Expand Down
Loading