Skip to content

Commit

Permalink
[Feature Branch] Resolve review comments (#1154)
Browse files Browse the repository at this point in the history
Signed-off-by: Chang Liu <[email protected]>
  • Loading branch information
cliu123 authored Oct 24, 2022
1 parent e204d71 commit fa1436c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
6 changes: 5 additions & 1 deletion public/apps/account/account-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export async function setupTopNavButton(coreStart: CoreStart, config: ClientConf

let tenant: string | undefined;
if (config.multitenancy.enabled && config.multitenancy.enable_aggregation_view) {
tenant = await fetchCurrentTenant(coreStart.http);
try {
tenant = await fetchCurrentTenant(coreStart.http);
} catch (e) {
console.log(e);
}
} else {
tenant = accountInfo.user_requested_tenant;
}
Expand Down
26 changes: 26 additions & 0 deletions public/apps/configuration/utils/tenant-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import { HttpStart } from 'opensearch-dashboards/public';
import { map } from 'lodash';
import React from 'react';
import { i18n } from '@osd/i18n';
import {
API_ENDPOINT_TENANTS,
API_ENDPOINT_MULTITENANCY,
Expand All @@ -39,6 +41,8 @@ export const globalTenantName = 'global_tenant';
export const GLOBAL_TENANT = '';
export const PRIVATE_TENANT = '__user__';
export const DEFAULT_TENANT = 'default';
export const GLOBAL_TENANT_RENDERING_TEXT = 'Global';
export const PRIVATE_TENANT_RENDERING_TEXT = 'Private';
export const GLOBAL_USER_DICT: { [key: string]: string } = {
Label: 'Global',
Value: GLOBAL_TENANT,
Expand Down Expand Up @@ -181,3 +185,25 @@ export function isPrivateTenant(selectedTenant: string | null) {
export function isGlobalTenant(selectedTenant: string | null) {
return selectedTenant !== null && selectedTenant === GLOBAL_TENANT;
}

export const tenantColumn = {
id: 'tenant_column',
euiColumn: {
field: 'namespaces',
name: <div>Tenant</div>,
dataType: 'string',
render: (value: any[][]) => {
let text = value.flat()[0];
if (isGlobalTenant(text)) {
text = GLOBAL_TENANT_RENDERING_TEXT;
} else if (isPrivateTenant(text)) {
text = PRIVATE_TENANT_RENDERING_TEXT;
}
text = i18n.translate('savedObjectsManagement.objectsTable.table.columnTenantName', {
defaultMessage: text,
});
return <div>{text}</div>;
},
},
loadData: () => {},
};
28 changes: 4 additions & 24 deletions public/plugin.tsx → public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import { BehaviorSubject } from 'rxjs';
import { SavedObjectsManagementColumn } from 'src/plugins/saved_objects_management/public';
import React from 'react';
import { i18n } from '@osd/i18n';
import {
AppMountParameters,
AppStatus,
Expand Down Expand Up @@ -48,7 +46,7 @@ import {
} from './types';
import { addTenantToShareURL } from './services/shared-link';
import { interceptError } from './utils/logout-utils';
import { isGlobalTenant, isPrivateTenant } from './apps/configuration/utils/tenant-utils';
import { tenantColumn } from './apps/configuration/utils/tenant-utils';

async function hasApiPermission(core: CoreSetup): Promise<boolean | undefined> {
try {
Expand Down Expand Up @@ -156,27 +154,9 @@ export class SecurityPlugin
);

if (config.multitenancy.enabled && config.multitenancy.enable_aggregation_view) {
deps.savedObjectsManagement.columns.register(({
id: 'tenant_column',
euiColumn: {
field: 'namespaces',
name: <div>Tenant</div>,
dataType: 'string',
render: (value: any[][]) => {
let text = value.flat()[0];
if (isGlobalTenant(text)) {
text = GLOBAL_TENANT_RENDERING_TEXT;
} else if (isPrivateTenant(text)) {
text = PRIVATE_TENANT_RENDERING_TEXT;
}
text = i18n.translate('savedObjectsManagement.objectsTable.table.columnTenantName', {
defaultMessage: text,
});
return <div>{text}</div>;
},
},
loadData: () => {},
} as unknown) as SavedObjectsManagementColumn<string>);
deps.savedObjectsManagement.columns.register(
(tenantColumn as unknown) as SavedObjectsManagementColumn<string>
);
}

// Return methods that should be available to other plugins
Expand Down

0 comments on commit fa1436c

Please sign in to comment.