Skip to content
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

System index templates can't be edited #55229

Merged

Conversation

jkelastic
Copy link
Contributor

Summary

Fixed # 52566 Removed the validator that checks for system indices and disable editing on index templates

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@jkelastic jkelastic added release_note:fix Feature:Index Management Index and index templates UI v8.0.0 Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.7.0 labels Jan 17, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/es-ui (Team:Elasticsearch UI)

@jkelastic
Copy link
Contributor Author

I think we still want this validation when creating an index template. By deleting this code, I think it will remove it from both creating and editing. I reached out to @sebelga to see the best way to approach this with the form lib.

copied previous comments over to this new branch

@jkelastic
Copy link
Contributor Author

@alisonelizabeth I've recreated all 3 branches. Things look good now. Sorry for the inconvenience.

cc @sebelga

@@ -68,14 +68,6 @@ export const schemas: Record<string, FormSchema> = {
),
}),
},
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As from my comment on the other PR, we should keep this validation for when we create new template.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copying the original suggestion here for reference:

So here we have multiple options

  • Add a skipValidation prop to UseField (that would go along with the enabled: false
  • Be more granular and being able to provide validation IDs to be skipped
    validationsToSkip={['startWithDot']}
  • Extract and export the name config from the schema. Then add it on the UseField without the validations
import { schemas, nameConfig } from '../template_form_schemas';
const { validations, nameConfigWithoutValidations } = nameConfig;

// And then use that config when editing

<UseField
  path="name"
  componentProps={{
    idAria: name.idAria,
    ['data-test-subj']: name.testSubject,
    euiFieldProps: { disabled: isEditing },
  }}
  config={ isEditing ? nameConfigWithoutValidations : nameConfig }
/>

I would go with the last one as it is simpler and we don't need to touch the lib for now. It would be a nice enhancement though.

(#55145 (comment))

Copy link
Contributor Author

@jkelastic jkelastic Jan 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put the above in step_logstics.tsx, but it says nameConfig doesn't exist in ../template_form_schemas . I must not be getting this correct.

Screen Shot 2020-01-22 at 3 28 48 PM

Screen Shot 2020-01-22 at 3 28 28 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you need to extract the config from the schema. Like this

// template_form_schema.tsx

import {
  FormSchema,
  FIELD_TYPES,
  VALIDATION_TYPES,
  FieldConfig, // Add this import
} from '../../../../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib';

// ...

export const nameConfig: FieldConfig = {
  type: FIELD_TYPES.TEXT,
  label: i18n.translate('xpack.idxMgmt.templateForm.stepLogistics.fieldNameLabel', {
    defaultMessage: 'Name',
  }),
  validations: [
    {
      validator: emptyField(
        i18n.translate('xpack.idxMgmt.templateValidation.templateNameRequiredError', {
          defaultMessage: 'A template name is required.',
        })
      ),
    },
    {
      validator: containsCharsField({
        chars: ' ',
        message: i18n.translate('xpack.idxMgmt.templateValidation.templateNameSpacesError', {
          defaultMessage: 'Spaces are not allowed in a template name.',
        }),
      }),
    },
    {
      validator: startsWithField({
        char: '_',
        message: i18n.translate('xpack.idxMgmt.templateValidation.templateNameUnderscoreError', {
          defaultMessage: 'A template name must not start with an underscore.',
        }),
      }),
    },
    {
      validator: startsWithField({
        char: '.',
        message: i18n.translate('xpack.idxMgmt.templateValidation.templateNamePeriodError', {
          defaultMessage: 'A template name must not start with a period.',
        }),
      }),
    },
    {
      validator: containsCharsField({
        chars: INVALID_TEMPLATE_NAME_CHARS,
        message: ({ charsFound }) =>
          i18n.translate('xpack.idxMgmt.templateValidation.templateNameInvalidaCharacterError', {
            defaultMessage: 'A template name must not contain the character "{invalidChar}"',
            values: { invalidChar: charsFound[0] },
          }),
      }),
    },
    {
      validator: lowerCaseStringField(
        i18n.translate('xpack.idxMgmt.templateValidation.templateNameLowerCaseRequiredError', {
          defaultMessage: 'The template name must be in lowercase.',
        })
      ),
    },
  ],
};

export const schemas: Record<string, FormSchema> = {
  logistics: {
    name: nameConfig, // use it here
    ...
  },
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebelga thank you for all the detailed steps. I have a question, if const { validations, nameConfigWithoutValidations } = nameConfig; then nameConfigWithoutValidations would still always validate the system indices correct? We need to remove the period validation

    {
      validator: startsWithField({
        char: '.',
        message: i18n.translate('xpack.idxMgmt.templateValidation.templateNamePeriodError', {
          defaultMessage: 'A template name must not start with a period.',
        }),
      }),
    },

from nameConfig

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebelga I've got some help from @alisonelizabeth and sorted out my mistakes and confusion. I've uploaded the modified code. Please help check my code again. Thank you!

Copy link
Contributor

@sebelga sebelga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code LGTM! I haven't tested locally. Thanks for making these changes!

@jkelastic
Copy link
Contributor Author

@elasticmachine merge upstream

@jkelastic
Copy link
Contributor Author

Code LGTM! I haven't tested locally. Thanks for making these changes!

No problem, happy to be able to contribute and make a difference!

@alisonelizabeth
Copy link
Contributor

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jkelastic jkelastic merged commit b7bcff7 into elastic:master Jan 30, 2020
@jkelastic jkelastic deleted the bugfix/index_mgmt_systemAllowIndices branch January 30, 2020 18:30
@cjcenizal
Copy link
Contributor

@alisonelizabeth @jkelastic @sebelga I just want to double-check -- has this been tested locally and verified to fix the issue?

@alisonelizabeth
Copy link
Contributor

@cjcenizal I tested the PR targeting master.

gmmorris added a commit to gmmorris/kibana that referenced this pull request Jan 31, 2020
* master: (53 commits)
  Fix setting filters without $store value (elastic#56304)
  kuery_autocomplete -> convert remaining items to TS/Jest (elastic#56316)
  [Reporting] New Platform: moves most of our libs/constants and utils to np shims (elastic#55935)
  [reporting] remove a legacy cross-plugin import (elastic#56354)
  [DOCS] Updates example in Timelion doc (elastic#56444)
  [APM] Service map center button (elastic#56434)
  [skip-ci] Add example for migrating pre-handlers (elastic#56080)
  [ML] Fix Data Visualizer responsive layout  (elastic#56372)
  Add missing docker settings (elastic#56411)
  [Endpoint] Add Endpoint Details route (elastic#55746)
  chore(NA): delete data/optimize with kbn clean (elastic#55890)
  System index templates can't be edited (elastic#55229)
  Sync badge (elastic#55113)
  Only fire appState changes when there is a change (elastic#56183)
  Import appropriate files to setup plugin system at the correct time (elastic#55956)
  [Monitoring] Change all configs to `monitoring.*` (elastic#56215)
  [ML] conditional rison encoding for query params (elastic#56380)
  Move tsvb server to new platform (elastic#55310)
  exclude tutorial resources from code ownership (elastic#55987)
  [Watcher] Follow up on flaky functional test (elastic#56384)
  ...
jloleysens added a commit to jloleysens/kibana that referenced this pull request Jan 31, 2020
…56356

* '7.x' of github.com:elastic/kibana: (23 commits)
  Fix setting filters without $store value (elastic#56304) (elastic#56475)
  [ML] Fix Data Visualizer responsive layout  (elastic#56372) (elastic#56472)
  [ML] conditional rison encoding for query params (elastic#56380) (elastic#56469)
  kuery_autocomplete -> convert remaining items to TS/Jest (elastic#56316) (elastic#56471)
  [APM] Fit service map to container (elastic#56336) (elastic#56463)
  Add animation to service map layout (elastic#56042) (elastic#56460)
  chore(NA): delete data/optimize with kbn clean (elastic#55890) (elastic#56422)
  [APM] Storybook support (elastic#54970) (elastic#56445)
  [DOCS] Updates example in Timelion doc (elastic#56444) (elastic#56454)
  [Logs UI] Fix Check for New Data button on empty indices screen (elastic#56239) (elastic#56320)
  [DOCS] Adds breaking changes for 7.6 (elastic#56437)
  [Monitoring] Change all configs to `monitoring.*` (elastic#56215) (elastic#56421)
  [skip-ci] Add example for migrating pre-handlers (elastic#56080) (elastic#56436)
  [7.x] System index templates can't be edited (elastic#55229) (elastic#56417)
  Add missing docker settings (elastic#56411)
  [Uptime] Use dynamic index pattern in Uptime (elastic#55446) (elastic#56386)
  fix edit rule for detections (elastic#56333) (elastic#56405)
  [Filter Bar] Remove flickering when opening filter bar popover (elastic#56222) (elastic#56385)
  [ILM] Index Lifecycle Policies show wrong unit in Kibana UI (elastic#55228) (elastic#55757)
  Move tsvb server to new platform (elastic#55310) (elastic#56394)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Index Management Index and index templates UI release_note:fix Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants