-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Watcher history page: port to react (#33047)
Get watch detail page ported to react.
- Loading branch information
Paul Sanwald
authored
Apr 12, 2019
1 parent
d22e9c2
commit 0078417
Showing
9 changed files
with
569 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...gins/watcher/public/sections/watch_detail/components/watch_detail/watch_action_status.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { InjectedIntl, injectI18n } from '@kbn/i18n/react'; | ||
import React from 'react'; | ||
import { EuiIcon } from '@elastic/eui'; | ||
import { WATCH_STATES } from '../../../../../common/constants/watch_states'; | ||
|
||
const WatchActionStatusUi = ({ intl, watchState }: { intl: InjectedIntl; watchState: string }) => { | ||
const stateToIcon: { [key: string]: JSX.Element } = { | ||
[WATCH_STATES.OK]: <EuiIcon type="check" color="green" />, | ||
[WATCH_STATES.DISABLED]: <EuiIcon type="minusInCircle" color="grey" />, | ||
[WATCH_STATES.FIRING]: <EuiIcon type="play" color="primary" />, | ||
[WATCH_STATES.ERROR]: <EuiIcon type="crossInACircleFilled" color="red" />, | ||
[WATCH_STATES.CONFIG_ERROR]: <EuiIcon type="crossInACircleFilled" color="red" />, | ||
}; | ||
|
||
return <div>{stateToIcon[watchState]}</div>; | ||
}; | ||
|
||
export const WatchActionStatus = injectI18n(WatchActionStatusUi); |
102 changes: 102 additions & 0 deletions
102
...s/watcher/public/sections/watch_detail/components/watch_detail/watch_detail_component.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiInMemoryTable, | ||
EuiSpacer, | ||
EuiText, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react'; | ||
import React, { Fragment, useEffect, useState } from 'react'; | ||
import { fetchWatchDetail } from '../../../../lib/api'; | ||
import { WatchActionStatus } from './watch_action_status'; | ||
|
||
const WatchDetailUi = ({ intl, watchId }: { intl: InjectedIntl; watchId: string }) => { | ||
const [isWatchesLoading, setIsWatchesLoading] = useState<boolean>(true); | ||
const [actions, setWatchActions] = useState([]); | ||
|
||
const pagination = { | ||
initialPageSize: 10, | ||
pageSizeOptions: [10, 50, 100], | ||
}; | ||
|
||
const columns = [ | ||
{ | ||
field: 'id', | ||
name: i18n.translate('xpack.watcher.sections.watchDetail.watchTable.actionHeader', { | ||
defaultMessage: 'Action', | ||
}), | ||
sortable: true, | ||
truncateText: true, | ||
render: (action: string) => { | ||
return <EuiText>{action}</EuiText>; | ||
}, | ||
}, | ||
{ | ||
field: 'state', | ||
name: i18n.translate('xpack.watcher.sections.watchDetail.watchTable.stateHeader', { | ||
defaultMessage: 'State', | ||
}), | ||
sortable: true, | ||
truncateText: true, | ||
render: (state: string) => { | ||
return ( | ||
<EuiFlexGroup gutterSize="xs" alignItems="center"> | ||
<EuiFlexItem grow={false}> | ||
<WatchActionStatus watchState={state} /> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false} className="watchState__message"> | ||
<EuiText>{state}</EuiText> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}, | ||
}, | ||
]; | ||
const loadWatchActions = async () => { | ||
const loadedWatchActions = await fetchWatchDetail(watchId); | ||
setWatchActions(loadedWatchActions.watchStatus.actionStatuses); | ||
setIsWatchesLoading(false); | ||
}; | ||
useEffect(() => { | ||
loadWatchActions(); | ||
// only run the first time the component loads | ||
}, []); | ||
|
||
return ( | ||
<Fragment> | ||
<EuiTitle size="m"> | ||
<h1> | ||
<FormattedMessage | ||
id="xpack.watcher.sections.watchDetail.header" | ||
defaultMessage="Current status" | ||
/> | ||
</h1> | ||
</EuiTitle> | ||
<EuiSpacer size="s" /> | ||
<EuiInMemoryTable | ||
items={actions} | ||
itemId="id" | ||
columns={columns} | ||
pagination={pagination} | ||
sorting={true} | ||
loading={isWatchesLoading} | ||
message={ | ||
<FormattedMessage | ||
id="xpack.watcher.sections.watchDetail.watchTable.noWatchesMessage" | ||
defaultMessage="No current status" | ||
/> | ||
} | ||
/> | ||
</Fragment> | ||
); | ||
}; | ||
|
||
export const WatchDetail = injectI18n(WatchDetailUi); |
Oops, something went wrong.