-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[serverless] Advanced Settings - Field Row components #165286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
clintandrewhall
merged 4 commits into
elastic:main
from
clintandrewhall:advanced_settings/field
Sep 11, 2023
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
12 changes: 12 additions & 0 deletions
12
packages/kbn-management/settings/components/field_input/README.mdx
This file contains hidden or 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,12 @@ | ||
| --- | ||
| id: management/settings/components/fieldInput | ||
| slug: /management/settings/components/field-input | ||
| title: Management Settings Field Input Component | ||
| description: A package containing a component for rendering and manipulating the raw value of a UiSetting in Field Row. | ||
| tags: ['management', 'settings'] | ||
| date: 2023-08-31 | ||
| --- | ||
|
|
||
| ## Description | ||
|
|
||
| This package contains a component for rendering and manipulating the raw value of a UiSetting. It's used primarily by the `FieldRow` component to drive unsaved or reset changes. |
12 changes: 12 additions & 0 deletions
12
packages/kbn-management/settings/components/field_input/__stories__/array_input.stories.tsx
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { getInputStory, getStory } from './common'; | ||
|
|
||
| export default getStory('Array Input', 'An input with an array value.'); | ||
| export const ArrayInput = getInputStory('array' as const); |
12 changes: 12 additions & 0 deletions
12
...ages/kbn-management/settings/components/field_input/__stories__/boolean_input.stories.tsx
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { getInputStory, getStory } from './common'; | ||
|
|
||
| export default getStory('Boolean Input', 'An input with a boolean value.'); | ||
| export const BooleanInput = getInputStory('boolean' as const); |
12 changes: 12 additions & 0 deletions
12
packages/kbn-management/settings/components/field_input/__stories__/color_input.stories.tsx
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { getInputStory, getStory } from './common'; | ||
|
|
||
| export default getStory('Color Input', 'An input with a color value.'); | ||
| export const ColorInput = getInputStory('color' as const); |
120 changes: 120 additions & 0 deletions
120
packages/kbn-management/settings/components/field_input/__stories__/common.tsx
This file contains hidden or 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,120 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import React from 'react'; | ||
| import type { ComponentMeta } from '@storybook/react'; | ||
| import { action } from '@storybook/addon-actions'; | ||
|
|
||
| import { EuiPanel } from '@elastic/eui'; | ||
| import { UiSettingsType } from '@kbn/core-ui-settings-common'; | ||
| import { SettingType, UiSettingMetadata } from '@kbn/management-settings-types'; | ||
| import { | ||
| useFieldDefinition, | ||
| getDefaultValue, | ||
| } from '@kbn/management-settings-field-definition/storybook'; | ||
|
|
||
| import { FieldInputProvider } from '../services'; | ||
| import { FieldInput as Component, FieldInput } from '../field_input'; | ||
| import { InputProps, OnChangeFn } from '../types'; | ||
|
|
||
| /** | ||
| * Props for a {@link FieldInput} Storybook story. | ||
| */ | ||
| export type StoryProps<T extends SettingType> = Pick<InputProps<T>, 'value' | 'isDisabled'>; | ||
|
|
||
| /** | ||
| * Interface defining available {@link https://storybook.js.org/docs/react/writing-stories/parameters parameters} | ||
| * for a {@link FieldInput} Storybook story. | ||
| */ | ||
| interface Params { | ||
| argTypes?: Record<string, unknown>; | ||
| settingFields?: Partial<UiSettingMetadata<UiSettingsType>>; | ||
| } | ||
|
|
||
| /** | ||
| * Interface defining types for available {@link https://storybook.js.org/docs/react/writing-stories/args arguments} | ||
| * for a {@link FieldInput} Storybook story. | ||
| */ | ||
| export interface Args { | ||
| /** True if the field is disabled, false otherwise. */ | ||
| isDisabled: boolean; | ||
| } | ||
|
|
||
| /** | ||
| * Default argument values for a {@link FieldInput} Storybook story. | ||
| */ | ||
| export const storyArgs = { | ||
| /** True if the field is disabled, false otherwise. */ | ||
| isDisabled: false, | ||
| }; | ||
|
|
||
| /** | ||
| * Utility function for returning a {@link FieldInput} Storybook story | ||
| * definition. | ||
| * @param title The title displayed in the Storybook UI. | ||
| * @param description The description of the story. | ||
| * @returns A Storybook Story. | ||
| */ | ||
| export const getStory = (title: string, description: string) => | ||
| ({ | ||
| title: `Settings/Field Input/${title}`, | ||
| description, | ||
| argTypes: { | ||
| isDisabled: { | ||
| name: 'Is field disabled?', | ||
| }, | ||
| value: { | ||
| name: 'Current saved value', | ||
| }, | ||
| }, | ||
| decorators: [ | ||
| (Story) => ( | ||
| <FieldInputProvider showDanger={action('showDanger')}> | ||
| <EuiPanel style={{ width: 500 }}> | ||
| <Story /> | ||
| </EuiPanel> | ||
| </FieldInputProvider> | ||
| ), | ||
| ], | ||
| } as ComponentMeta<typeof Component>); | ||
|
|
||
| /** | ||
| * Utility function for returning a {@link FieldInput} Storybook story. | ||
| * @param type The type of the UiSetting for this {@link FieldRow}. | ||
| * @param params Additional, optional {@link https://storybook.js.org/docs/react/writing-stories/parameters parameters}. | ||
| * @returns A Storybook Story. | ||
| */ | ||
| export const getInputStory = (type: SettingType, params: Params = {}) => { | ||
| const Story = ({ value, isDisabled = false }: StoryProps<typeof type>) => { | ||
| const setting: UiSettingMetadata<typeof type> = { | ||
| type, | ||
| value, | ||
| userValue: value, | ||
| ...params.settingFields, | ||
| }; | ||
|
|
||
| const [field, unsavedChange, onChangeFn] = useFieldDefinition(setting); | ||
|
|
||
| const onChange: OnChangeFn<typeof type> = (newChange) => { | ||
| onChangeFn(newChange); | ||
| }; | ||
| return ( | ||
| <FieldInput | ||
| {...{ field, isInvalid: unsavedChange.isInvalid, unsavedChange, onChange, isDisabled }} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| Story.args = { | ||
| value: getDefaultValue(type), | ||
| ...params.argTypes, | ||
| ...storyArgs, | ||
| }; | ||
|
|
||
| return Story; | ||
| }; |
12 changes: 12 additions & 0 deletions
12
packages/kbn-management/settings/components/field_input/__stories__/image_input.stories.tsx
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { getInputStory, getStory } from './common'; | ||
|
|
||
| export default getStory('Image Input', 'An input with an image value.'); | ||
| export const ImageInput = getInputStory('image' as const); |
12 changes: 12 additions & 0 deletions
12
packages/kbn-management/settings/components/field_input/__stories__/json_input.stories.tsx
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { getInputStory, getStory } from './common'; | ||
|
|
||
| export default getStory('JSON Input', 'An input with a JSON value.'); | ||
| export const JSONInput = getInputStory('json' as const); |
12 changes: 12 additions & 0 deletions
12
...ges/kbn-management/settings/components/field_input/__stories__/markdown_input.stories.tsx
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { getInputStory, getStory } from './common'; | ||
|
|
||
| export default getStory('Markdown Input', 'An input with a markdown value.'); | ||
| export const MarkdownInput = getInputStory('markdown' as const); |
12 changes: 12 additions & 0 deletions
12
packages/kbn-management/settings/components/field_input/__stories__/number_input.stories.tsx
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { getInputStory, getStory } from './common'; | ||
|
|
||
| export default getStory('Number Input', 'An input with a number value.'); | ||
| export const NumberInput = getInputStory('number' as const); |
27 changes: 27 additions & 0 deletions
27
packages/kbn-management/settings/components/field_input/__stories__/select_input.stories.tsx
This file contains hidden or 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,27 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { getInputStory, getStory } from './common'; | ||
|
|
||
| const argTypes = { | ||
| value: { | ||
| name: 'Current saved value', | ||
| control: { | ||
| type: 'select', | ||
| options: ['option1', 'option2', 'option3'], | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| const settingFields = { | ||
| optionLabels: { option1: 'Option 1', option2: 'Option 2', option3: 'Option 3' }, | ||
| options: ['option1', 'option2', 'option3'], | ||
| }; | ||
|
|
||
| export default getStory('Select Input', 'An input with multiple values.'); | ||
| export const SelectInput = getInputStory('select' as const, { argTypes, settingFields }); | ||
12 changes: 12 additions & 0 deletions
12
packages/kbn-management/settings/components/field_input/__stories__/text_input.stories.tsx
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| import { getInputStory, getStory } from './common'; | ||
|
|
||
| export default getStory('String Input', 'An input with a string value.'); | ||
| export const StringInput = getInputStory('string' as const); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.