[Advanced settings] Set order for category panels (#168149)

## Summary

This PR sets the order for the category panels so that it matches the
order in the original Advanced settings page.

### How to test
1. Start Es with `yarn es serverless` and Kibana with `yarn
serverless-{es/oblt/security}`
2. Go to Management -> Advanced Settings
3. Verify that the order of the categories is the same as the category
order in the existing self-managed Advanced settings page (as of 8.10).
Keep in mind that some of the categories are missing in serverless
because some settings have been filtered out.

<!---
### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
-->
This commit is contained in:
Elena Stoeva 2023-10-09 14:04:37 +01:00 committed by GitHub
parent b2318c1d05
commit 6e548c0ce9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 118 additions and 21 deletions

View file

@ -7,10 +7,11 @@
*/ */
import { CategorizedFields, FieldDefinition } from '@kbn/management-settings-types'; import { CategorizedFields, FieldDefinition } from '@kbn/management-settings-types';
import { CATEGORY_ORDER } from './const';
export const categorizeFields = (fields: FieldDefinition[]): CategorizedFields => { export const categorizeFields = (fields: FieldDefinition[]): CategorizedFields => {
// Group settings by category // Group settings by category
return fields.reduce((grouped: CategorizedFields, field) => { const groups = fields.reduce((grouped: CategorizedFields, field) => {
const category = field.categories[0]; const category = field.categories[0];
const group = grouped[category] || { count: 0, fields: [] }; const group = grouped[category] || { count: 0, fields: [] };
group.fields = [...group.fields, field]; group.fields = [...group.fields, field];
@ -19,4 +20,13 @@ export const categorizeFields = (fields: FieldDefinition[]): CategorizedFields =
return grouped; return grouped;
}, {}); }, {});
const orderedGroups: CategorizedFields = {};
for (const category of CATEGORY_ORDER) {
if (groups[category]) {
orderedGroups[category] = groups[category];
}
}
return { ...orderedGroups, ...groups };
}; };

View file

@ -0,0 +1,42 @@
/*
* 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.
*/
export const GENERAL_CATEGORY = 'general';
export const PRESENTATION_LAB_CATEGORY = 'Presentation Labs';
export const ACCESSIBILITY_CATEGORY = 'accessibility';
export const AUTOCOMPLETE_CATEGORY = 'autocomplete';
export const BANNER_CATEGORY = 'banner';
export const DISCOVER_CATEGORY = 'discover';
export const MACHINE_LEARNING_CATEGORY = 'machineLearning';
export const NOTIFICATIONS_CATEGORY = 'notifications';
export const OBSERVABILITY_CATEGORY = 'observability';
export const REPORTING_CATEGORY = 'reporting';
export const ROLLUPS_CATEGORY = 'rollups';
export const SEARCH_CATEGORY = 'search';
export const SECURITY_SOLUTION_CATEGORY = 'securitySolution';
export const TIMELION_CATEGORY = 'timelion';
export const VISUALIZATION_CATEGORY = 'visualization';
export const ENTERPRISE_SEARCH_CATEGORY = 'enterpriseSearch';
export const CATEGORY_ORDER = [
GENERAL_CATEGORY,
PRESENTATION_LAB_CATEGORY,
ACCESSIBILITY_CATEGORY,
AUTOCOMPLETE_CATEGORY,
BANNER_CATEGORY,
DISCOVER_CATEGORY,
MACHINE_LEARNING_CATEGORY,
NOTIFICATIONS_CATEGORY,
OBSERVABILITY_CATEGORY,
REPORTING_CATEGORY,
ROLLUPS_CATEGORY,
SEARCH_CATEGORY,
SECURITY_SOLUTION_CATEGORY,
TIMELION_CATEGORY,
VISUALIZATION_CATEGORY,
];

View file

@ -7,45 +7,90 @@
*/ */
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';
import {
ACCESSIBILITY_CATEGORY,
AUTOCOMPLETE_CATEGORY,
BANNER_CATEGORY,
DISCOVER_CATEGORY,
ENTERPRISE_SEARCH_CATEGORY,
GENERAL_CATEGORY,
MACHINE_LEARNING_CATEGORY,
NOTIFICATIONS_CATEGORY,
OBSERVABILITY_CATEGORY,
PRESENTATION_LAB_CATEGORY,
REPORTING_CATEGORY,
ROLLUPS_CATEGORY,
SEARCH_CATEGORY,
SECURITY_SOLUTION_CATEGORY,
TIMELION_CATEGORY,
VISUALIZATION_CATEGORY,
} from './const';
const upperFirst = (str = '') => str.replace(/^./, (strng) => strng.toUpperCase()); const upperFirst = (str = '') => str.replace(/^./, (strng) => strng.toUpperCase());
const names: Record<string, string> = { const names: Record<string, string> = {
general: i18n.translate('management.settings.categoryNames.generalLabel', { [GENERAL_CATEGORY]: i18n.translate('management.settings.categoryNames.generalLabel', {
defaultMessage: 'General', defaultMessage: 'General',
}), }),
machineLearning: i18n.translate('management.settings.categoryNames.machineLearningLabel', { [MACHINE_LEARNING_CATEGORY]: i18n.translate(
'management.settings.categoryNames.machineLearningLabel',
{
defaultMessage: 'Machine Learning', defaultMessage: 'Machine Learning',
}), }
observability: i18n.translate('management.settings.categoryNames.observabilityLabel', { ),
[OBSERVABILITY_CATEGORY]: i18n.translate('management.settings.categoryNames.observabilityLabel', {
defaultMessage: 'Observability', defaultMessage: 'Observability',
}), }),
timelion: i18n.translate('management.settings.categoryNames.timelionLabel', { [TIMELION_CATEGORY]: i18n.translate('management.settings.categoryNames.timelionLabel', {
defaultMessage: 'Timelion', defaultMessage: 'Timelion',
}), }),
notifications: i18n.translate('management.settings.categoryNames.notificationsLabel', { [NOTIFICATIONS_CATEGORY]: i18n.translate('management.settings.categoryNames.notificationsLabel', {
defaultMessage: 'Notifications', defaultMessage: 'Notifications',
}), }),
visualizations: i18n.translate('management.settings.categoryNames.visualizationsLabel', { [VISUALIZATION_CATEGORY]: i18n.translate(
defaultMessage: 'Visualizations', 'management.settings.categoryNames.visualizationsLabel',
}), {
discover: i18n.translate('management.settings.categoryNames.discoverLabel', { defaultMessage: 'Visualization',
}
),
[DISCOVER_CATEGORY]: i18n.translate('management.settings.categoryNames.discoverLabel', {
defaultMessage: 'Discover', defaultMessage: 'Discover',
}), }),
dashboard: i18n.translate('management.settings.categoryNames.dashboardLabel', { [REPORTING_CATEGORY]: i18n.translate('management.settings.categoryNames.reportingLabel', {
defaultMessage: 'Dashboard',
}),
reporting: i18n.translate('management.settings.categoryNames.reportingLabel', {
defaultMessage: 'Reporting', defaultMessage: 'Reporting',
}), }),
search: i18n.translate('management.settings.categoryNames.searchLabel', { [SEARCH_CATEGORY]: i18n.translate('management.settings.categoryNames.searchLabel', {
defaultMessage: 'Search', defaultMessage: 'Search',
}), }),
securitySolution: i18n.translate('management.settings.categoryNames.securitySolutionLabel', { [SECURITY_SOLUTION_CATEGORY]: i18n.translate(
'management.settings.categoryNames.securitySolutionLabel',
{
defaultMessage: 'Security Solution', defaultMessage: 'Security Solution',
}), }
enterpriseSearch: i18n.translate('management.settings.categoryNames.enterpriseSearchLabel', { ),
[ENTERPRISE_SEARCH_CATEGORY]: i18n.translate(
'management.settings.categoryNames.enterpriseSearchLabel',
{
defaultMessage: 'Enterprise Search', defaultMessage: 'Enterprise Search',
}
),
[PRESENTATION_LAB_CATEGORY]: i18n.translate(
'management.settings.categoryNames.presentationLabLabel',
{
defaultMessage: 'Presentation Labs',
}
),
[ACCESSIBILITY_CATEGORY]: i18n.translate('management.settings.categoryNames.accessibilityLabel', {
defaultMessage: 'Accessibility',
}),
[AUTOCOMPLETE_CATEGORY]: i18n.translate('management.settings.categoryNames.autocompleteLabel', {
defaultMessage: 'Autocomplete',
}),
[BANNER_CATEGORY]: i18n.translate('management.settings.categoryNames.bannerLabel', {
defaultMessage: 'Banner',
}),
[ROLLUPS_CATEGORY]: i18n.translate('management.settings.categoryNames.rollupsLabel', {
defaultMessage: 'Rollups',
}), }),
}; };