Skip to content

Commit

Permalink
type declarations to fix lint errors
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Tackett <[email protected]>
  • Loading branch information
Adam Tackett committed Aug 10, 2024
1 parent aea5eab commit 39c65a8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 47 deletions.
30 changes: 13 additions & 17 deletions public/components/overview/components/select_dashboard_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,23 @@ interface Props {
registerDashboard: () => void;
closeModalVisible: () => void;
}

export function SelectDashboardModal({
closeModal,
wrapper,
dashboards,
registerDashboard,
closeModalVisible,
}: Props) {
const [selectedOptionsState, setSelectedOptionsState] = useState<EuiComboBoxOptionOption[]>([]);
const [selectedId, setSelectedId] = useState('');
const [selectedOptionsState, setSelectedOptionsState] = useState<
Array<EuiComboBoxOptionOption<string>>
>([]);
const [selectedId, setSelectedId] = useState<string>('');
const [buttonIsActive, setButtonIsActive] = useState(false);

const onComboBoxChange = (options: EuiComboBoxOptionOption[]) => {
const onComboBoxChange = (options: Array<EuiComboBoxOptionOption<string>>) => {
if (options.length > 0) {
setButtonIsActive(options[0].value?.toString() !== selectedId);
setButtonIsActive(options[0].value !== selectedId);
}
setSelectedOptionsState(options);
};
Expand All @@ -58,20 +61,19 @@ export function SelectDashboardModal({
setSelectedId(uiSettingsService.get('observability:defaultDashboard'));
}, []);

const options: EuiComboBoxOptionOption[] = Object.keys(dashboards).map((key) => ({
const options: Array<EuiComboBoxOptionOption<string>> = Object.keys(dashboards).map((key) => ({
value: key,
label: dashboards[key].label,
}));

useEffect(() => {
if (selectedId) {
const currentTitle: EuiComboBoxOptionOption = {
const currentTitle: EuiComboBoxOptionOption<string> = {
value: selectedId,
label: dashboards[selectedId].label,
};
if (currentTitle) {
const comboBoxOption: Array<EuiComboBoxOptionOption<string>> = [currentTitle];
setSelectedOptionsState(comboBoxOption);
setSelectedOptionsState([currentTitle]);
setButtonIsActive(false);
}
}
Expand Down Expand Up @@ -99,15 +101,9 @@ export function SelectDashboardModal({
<EuiButton onClick={closeModal}>Cancel</EuiButton>
</EuiFlexItem>
<EuiFlexItem grow={false}>
{buttonIsActive ? (
<EuiButton onClick={onClickAdd} fill>
{wrapper.dashboardSelected ? 'Update' : 'Add'}
</EuiButton>
) : (
<EuiButton onClick={onClickAdd} fill disabled>
{wrapper.dashboardSelected ? 'Update' : 'Add'}
</EuiButton>
)}
<EuiButton onClick={onClickAdd} fill disabled={!buttonIsActive}>
{wrapper.dashboardSelected ? 'Update' : 'Add'}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiModalFooter>
Expand Down
53 changes: 29 additions & 24 deletions public/components/overview/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, { useEffect, useState } from 'react';
import { HashRouter, RouteComponentProps, Switch, Route } from 'react-router-dom';
import { EuiText } from '@elastic/eui';
import moment from 'moment';
import { TraceAnalyticsCoreDeps } from '../trace_analytics/home';
import { ChromeBreadcrumb } from '../../../../../src/core/public';
import { coreRefs } from '../../framework/core_refs';
import { ContentManagementPluginStart } from '../../../../../src/plugins/content_management/public';
Expand All @@ -24,23 +23,21 @@ const anomalyPluginID = 'anomalyDetection';

const uiSettingsKey = 'observability:defaultDashboard';

export type AppAnalyticsCoreDeps = TraceAnalyticsCoreDeps;

interface HomeProps extends RouteComponentProps, AppAnalyticsCoreDeps {
interface HomeProps extends RouteComponentProps {
parentBreadcrumbs: ChromeBreadcrumb[];
contentManagement: ContentManagementPluginStart;
}

let showModal;
let showModal: { (): void; (): void; (): void };
const wrapper = {
dashboardSelected: false,
};
let startDate;
let setStartDate;
let endDate;
let setEndDate;
let dashboardTitle;
let setDashboardTitle;
let startDate: string;
let setStartDate: (start: string) => void;
let endDate: string;
let setEndDate: (end: string) => void;
let dashboardTitle: string;
let setDashboardTitle: (arg0: string) => void;

coreRefs.contentManagement?.registerContentProvider({
id: 'custom_content',
Expand Down Expand Up @@ -144,7 +141,6 @@ export const Home = ({ ..._props }: HomeProps) => {
description: card.description,
title: card.title,
onClick: () => navigateToApp(card.url, '#/'),
getIcon: () => {},
getFooter: () => {
return (
<EuiText size="s" textAlign="left">
Expand Down Expand Up @@ -173,10 +169,11 @@ export const Home = ({ ..._props }: HomeProps) => {
getTargetArea: () => HOME_CONTENT_AREAS.DASHBOARD,
});
setIsRegistered(true);
if (dashboards && dashboards[uiSettingsService.get(uiSettingsKey)]) {
setDashboardTitle(dashboards[uiSettingsService.get(uiSettingsKey)].label);
setStartDate(dashboards[uiSettingsService.get(uiSettingsKey)].startDate);
setEndDate(dashboards[uiSettingsService.get(uiSettingsKey)].endDate);
const defaultDashboard = uiSettingsService.get(uiSettingsKey);
if (dashboards && defaultDashboard && dashboards[defaultDashboard]) {
setDashboardTitle(dashboards[defaultDashboard].label);
setStartDate(dashboards[defaultDashboard].startDate);
setEndDate(dashboards[defaultDashboard].endDate);
}
};

Expand All @@ -186,18 +183,25 @@ export const Home = ({ ..._props }: HomeProps) => {
type: 'dashboard',
})
.then((response) => {
const savedDashoards = response.savedObjects.reduce((acc, savedDashboard) => {
const savedDashboards = response.savedObjects.reduce((acc, savedDashboard) => {
const dashboardAttributes = savedDashboard.attributes as {
title: string;
timeFrom: string;
timeTo: string;
};
const id = savedDashboard.id.toString();
acc[id] = {
label: savedDashboard.attributes.title,
startDate: savedDashboard.attributes.timeFrom,
endDate: savedDashboard.attributes.timeTo,
value: id,
label: dashboardAttributes.title,
startDate: dashboardAttributes.timeFrom,
endDate: dashboardAttributes.timeTo,
};
return acc;
}, {} as DashboardDictionary);
setDashboards(savedDashoards);
if (uiSettingsService.get(uiSettingsKey)) {
setDashboardTitle(dashboards[uiSettingsService.get(uiSettingsKey)].label);
setDashboards(savedDashboards);
const defaultDashboard = uiSettingsService.get(uiSettingsKey);
if (defaultDashboard && dashboards[defaultDashboard]) {
setDashboardTitle(dashboards[defaultDashboard].label);
}
})
.catch((error) => {
Expand All @@ -207,7 +211,8 @@ export const Home = ({ ..._props }: HomeProps) => {

useEffect(() => {
registerCards();
if (uiSettingsService.get(uiSettingsKey)) {
const defaultDashboard = uiSettingsService.get(uiSettingsKey);
if (defaultDashboard) {
wrapper.dashboardSelected = true;
registerDashboard();
}
Expand Down
13 changes: 7 additions & 6 deletions public/plugin_helpers/plugin_overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ export const setupOverviewPage = (contentManagement: ContentManagementPluginSetu
title: 'Selector Section',
kind: 'custom',
render: (contents) => (
<>{contents.map((content) => (content.kind === 'custom' ? content.render() : null))}</>
<>
{contents.map((content, index) =>
content.kind === 'custom' ? (
<React.Fragment key={index}>{content.render()}</React.Fragment>
) : null
)}
</>
),
},
{
Expand All @@ -47,8 +53,3 @@ export const setupOverviewPage = (contentManagement: ContentManagementPluginSetu
],
});
};

// export const initHome = (contentManagement: ContentManagementPluginStart) => {
// //Delete if not needed
// //If we need something updated on start
// };

0 comments on commit 39c65a8

Please sign in to comment.