Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Jun 16, 2020
1 parent 57bbc8f commit 7f02d72
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,21 @@ describe('<ComponentTemplateDetails />', () => {
});

test('should render a footer with context menu', () => {
const { exists } = testBed;
const { exists, actions, component, find } = testBed;

// Verify footer exists
expect(exists('componentTemplateDetails.footer')).toBe(true);
expect(exists('manageComponentTemplateButton')).toBe(true);

// Click manage button and verify actions
act(() => {
actions.clickManageButton();
});

component.update();

expect(exists('manageComponentTemplateContextMenu')).toBe(true);
expect(find('manageComponentTemplateContextMenu.action').length).toEqual(1);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ const createActions = (testBed: TestBed<ComponentTemplateDetailsTestSubjects>) =
find('aliasesTab').simulate('click');
};

const clickManageButton = () => {
find('manageComponentTemplateButton').simulate('click');
};

return {
clickSettingsTab,
clickAliasesTab,
clickMappingsTab,
clickManageButton,
};
};

Expand Down Expand Up @@ -76,4 +81,6 @@ export type ComponentTemplateDetailsTestSubjects =
| 'noMappingsCallout'
| 'settingsTabContent'
| 'noSettingsCallout'
| 'manageComponentTemplateButton';
| 'manageComponentTemplateButton'
| 'manageComponentTemplateContextMenu'
| 'manageComponentTemplateContextMenu.action';
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
import { SectionLoading, TabSettings, TabAliases, TabMappings } from '../shared_imports';
import { useComponentTemplatesContext } from '../component_templates_context';
import { TabSummary } from './tab_summary';
import { ComponentTemplateTabs, TabType, Tab } from './tabs';
import { ComponentTemplateTabs, TabType } from './tabs';
import { ManageButton, ManageAction } from './manage_button';

interface Props {
Expand All @@ -43,7 +43,7 @@ export const ComponentTemplateDetailsFlyout: React.FunctionComponent<Props> = ({
componentTemplateName
);

const [activeTab, setActiveTab] = useState<Tab>(TabType.Summary);
const [activeTab, setActiveTab] = useState<TabType>('summary');

let content: React.ReactNode | undefined;

Expand Down Expand Up @@ -77,13 +77,11 @@ export const ComponentTemplateDetailsFlyout: React.FunctionComponent<Props> = ({
template: { settings, mappings, aliases },
} = componentTemplateDetails;

const tabToComponentMap: {
[key: string]: React.ReactNode;
} = {
[TabType.Summary]: <TabSummary componentTemplateDetails={componentTemplateDetails} />,
[TabType.Settings]: <TabSettings settings={settings} />,
[TabType.Mappings]: <TabMappings mappings={mappings} />,
[TabType.Aliases]: <TabAliases aliases={aliases} />,
const tabToComponentMap: Record<TabType, React.ReactNode> = {
summary: <TabSummary componentTemplateDetails={componentTemplateDetails} />,
settings: <TabSettings settings={settings} />,
mappings: <TabMappings mappings={mappings} />,
aliases: <TabAliases aliases={aliases} />,
};

const tabContent = tabToComponentMap[activeTab];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,26 @@ export const ManageButton: React.FunctionComponent<Props> = ({

const items: EuiContextMenuPanelItemDescriptor[] = actions.map(
({ name, icon, getIsDisabled, closePopoverOnClick, handleActionClick }) => {
const isDisabled = getIsDisabled ? getIsDisabled(componentTemplateDetails) : false;

return {
name,
icon,
disabled: getIsDisabled ? getIsDisabled(componentTemplateDetails) : false,
disabled: isDisabled,
toolTipContent: isDisabled ? (
<FormattedMessage
id="xpack.idxMgmt.componentTemplateDetails.manageButtonDisabledTooltipLabel"
defaultMessage="Template is in use and cannot be deleted"
/>
) : null,
onClick: () => {
handleActionClick();

if (closePopoverOnClick) {
setIsPopOverOpen(false);
}
},
'data-test-subj': 'action',
};
}
);
Expand Down Expand Up @@ -77,6 +86,7 @@ export const ManageButton: React.FunctionComponent<Props> = ({
>
<EuiContextMenu
initialPanelId={0}
data-test-subj="manageComponentTemplateContextMenu"
panels={[
{
id: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,39 @@ import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiTab, EuiTabs } from '@elastic/eui';

export type Tab = TabType.Summary | TabType.Mappings | TabType.Aliases | TabType.Settings;
export type TabType = 'summary' | 'mappings' | 'aliases' | 'settings';

export enum TabType {
Summary = 'summary',
Mappings = 'mappings',
Aliases = 'aliases',
Settings = 'settings',
interface Props {
setActiveTab: (id: TabType) => void;
activeTab: TabType;
}

interface Props {
setActiveTab: (id: Tab) => void;
activeTab: Tab;
interface Tab {
id: TabType;
name: string;
}

const TABS = [
const TABS: Tab[] = [
{
id: TabType.Summary,
id: 'summary',
name: i18n.translate('xpack.idxMgmt.componentTemplateDetails.summaryTabTitle', {
defaultMessage: 'Summary',
}),
},
{
id: TabType.Settings,
id: 'settings',
name: i18n.translate('xpack.idxMgmt.componentTemplateDetails.settingsTabTitle', {
defaultMessage: 'Settings',
}),
},
{
id: TabType.Mappings,
id: 'mappings',
name: i18n.translate('xpack.idxMgmt.componentTemplateDetails.mappingsTabTitle', {
defaultMessage: 'Mappings',
}),
},
{
id: TabType.Aliases,
id: 'aliases',
name: i18n.translate('xpack.idxMgmt.componentTemplateDetails.aliasesTabTitle', {
defaultMessage: 'Aliases',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { ScopedHistory } from 'kibana/public';

import { SectionLoading } from '../shared_imports';
import { SectionLoading, ComponentTemplateDeserialized } from '../shared_imports';
import { UIM_COMPONENT_TEMPLATE_LIST_LOAD } from '../constants';
import { ComponentTemplateDeserialized } from '../shared_imports';
import { useComponentTemplatesContext } from '../component_templates_context';
import { ComponentTemplateDetailsFlyout } from '../component_template_details';
import { EmptyPrompt } from './empty_prompt';
Expand Down

0 comments on commit 7f02d72

Please sign in to comment.