Skip to content

Commit

Permalink
fetching resources timestamp from k8s object
Browse files Browse the repository at this point in the history
Signed-off-by: Eswaraiahsapram <esapram@redhat.com>

fix(deps): update dependency dompurify to v3.1.3 [security] (backstage#1231)

Signed-off-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: backstage-goalie[bot] <97962292+backstage-goalie[bot]@users.noreply.github.com>

workspace(tech-insights): added support for links to tech-insight checks (backstage#1203)

This includes UI components to render a popup menu with these links, by default on the result icon in the scorecards view.

Signed-off-by: Gustaf Räntilä <g.rantila@gmail.com>

fix(deps): update dependency body-parser to v1.20.3 [security] (backstage#1206)

Signed-off-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: backstage-goalie[bot] <97962292+backstage-goalie[bot]@users.noreply.github.com>

plugin(linguist): marked `createRouter`, `createRouterFromConfig`, `RouterOptions`, and `PluginOptions` as deprecated (backstage#1198)

Signed-off-by: Andre Wanlin <awanlin@spotify.com>

addressed review comments for argo resources timestamp

Signed-off-by: Eswaraiahsapram <esapram@redhat.com>
  • Loading branch information
Eswaraiahsapram committed Sep 17, 2024
1 parent 31c8ddf commit cdd3001
Show file tree
Hide file tree
Showing 43 changed files with 852 additions and 117 deletions.
30 changes: 25 additions & 5 deletions workspaces/code-coverage/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10197,7 +10197,7 @@ __metadata:
languageName: node
linkType: hard

"body-parser@npm:1.20.2, body-parser@npm:^1.20.0":
"body-parser@npm:1.20.2":
version: 1.20.2
resolution: "body-parser@npm:1.20.2"
dependencies:
Expand All @@ -10217,6 +10217,26 @@ __metadata:
languageName: node
linkType: hard

"body-parser@npm:^1.20.0":
version: 1.20.3
resolution: "body-parser@npm:1.20.3"
dependencies:
bytes: 3.1.2
content-type: ~1.0.5
debug: 2.6.9
depd: 2.0.0
destroy: 1.2.0
http-errors: 2.0.0
iconv-lite: 0.4.24
on-finished: 2.4.1
qs: 6.13.0
raw-body: 2.5.2
type-is: ~1.6.18
unpipe: 1.0.0
checksum: 1a35c59a6be8d852b00946330141c4f142c6af0f970faa87f10ad74f1ee7118078056706a05ae3093c54dabca9cd3770fa62a170a85801da1a4324f04381167d
languageName: node
linkType: hard

"bonjour-service@npm:^1.2.1":
version: 1.2.1
resolution: "bonjour-service@npm:1.2.1"
Expand Down Expand Up @@ -21232,12 +21252,12 @@ __metadata:
languageName: node
linkType: hard

"qs@npm:^6.11.0, qs@npm:^6.9.4":
version: 6.12.1
resolution: "qs@npm:6.12.1"
"qs@npm:6.13.0, qs@npm:^6.11.0, qs@npm:^6.9.4":
version: 6.13.0
resolution: "qs@npm:6.13.0"
dependencies:
side-channel: ^1.0.6
checksum: aa761d99e65b6936ba2dd2187f2d9976afbcda38deb3ff1b3fe331d09b0c578ed79ca2abdde1271164b5be619c521ec7db9b34c23f49a074e5921372d16242d5
checksum: e9404dc0fc2849245107108ce9ec2766cde3be1b271de0bf1021d049dc5b98d1a2901e67b431ac5509f865420a7ed80b7acb3980099fe1c118a1c5d2e1432ad8
languageName: node
linkType: hard

Expand Down
6 changes: 3 additions & 3 deletions workspaces/gcalendar/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12078,9 +12078,9 @@ __metadata:
linkType: hard

"dompurify@npm:^3.0.0":
version: 3.1.0
resolution: "dompurify@npm:3.1.0"
checksum: 06fc76607cd076e394b2ea5479ab6f0407b8fedb6877ae95e94207b878365e5e1cd914055dacce152a5f419818afb8d4cd284b780246cf35363f0747c179a0ba
version: 3.1.6
resolution: "dompurify@npm:3.1.6"
checksum: cc4fc4ccd9261fbceb2a1627a985c70af231274a26ddd3f643fd0616a0a44099bd9e4480940ce3655612063be4a1fe9f5e9309967526f8c0a99f931602323866
languageName: node
linkType: hard

Expand Down
5 changes: 5 additions & 0 deletions workspaces/linguist/.changeset/chilly-readers-own.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@backstage-community/plugin-linguist-backend': patch
---

Marked `createRouter`, `createRouterFromConfig`, `RouterOptions`, and `PluginOptions` as deprecated, to be removed soon after the Backstage `1.32.0` release in October
8 changes: 4 additions & 4 deletions workspaces/linguist/plugins/linguist-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import { SchedulerService } from '@backstage/backend-plugin-api';
import { SchedulerServiceTaskScheduleDefinition } from '@backstage/backend-plugin-api';
import { UrlReaderService } from '@backstage/backend-plugin-api';

// @public (undocumented)
// @public @deprecated (undocumented)
export function createRouter(
pluginOptions: PluginOptions,
routerOptions: RouterOptions,
): Promise<express.Router>;

// @public (undocumented)
// @public @deprecated (undocumented)
export function createRouterFromConfig(
routerOptions: RouterOptions,
): Promise<express.Router>;
Expand All @@ -40,7 +40,7 @@ export interface LinguistBackendApi {
const linguistPlugin: BackendFeatureCompat;
export default linguistPlugin;

// @public (undocumented)
// @public @deprecated (undocumented)
export interface PluginOptions {
// (undocumented)
age?: HumanDuration;
Expand All @@ -56,7 +56,7 @@ export interface PluginOptions {
useSourceLocation?: boolean;
}

// @public (undocumented)
// @public @deprecated (undocumented)
export interface RouterOptions {
// (undocumented)
auth?: AuthService;
Expand Down
20 changes: 16 additions & 4 deletions workspaces/linguist/plugins/linguist-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ import {
} from '@backstage/backend-plugin-api';
import { MiddlewareFactory } from '@backstage/backend-defaults/rootHttpRouter';

/** @public */
/**
* @deprecated Please migrate to the new backend system as this will be removed in the future.
* @public
* */
export interface PluginOptions {
schedule?: SchedulerServiceTaskScheduleDefinition;
age?: HumanDuration;
Expand All @@ -48,7 +51,10 @@ export interface PluginOptions {
kind?: string[];
}

/** @public */
/**
* @deprecated Please migrate to the new backend system as this will be removed in the future.
* @public
* */
export interface RouterOptions {
linguistBackendApi?: LinguistBackendApi;
logger: LoggerService;
Expand All @@ -61,7 +67,10 @@ export interface RouterOptions {
httpAuth?: HttpAuthService;
}

/** @public */
/**
* @deprecated Please migrate to the new backend system as this will be removed in the future.
* @public
* */
export async function createRouter(
pluginOptions: PluginOptions,
routerOptions: RouterOptions,
Expand Down Expand Up @@ -149,7 +158,10 @@ export async function createRouter(
return router;
}

/** @public */
/**
* @deprecated Please migrate to the new backend system as this will be removed in the future.
* @public
* */
export async function createRouterFromConfig(routerOptions: RouterOptions) {
const { config } = routerOptions;
const pluginOptions: PluginOptions = {};
Expand Down
6 changes: 3 additions & 3 deletions workspaces/microsoft-calendar/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12012,9 +12012,9 @@ __metadata:
linkType: hard

"dompurify@npm:^3.0.0":
version: 3.1.0
resolution: "dompurify@npm:3.1.0"
checksum: 06fc76607cd076e394b2ea5479ab6f0407b8fedb6877ae95e94207b878365e5e1cd914055dacce152a5f419818afb8d4cd284b780246cf35363f0747c179a0ba
version: 3.1.6
resolution: "dompurify@npm:3.1.6"
checksum: cc4fc4ccd9261fbceb2a1627a985c70af231274a26ddd3f643fd0616a0a44099bd9e4480940ce3655612063be4a1fe9f5e9309967526f8c0a99f931602323866
languageName: node
linkType: hard

Expand Down
2 changes: 2 additions & 0 deletions workspaces/redhat-argocd/plugins/argocd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"@patternfly/react-icons": "^5.1.1",
"@patternfly/react-tokens": "^5.1.2",
"moment": "^2.30.1",
"pluralize": "^8.0.0",
"react-use": "17.5.1"
},
"peerDependencies": {
Expand All @@ -71,6 +72,7 @@
"@testing-library/jest-dom": "6.5.0",
"@testing-library/react": "14.3.1",
"@testing-library/user-event": "14.5.2",
"@types/pluralize": "^0.0.33",
"msw": "1.3.3",
"react": "^16.13.1 || ^17.0.0 || ^18.0.0",
"react-dom": "^18",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { ResourcesColumnHeaders } from './ResourcesColumnHeader';
import { ResourcesFilterBy } from './filters/ResourcesFilterBy';
import { Order, Resource } from '../../../../types/application';
import { FiltersType } from '../../../../types/resources';
import { getResourceCreateTimestamp } from '../../../../utils/utils';
import { useArgoResources } from '../rollouts/RolloutContext';

interface ResourcesTableProps {
resources: Resource[];
Expand Down Expand Up @@ -56,25 +58,33 @@ export const ResourcesTable: FC<ResourcesTableProps> = ({
SearchByName: [],
});

const getSortableRowValues = useCallback(
(res: Resource) => {
const {
name = '',
kind = '',
status = '',
health = { status: '' },
} = res;
const healthStatus = health.status || '';

return [undefined, name, kind, createdAt, status, healthStatus];
},
[createdAt],
);
const getSortableRowValues = useCallback((res: Resource) => {
const {
name = '',
kind = '',
status = '',
health = { status: '' },
createTimestamp,
} = res;
const healthStatus = health.status || '';

return [undefined, name, kind, createTimestamp, status, healthStatus];
}, []);

const allResources = React.useMemo(
() => resources.map((r, idx) => ({ ...r, id: idx })) ?? [],
[resources],
);
const { argoResources } = useArgoResources();

const allResources = React.useMemo(() => {
const getTimestamp = (row: Resource) =>
getResourceCreateTimestamp(argoResources, row) || createdAt;

return (
resources.map((r, idx) => ({
...r,
id: idx,
createTimestamp: getTimestamp(r),
})) ?? []
);
}, [resources, argoResources, createdAt]);

const getAllKinds = React.useMemo(() => {
return resources.reduce((kinds: string[], resource) => {
Expand Down Expand Up @@ -195,7 +205,7 @@ export const ResourcesTable: FC<ResourcesTableProps> = ({
/>
{visibleRows.length > 0 ? (
<TableBody>
<ResourcesTableBody rows={visibleRows} createdAt={createdAt} />
<ResourcesTableBody rows={visibleRows} />
{emptyRows > 0 && (
<TableRow style={{ height: 55 * emptyRows }}>
<TableCell colSpan={ResourcesColumnHeaders.length} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,16 @@ import { Resource } from '../../../../types/application';

interface ResourcesTableBodyProps {
rows: Resource[];
createdAt: string;
}

export const ResourcesTableBody: React.FC<ResourcesTableBodyProps> = ({
rows,
createdAt,
}) => {
return (
<>
{rows.map((row: Resource, index: number) => {
return (
<ResourcesTableRow
row={row}
createdAt={createdAt}
key={index}
uid={index.toString()}
/>
<ResourcesTableRow row={row} key={index} uid={index.toString()} />
);
})}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import {
Box,
Collapse,
Expand All @@ -19,25 +19,16 @@ import ResourceMetadata from './resource/ResourceMetadata';
type ResourcesTableRowProps = {
uid: string;
row: Resource;
createdAt: string;
};

const useStyles = makeStyles(theme => ({
resourceRow: {
'& > *': { borderBottom: 'unset' },
'&:first-child': {
// borderTop: `1px solid ${theme.palette.grey.A100}`,
},
'&:nth-of-type(odd)': {
backgroundColor: 'inherit',
},
// boxShadow: '0px 0.5px 2px rgba(0, 0, 0, 0.3)',
// borderBottom: `1px solid ${theme.palette.grey.A100}`,
},
expandedRow: {
'&:first-child': {
// borderBottom: `1px solid ${theme.palette.grey.A100}`,
},
padding: 10,
},
tableCell: {
Expand All @@ -49,11 +40,15 @@ const useStyles = makeStyles(theme => ({
export const ResourcesTableRow: React.FC<ResourcesTableRowProps> = ({
uid,
row,
createdAt,
}) => {
const classes = useStyles();
const [open, setOpen] = React.useState(false);

const formattedTimestamp = useMemo(
() => moment.utc(row?.createTimestamp).local().format('MM/DD/YYYY hh:mm a'),
[row?.createTimestamp],
);

return (
<>
<TableRow className={classes.resourceRow}>
Expand All @@ -74,7 +69,7 @@ export const ResourcesTableRow: React.FC<ResourcesTableRowProps> = ({
{row.kind}
</TableCell>
<TableCell className={classes.tableCell} align="left">
{moment.utc(createdAt).local().format('MM/DD/YYYY hh:mm a')}
{formattedTimestamp}
</TableCell>
<TableCell className={classes.tableCell} align="left">
{row.status && <ResourceSyncStatus syncStatus={row.status} />}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { render, screen, fireEvent, waitFor } from '@testing-library/react';

import { ResourcesTable } from '../ResourcesTable';
import { Resource } from '../../../../../types/application';
import { useArgoResources } from '../../rollouts/RolloutContext';

jest.mock('../../../sidebar/rollouts/RolloutContext', () => ({
...jest.requireActual('../../../sidebar/rollouts/RolloutContext'),
useArgoResources: jest.fn(),
}));

jest.mock('../ResourcesSearchBar', () => ({
ResourcesSearchBar: jest.fn(({ value, onChange, onSearchClear }) => (
Expand Down Expand Up @@ -32,6 +38,11 @@ jest.mock('../filters/ResourcesFilterBy', () => ({
}));

describe('ResourcesTable Component', () => {
beforeEach(() => {
jest.clearAllMocks();
(useArgoResources as jest.Mock).mockReturnValue({ argoResources: [] });
});

const resources = [
{
kind: 'Rollout',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ describe('ResourcesTableBody Component', () => {
name: 'quarkus-app',
status: 'Synced',
health: { status: 'Healthy' },
createTimestamp: '2024-08-25T12:00:00Z',
},
{
version: 'v1',
Expand All @@ -26,9 +27,9 @@ describe('ResourcesTableBody Component', () => {
name: 'quarkus-app',
status: 'Synced',
health: { status: 'Healthy' },
createTimestamp: '2024-08-25T12:00:00Z',
},
],
createdAt: '2024-08-25T12:00:00Z',
};

it('should render the correct number of ResourcesTableRow components', () => {
Expand All @@ -46,7 +47,6 @@ describe('ResourcesTableBody Component', () => {
index + 1,
expect.objectContaining({
row,
createdAt: defaultProps.createdAt,
uid: index.toString(),
}),
expect.anything(),
Expand Down
Loading

0 comments on commit cdd3001

Please sign in to comment.