Skip to content

Commit

Permalink
[Backport 2.3] Fix default last scan date formatter (#4977)
Browse files Browse the repository at this point in the history
* Change default last scan date formatter

* Add changelog

Co-authored-by: Álex <alejandro.ruiz.becerra@wazuh.com>
  • Loading branch information
asteriscos and AlexRuiz7 committed Dec 15, 2022
1 parent 7d66538 commit 14224c2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed WAZUH_PROTOCOL param suggestion [#4849](https://github.com/wazuh/wazuh-kibana-app/pull/4849)
- Raspbian OS, Ubuntu, Amazon Linux and Amazon Linux 2 commands in the wizard deploy agent now change when a different architecture is selected [#4876](https://github.com/wazuh/wazuh-kibana-app/pull/4876) [#4880](https://github.com/wazuh/wazuh-kibana-app/pull/4880)
- Fixed a bug that caused the flyouts to close when clicking inside them [#4638](https://github.com/wazuh/wazuh-kibana-app/pull/4638)
- Fixed vulnerabilities default last scan date formatter [#4975](https://github.com/wazuh/wazuh-kibana-app/pull/4975)

### Removed

Expand Down
22 changes: 8 additions & 14 deletions public/components/agents/vuls/inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
VisualizationBasicWidget,
} from '../../common/charts/visualizations/basic';
import { WzStat } from '../../wz-stat';
import { formatUIDate } from '../../../react-services/time-service';
import { beautifyDate } from './inventory/lib';

interface Aggregation {
title: number;
Expand Down Expand Up @@ -104,12 +104,6 @@ export class Inventory extends Component {
this.colorsVisualizationVulnerabilitiesSummaryData = euiPaletteColorBlind();
}

// when vulnerability module is not configured
// its meant to render nothing when such date is received
beautifyDate(date?: string) {
return date && !['1970-01-01T00:00:00Z', '-'].includes(date) ? formatUIDate(date) : '-';
}

async componentDidMount() {
this._isMount = true;
await this.loadAgent();
Expand Down Expand Up @@ -154,11 +148,11 @@ export class Inventory extends Component {

return Object.keys(severity).length
? SEVERITY_KEYS.map((key) => ({
label: key,
value: severity[key] ? severity[key] : 0,
color: this.titleColors[key],
onClick: () => this.onFiltersChange(this.buildFilterQuery(FIELD, key)),
}))
label: key,
value: severity[key] ? severity[key] : 0,
color: this.titleColors[key],
onClick: () => this.onFiltersChange(this.buildFilterQuery(FIELD, key)),
}))
: [];
}

Expand Down Expand Up @@ -234,8 +228,8 @@ export class Inventory extends Component {
if (isLoading) {
return this.loadingInventory();
}
const last_full_scan = this.beautifyDate(vulnerabilityLastScan.last_full_scan);
const last_partial_scan = this.beautifyDate(vulnerabilityLastScan.last_partial_scan);
const last_full_scan = beautifyDate(vulnerabilityLastScan.last_full_scan);
const last_partial_scan = beautifyDate(vulnerabilityLastScan.last_partial_scan);

const table = this.renderTable();
return (
Expand Down
17 changes: 5 additions & 12 deletions public/components/agents/vuls/inventory/detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { AppNavigate } from '../../../../react-services/app-navigate';
import { TruncateHorizontalComponents } from '../../../common/util';
import { getDataPlugin, getUiSettings } from '../../../../kibana-services';
import { FilterManager } from '../../../../../../../src/plugins/data/public/';
import { formatUIDate } from '../../../../react-services/time-service';
import { beautifyDate } from './lib';
export class Details extends Component {
props!: {
currentItem: {
Expand Down Expand Up @@ -132,28 +132,28 @@ export class Details extends Component {
name: 'Last full scan',
icon: 'clock',
link: false,
transformValue: this.beautifyDate
transformValue: beautifyDate
},
{
field: 'last_partial_scan',
name: 'Last partial scan',
icon: 'clock',
link: false,
transformValue: this.beautifyDate
transformValue: beautifyDate
},
{
field: 'published',
name: 'Published',
icon: 'clock',
link: false,
transformValue: this.beautifyDate
transformValue: beautifyDate
},
{
field: 'updated',
name: 'Updated',
icon: 'clock',
link: false,
transformValue: this.beautifyDate
transformValue: beautifyDate
},
{
field: 'external_references',
Expand All @@ -165,13 +165,6 @@ export class Details extends Component {
];
}

// This method was created because Wazuh API returns 1970-01-01T00:00:00Z dates or undefined ones
// when vulnerability module is not configured
// its meant to render nothing when such date is received
beautifyDate(date?: string) {
return date && !['1970-01-01T00:00:00Z', '-'].includes(date) ? formatUIDate(date) : '-';
}

viewInEvents = (ev) => {
const { cve } = this.props.currentItem;
if (this.props.view === 'extern') {
Expand Down
3 changes: 2 additions & 1 deletion public/components/agents/vuls/inventory/lib/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './api-requests';
export * from './api-requests';
export * from './utils';
10 changes: 10 additions & 0 deletions public/components/agents/vuls/inventory/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { formatUIDate } from '../../../../../react-services/time-service';

// This method was created because Wazuh API returns 1970-01-01T00:00:00Z dates or undefined ones
// when vulnerability module is not configured
// its meant to render nothing when such date is received
export function beautifyDate(date?: string) {
return date &&
(!['-'].includes(date) && !date.startsWith('1970')) ?
formatUIDate(date) : '-';
}

0 comments on commit 14224c2

Please sign in to comment.