Skip to content

Commit

Permalink
feat: add ReadOnly label to replicated tables (#970)
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov authored Jul 3, 2024
1 parent 071b0a7 commit 669f7f0
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 15 deletions.
6 changes: 4 additions & 2 deletions src/components/InfoViewer/InfoViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React from 'react';

import {cn} from '../../utils/cn';

import i18n from './i18n';

import './InfoViewer.scss';

export interface InfoViewerItem {
Expand All @@ -10,7 +12,7 @@ export interface InfoViewerItem {
}

export interface InfoViewerProps {
title?: string;
title?: React.ReactNode;
info?: InfoViewerItem[];
dots?: boolean;
size?: 's';
Expand Down Expand Up @@ -53,7 +55,7 @@ export const InfoViewer = ({
))}
</div>
) : (
<React.Fragment>No {title} data</React.Fragment>
i18n('no-data')
)}
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion src/components/InfoViewer/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"common.created": "Created",
"common.type": "Type"
"common.type": "Type",
"no-data": "No data"
}
3 changes: 1 addition & 2 deletions src/components/InfoViewer/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {registerKeysets} from '../../../utils/i18n';

import en from './en.json';
import ru from './ru.json';

const COMPONENT = 'ydb-components-info-viewer';

export default registerKeysets(COMPONENT, {ru, en});
export default registerKeysets(COMPONENT, {en});
4 changes: 0 additions & 4 deletions src/components/InfoViewer/i18n/ru.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {InfoViewer} from '../../../../../components/InfoViewer';
import type {KeyValueRow} from '../../../../../types/api/query';
import type {EPathType, TEvDescribeSchemeResult} from '../../../../../types/api/schema';
import {cn} from '../../../../../utils/cn';
import {getEntityName} from '../../../utils';
import {EntityTitle} from '../../../EntityTitle/EntityTitle';

import i18n from './i18n';
import {prepareTableInfo} from './prepareTableInfo';
Expand All @@ -20,7 +20,7 @@ interface TableInfoProps {
}

export const TableInfo = ({data, type, olapStats}: TableInfoProps) => {
const entityName = getEntityName(data?.PathDescription);
const title = <EntityTitle data={data?.PathDescription} />;

const {
generalInfo = [],
Expand All @@ -33,9 +33,9 @@ export const TableInfo = ({data, type, olapStats}: TableInfoProps) => {
<div className={b()}>
<InfoViewer
info={generalInfo}
title={entityName}
title={title}
className={b('info-block')}
renderEmptyState={() => <div className={b('title')}>{entityName}</div>}
renderEmptyState={() => <div className={b('title')}>{title}</div>}
/>
<div className={b('row')}>
<div className={b('col')}>
Expand Down
23 changes: 23 additions & 0 deletions src/containers/Tenant/EntityTitle/EntityTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import {Flex, Label} from '@gravity-ui/uikit';

import type {TPathDescription} from '../../../types/api/schema';
import i18n from '../i18n';
import {getEntityName, isReadOnlyTable} from '../utils';

interface EntityTitleProps {
data?: TPathDescription;
}

export function EntityTitle({data}: EntityTitleProps) {
const entityName = getEntityName(data);

if (isReadOnlyTable(data)) {
return (
<Flex gap={1} wrap={'nowrap'}>
{entityName} <Label>{i18n('label.read-only')}</Label>
</Flex>
);
}

return entityName;
}
5 changes: 3 additions & 2 deletions src/containers/Tenant/ObjectSummary/ObjectSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import type {InfoViewerItem} from '../../../components/InfoViewer/InfoViewer';
import {LinkWithIcon} from '../../../components/LinkWithIcon/LinkWithIcon';
import {Loader} from '../../../components/Loader';
import SplitPane from '../../../components/SplitPane';
import {getEntityName} from '../../../containers/Tenant/utils';
import routes, {createExternalUILink, createHref} from '../../../routes';
import {schemaApi, setShowPreview} from '../../../store/reducers/schema/schema';
import {
Expand All @@ -33,6 +32,7 @@ import {
import {formatDateTime, formatSecondsToHours} from '../../../utils/dataFormatters/dataFormatters';
import {useTypedDispatch, useTypedSelector} from '../../../utils/hooks';
import {Acl} from '../Acl/Acl';
import {EntityTitle} from '../EntityTitle/EntityTitle';
import {SchemaTree} from '../Schema/SchemaTree/SchemaTree';
import {SchemaViewer} from '../Schema/SchemaViewer/SchemaViewer';
import {TENANT_INFO_TABS, TENANT_SCHEMA_TAB, TenantTabsGroups} from '../TenantPages';
Expand Down Expand Up @@ -159,7 +159,8 @@ export function ObjectSummary({
});

const {PathDescription} = currentObjectData;
const title = getEntityName(PathDescription);

const title = <EntityTitle data={PathDescription} />;

const getPathTypeOverview: Record<EPathType, (() => InfoViewerItem[]) | undefined> = {
[EPathType.EPathTypeInvalid]: undefined,
Expand Down
1 change: 1 addition & 0 deletions src/containers/Tenant/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"summary.mode": "Mode",
"summary.format": "Format",
"summary.retention": "Retention",
"label.read-only": "ReadOnly",
"actions.copied": "The path is copied to the clipboard",
"actions.notCopied": "Couldn’t copy the path",
"actions.copyPath": "Copy path",
Expand Down
6 changes: 6 additions & 0 deletions src/containers/Tenant/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ export const getEntityName = (pathDescription?: TPathDescription) => {

return mapPathTypeToEntityName(PathType, PathSubType);
};

export const isReadOnlyTable = (pathDescription?: TPathDescription) => {
return pathDescription?.UserAttributes?.some(({Key, Value}) => {
return Key === '__async_replica' && Value === 'true';
});
};
6 changes: 6 additions & 0 deletions src/types/api/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface TPathDescription {
/** info about the path itself */
Self?: TDirEntry;
DomainDescription?: TDomainDescription;
UserAttributes?: TUserAttribute[];

// for directory
Children?: TDirEntry[];
Expand Down Expand Up @@ -309,3 +310,8 @@ interface TTablePartition {
/** uint64 */
DatashardId?: string;
}

interface TUserAttribute {
Key?: string;
Value?: string;
}

0 comments on commit 669f7f0

Please sign in to comment.