-
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.
[Ingest Pipelines] Add new two columns detail layout to pipeline deta…
…ils page (#181003)
- Loading branch information
1 parent
83021ed
commit ab15175
Showing
11 changed files
with
336 additions
and
121 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
68 changes: 68 additions & 0 deletions
68
...ugins/ingest_pipelines/public/application/components/pipeline_form/bulk_request_panel.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,68 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { | ||
EuiSpacer, | ||
EuiPanel, | ||
EuiCodeBlock, | ||
EuiText, | ||
EuiSwitch, | ||
EuiSwitchEvent, | ||
} from '@elastic/eui'; | ||
|
||
const bulkRequestExample = `PUT books/_bulk?pipeline=my-pipeline | ||
{ "create":{ } } | ||
{ "name": "Snow Crash", "author": "Neal Stephenson" } | ||
{ "create":{ } } | ||
{ "name": "Revelation Space", "author": "Alastair Reynolds" } | ||
`; | ||
|
||
const singleRequestExample = `POST books/_doc?pipeline=my-pipeline-name | ||
{ | ||
"name": "Snow Crash", | ||
"author": "Neal Stephenson" | ||
} | ||
`; | ||
|
||
export const BulkRequestPanel = () => { | ||
const [showBulkToggle, setShowBulkToggle] = useState(true); | ||
|
||
return ( | ||
<EuiPanel hasShadow={false} hasBorder grow={false}> | ||
<EuiText size="s"> | ||
<strong> | ||
<FormattedMessage | ||
id="xpack.ingestPipelines.form.bulkCardTitle" | ||
defaultMessage="How to use this pipeline during data ingestion" | ||
/> | ||
</strong> | ||
</EuiText> | ||
|
||
<EuiSpacer size="m" /> | ||
|
||
<EuiSwitch | ||
compressed | ||
label={ | ||
<FormattedMessage | ||
id="xpack.ingestPipelines.form.bulkRequestToggle" | ||
defaultMessage="Bulk request" | ||
/> | ||
} | ||
checked={showBulkToggle} | ||
onChange={(e: EuiSwitchEvent) => setShowBulkToggle(e.target.checked)} | ||
/> | ||
|
||
<EuiSpacer size="m" /> | ||
|
||
<EuiCodeBlock language="json" overflowHeight={250} isCopyable> | ||
{showBulkToggle ? bulkRequestExample : singleRequestExample} | ||
</EuiCodeBlock> | ||
</EuiPanel> | ||
); | ||
}; |
107 changes: 107 additions & 0 deletions
107
...lugins/ingest_pipelines/public/application/components/pipeline_form/collapsible_panel.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,107 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useState, useEffect, ReactNode } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { | ||
EuiSpacer, | ||
EuiSwitch, | ||
EuiPanel, | ||
EuiAccordion, | ||
EuiAccordionProps, | ||
useGeneratedHtmlId, | ||
EuiSwitchEvent, | ||
EuiSwitchProps, | ||
} from '@elastic/eui'; | ||
import { useFormContext, useFormData } from '../../../shared_imports'; | ||
|
||
export interface CollapsiblePanelRenderProps { | ||
isEnabled: boolean; | ||
} | ||
|
||
interface Props { | ||
title: ReactNode | string; | ||
fieldName: string; | ||
initialToggleState: boolean; | ||
toggleProps?: Partial<EuiSwitchProps>; | ||
accordionProps?: Partial<EuiAccordionProps>; | ||
children: (options: CollapsiblePanelRenderProps) => ReactNode; | ||
} | ||
|
||
type AccordionStatus = 'open' | 'closed'; | ||
|
||
export const CollapsiblePanel: React.FunctionComponent<Props> = ({ | ||
title, | ||
children, | ||
fieldName, | ||
toggleProps, | ||
accordionProps, | ||
initialToggleState, | ||
}) => { | ||
const form = useFormContext(); | ||
const [formData] = useFormData({ form }); | ||
|
||
const accordionId = useGeneratedHtmlId({ prefix: 'collapsiblerPanel' }); | ||
const [isEnabled, setIsEnabled] = useState<boolean>(initialToggleState); | ||
const [trigger, setTrigger] = useState<AccordionStatus>(isEnabled ? 'open' : 'closed'); | ||
|
||
// We need to keep track of the initial field value for when the user | ||
// disable the enabled toggle (set field value to null) and then re-enable it. | ||
// In this scenario we want to show the initial value of the form. | ||
const [initialValue, setInitialValue] = useState(); | ||
useEffect(() => { | ||
if (initialValue === undefined && formData[fieldName]) { | ||
setInitialValue(formData[fieldName]); | ||
} | ||
}, [formData, initialValue, fieldName]); | ||
|
||
const onToggleChange = (e: EuiSwitchEvent) => { | ||
const isChecked = !!e.target.checked; | ||
|
||
setIsEnabled(isChecked); | ||
setTrigger(isChecked ? 'open' : 'closed'); | ||
|
||
if (isChecked) { | ||
form.setFieldValue(fieldName, initialValue || ''); | ||
} else { | ||
form.setFieldValue(fieldName, ''); | ||
} | ||
}; | ||
|
||
const onAccordionToggle = (isOpen: boolean) => { | ||
const newState = isOpen ? 'open' : 'closed'; | ||
setTrigger(newState); | ||
}; | ||
|
||
return ( | ||
<EuiPanel hasShadow={false} hasBorder grow={false}> | ||
<EuiAccordion | ||
{...accordionProps} | ||
id={accordionId} | ||
onToggle={onAccordionToggle} | ||
forceState={trigger} | ||
buttonContent={title} | ||
extraAction={ | ||
<EuiSwitch | ||
{...toggleProps} | ||
label={ | ||
<FormattedMessage | ||
id="xpack.ingestPipelines.collapsiblePanelToggle" | ||
defaultMessage="Enabled" | ||
/> | ||
} | ||
checked={isEnabled} | ||
onChange={onToggleChange} | ||
/> | ||
} | ||
> | ||
<EuiSpacer size="l" /> | ||
{children({ isEnabled })} | ||
</EuiAccordion> | ||
</EuiPanel> | ||
); | ||
}; |
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
Oops, something went wrong.