Skip to content

Commit

Permalink
fix types of badges (#2597)
Browse files Browse the repository at this point in the history
* fix types of badges

* bump

* fix types of badges

* fix tests

* fix tests

* add warning to cases

* fix docs

* fix tests

* I hope this is last fix
  • Loading branch information
mrCherry97 authored Oct 2, 2023
1 parent 74eda27 commit c06b893
Show file tree
Hide file tree
Showing 28 changed files with 71 additions and 108 deletions.
19 changes: 9 additions & 10 deletions docs/extensibility/display-section.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,18 @@ Badge widgets render texts as a status badge, using a set of predefined rules to

- **placeholder** - an optional property to change the default empty text placeholder `-` with a custom string.
If the **translations** section has a translation entry with the ID that is the same as the **placeholder** string, the translation is used.
- **highlights** - an optional map of highlight rules. Key refers to the type of highlight, while the rule can just be a plain array of values or a string containing a [JSONata](jsonata.md) rule. Allowed keys are `informative` `positive`, `negative` and `critical`.
- **highlights** - an optional map of highlight rules. Key refers to the type of highlight, while the rule can just be a plain array of values or a string containing a [JSONata](jsonata.md) rule. Allowed keys are `information`, `success`, `warning` and `error`.
- **description** - a [JSONata](jsonata.md) expression used to fetch additional information that will be displayed in a tooltip when hovering over the badge.
- **copyable** - an optional flag to display a **Copy to clipboard** button next to the widget. By default set to `false`.

#### Default highlight rules

When no highlights are provided, the following values are automatically handled:

- rendered as informative: `initial`, `pending`, `available`, `released`.
- rendered as positive: `ready`, `bound`, `running`, `success`, `succeeded`, `ok`.
- rendered as negative: `unknown`, `warning`.
- rendered as critical: `error`, `failure`, `invalid`.
- rendered as information: `initial`, `pending`, `available`, `released`.
- rendered as success: `ready`, `bound`, `running`, `success`, `succeeded`, `ok`.
- rendered as warning: `unknown`, `warning`.
- rendered as error: `error`, `failure`, `invalid`.

#### Example

Expand All @@ -231,10 +231,10 @@ When no highlights are provided, the following values are automatically handled:
widget: Badge
placeholder: '-'
highlights:
positive:
success:
- Running
- ok
negative: $item < 0
error: $item < 0
description: status.message
```

Expand Down Expand Up @@ -835,11 +835,10 @@ injections: |-
- name: status
widget: Badge
highlights:
positive:
success:
- 'OK'
negative:
error:
- 'ERROR'
critical:
- 'SKIPPED'
source: 'status.APIRuleStatus.code ? status.APIRuleStatus.code : "UNKNOWN"'
description: status.APIRuleStatus.desc
Expand Down
5 changes: 2 additions & 3 deletions examples/injections/apirules.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ injections: |-
- name: status
widget: Badge
highlights:
positive:
success:
- 'OK'
negative:
error:
- 'ERROR'
critical:
- 'SKIPPED'
source: 'status.APIRuleStatus.code ? status.APIRuleStatus.code : "UNKNOWN"'
description: status.APIRuleStatus.desc
9 changes: 4 additions & 5 deletions examples/injections/functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@ injections: |-
- name: header.status
widget: Badge
highlights:
positive:
success:
- RUNNING
negative:
error:
- FAILED
- ERROR
informative:
- INITIALIZING
critical:
- DEPLOYING
- BUILDING
- PENDING
information:
- INITIALIZING
source: >-
($.status = undefined or $.status.conditions = undefined or
$count($.status.conditions) = 0) ? 'INITIALIZING' :
Expand Down
4 changes: 2 additions & 2 deletions examples/services/configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ data:
sort: true
widget: Badge
highlights:
positive:
success:
- 'true'
negative:
error:
- 'false'
- widget: ResourceList
source: $apirules()
Expand Down
14 changes: 3 additions & 11 deletions public/schemas/schema-details.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,23 @@ $widgets:
type: object
widget: FormGroup
properties:
informative:
information:
type: [string, array]
widget: MultiType
widgets:
string: Jsonata
array: SimpleList
items:
type: string
positive:
success:
type: [string, array]
widget: MultiType
widgets:
string: Jsonata
array: SimpleList
items:
type: string
negative:
type: [string, array]
widget: MultiType
widgets:
string: Jsonata
array: SimpleList
items:
type: string
critical:
error:
type: [string, array]
widget: MultiType
widgets:
Expand Down
16 changes: 3 additions & 13 deletions public/schemas/schema-injections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ items:
type: object
widget: FormGroup
properties:
informative:
information:
type:
- string
- array
Expand All @@ -153,7 +153,7 @@ items:
array: SimpleList
items:
type: string
positive:
success:
type:
- string
- array
Expand All @@ -163,17 +163,7 @@ items:
array: SimpleList
items:
type: string
negative:
type:
- string
- array
widget: MultiType
widgets:
string: Jsonata
array: SimpleList
items:
type: string
critical:
error:
type:
- string
- array
Expand Down
14 changes: 3 additions & 11 deletions public/schemas/schema-list.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,23 @@ $widgets:
type: object
widget: FormGroup
properties:
informative:
information:
type: [string, array]
widget: MultiType
widgets:
string: Jsonata
array: SimpleList
items:
type: string
positive:
success:
type: [string, array]
widget: MultiType
widgets:
string: Jsonata
array: SimpleList
items:
type: string
negative:
type: [string, array]
widget: MultiType
widgets:
string: Jsonata
array: SimpleList
items:
type: string
critical:
error:
type: [string, array]
widget: MultiType
widgets:
Expand Down
2 changes: 1 addition & 1 deletion resources/web/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
spec:
containers:
- name: busola
image: europe-docker.pkg.dev/kyma-project/dev/busola-web:PR-2554
image: europe-docker.pkg.dev/kyma-project/dev/busola-web:PR-2597
imagePullPolicy: Always
resources:
requests:
Expand Down
2 changes: 1 addition & 1 deletion src/components/Clusters/views/ClusterStorageType.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export function ClusterStorageType({ clusterConfig }) {
return (
<StatusBadge
resourceKind="clusters"
type={knownStorage.includes(storage) ? 'info' : 'warning'}
type={knownStorage.includes(storage) ? 'Information' : 'Warning'}
>
{storage || 'unknown'}
</StatusBadge>
Expand Down
3 changes: 1 addition & 2 deletions src/components/Extensibility/components/Badge.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { isNil } from 'lodash';
import { useJsonata } from '../hooks/useJsonata';
import { useTranslation } from 'react-i18next';

import { StatusBadge } from 'shared/components/StatusBadge/StatusBadge';
import {
Expand All @@ -10,12 +11,10 @@ import {
import { Tooltip } from 'shared/components/Tooltip/Tooltip';

import './Badge.scss';
import { useTranslation } from 'react-i18next';

export function Badge({
value,
structure,
schema,
originalResource,
scope,
arrayItems,
Expand Down
12 changes: 6 additions & 6 deletions src/components/Extensibility/components/tests/Badge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,34 @@ describe('Badge', () => {
expect(status).toHaveLength(1);
});

it('Renders a badge with positive type for custom highlights', () => {
it('Renders a badge with success type for custom highlights', () => {
const value = 'yes';
const structure = {
highlights: {
positive: ['yes', 'ok'],
Success: ['yes', 'ok'],
},
};

const wrapper = shallow(<Badge value={value} structure={structure} />);
const status = wrapper.find(StatusBadge);
const badgeProps = status.props();
expect(badgeProps.type).toEqual('positive');
expect(badgeProps.type).toEqual('Success');
expect(badgeProps.autoResolveType).toEqual(false);
expect(status).toHaveLength(1);
});

it('Renders a badge with positive type for custom highlights', () => {
it('Renders a badge with error type for custom highlights', () => {
const value = -2;
const structure = {
highlights: {
negative: 'data < 0',
Error: 'data < 0',
},
};

const wrapper = shallow(<Badge value={value} structure={structure} />);
const status = wrapper.find(StatusBadge);
const badgeProps = status.props();
expect(badgeProps.type).toEqual('negative');
expect(badgeProps.type).toEqual('Error');
expect(badgeProps.autoResolveType).toEqual(false);
expect(status).toHaveLength(1);
});
Expand Down
1 change: 0 additions & 1 deletion src/components/HelmReleases/HelmReleaseStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export function HelmReleaseStatus({ status }) {
case 'deployed':
return 'Success';
case 'uninstalling':
return 'Error';
case 'failed':
return 'Error';
case 'unknown':
Expand Down
2 changes: 1 addition & 1 deletion src/components/HelmReleases/ReleaseDataPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function ReleaseDataPanel({ release, simpleHeader }) {
{name}
</Link>
<div className="fd-margin-begin--sm">
<StatusBadge noTooltip type="info">
<StatusBadge noTooltip type="Information">
{t('helm-releases.headers.release-version', { version })}
</StatusBadge>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/resources/CronJobs/CronJobConcurrencyPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { StatusBadge } from 'shared/components/StatusBadge/StatusBadge';
export function CronJobConcurrencyPolicy({ concurrencyPolicy }) {
return (
<StatusBadge
type="info"
type="Information"
tooltipProps={{ position: 'bottom' }}
resourceKind="cron-jobs"
>
Expand Down
2 changes: 1 addition & 1 deletion src/resources/Jobs/JobCompletions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function JobCompletions({ job }) {

const succeeded = job.status.succeeded || 0;
const completions = job.spec.completions || 0;
const statusType = succeeded === completions ? 'positive' : 'informative';
const statusType = succeeded === completions ? 'Success' : 'Information';

return (
<TooltipBadge
Expand Down
6 changes: 3 additions & 3 deletions src/resources/Jobs/JobConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ export function JobConditions(job) {
];
const conditionTypeStatus = type => {
if (type === 'Complete') {
return 'success';
return 'Success';
} else if (type === 'Failed') {
return 'error';
return 'Error';
} else {
return 'info';
return 'Information';
}
};
const rowRenderer = condition => {
Expand Down
6 changes: 3 additions & 3 deletions src/resources/Namespaces/NamespaceStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export function NamespaceStatus({ namespaceStatus }) {
const badgeType = status => {
switch (status) {
case 'Active':
return 'success';
return 'Success';
case 'Terminating':
return 'info';
return 'Information';
default:
return 'error';
return 'Error';
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/resources/PersistentVolumes/PersistentVolumeStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ export function PersistentVolumeStatus({ status }) {
switch (status) {
case 'Bound':
case 'Available':
return 'success';
return 'Success';
case 'Released':
case 'Pending':
return 'info';
return 'Information';
default:
return 'error';
return 'Error';
}
};

Expand Down
8 changes: 4 additions & 4 deletions src/resources/Pods/ContainerStatus.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/resources/Pods/PodRestarts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c06b893

Please sign in to comment.