-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Add datafeed query reset button (#73958)
* [ML] Add datafeed query reset button * changing id * adding translation * fix typo * default query refactor Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
d19883f
commit 278d324
Showing
4 changed files
with
100 additions
and
10 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.../application/jobs/new_job/pages/components/datafeed_step/components/reset_query/index.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,7 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { ResetQueryButton } from './reset_query'; |
75 changes: 75 additions & 0 deletions
75
...cation/jobs/new_job/pages/components/datafeed_step/components/reset_query/reset_query.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,75 @@ | ||
/* | ||
* 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 React, { FC, useContext, useState } from 'react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { | ||
EuiButtonEmpty, | ||
EuiConfirmModal, | ||
EuiOverlayMask, | ||
EuiCodeBlock, | ||
EuiSpacer, | ||
} from '@elastic/eui'; | ||
import { JobCreatorContext } from '../../../job_creator_context'; | ||
import { getDefaultDatafeedQuery } from '../../../../../utils/new_job_utils'; | ||
|
||
export const ResetQueryButton: FC = () => { | ||
const { jobCreator, jobCreatorUpdate } = useContext(JobCreatorContext); | ||
const [confirmModalVisible, setConfirmModalVisible] = useState(false); | ||
const [defaultQueryString] = useState(JSON.stringify(getDefaultDatafeedQuery(), null, 2)); | ||
|
||
const closeModal = () => setConfirmModalVisible(false); | ||
const showModal = () => setConfirmModalVisible(true); | ||
|
||
function resetDatafeed() { | ||
jobCreator.query = getDefaultDatafeedQuery(); | ||
jobCreatorUpdate(); | ||
closeModal(); | ||
} | ||
return ( | ||
<> | ||
{confirmModalVisible && ( | ||
<EuiOverlayMask> | ||
<EuiConfirmModal | ||
title={i18n.translate('xpack.ml.newJob.wizard.datafeedStep.resetQueryConfirm.title', { | ||
defaultMessage: 'Reset datafeed query', | ||
})} | ||
onCancel={closeModal} | ||
onConfirm={resetDatafeed} | ||
cancelButtonText={i18n.translate( | ||
'xpack.ml.newJob.wizard.datafeedStep.resetQueryConfirm.cancel', | ||
{ defaultMessage: 'Cancel' } | ||
)} | ||
confirmButtonText={i18n.translate( | ||
'xpack.ml.newJob.wizard.datafeedStep.resetQueryConfirm.confirm', | ||
{ defaultMessage: 'Confirm' } | ||
)} | ||
defaultFocusedButton="confirm" | ||
> | ||
<FormattedMessage | ||
id="xpack.ml.newJob.wizard.datafeedStep.resetQueryConfirm.description" | ||
defaultMessage="Set the datafeed query to be the default." | ||
/> | ||
|
||
<EuiSpacer size="s" /> | ||
|
||
<EuiCodeBlock language="js" fontSize="m" paddingSize="s"> | ||
{defaultQueryString} | ||
</EuiCodeBlock> | ||
</EuiConfirmModal> | ||
</EuiOverlayMask> | ||
)} | ||
|
||
<EuiButtonEmpty size="s" onClick={showModal}> | ||
<FormattedMessage | ||
id="xpack.ml.newJob.wizard.datafeedStep.resetQueryButton" | ||
defaultMessage="Reset datafeed query to default" | ||
/> | ||
</EuiButtonEmpty> | ||
</> | ||
); | ||
}; |
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