Skip to content

Commit

Permalink
chore: Make linter and tests happy
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Coufal <[email protected]>
  • Loading branch information
tumido committed Feb 7, 2023
1 parent 694a918 commit 7030f6a
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 56 deletions.
1 change: 1 addition & 0 deletions plugins/quay/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
2 changes: 2 additions & 0 deletions plugins/quay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
"prepare": ""
},
"dependencies": {
"@backstage/catalog-model": "1.1.5",
"@backstage/core-components": "^0.12.1",
"@backstage/core-plugin-api": "^1.2.0",
"@backstage/plugin-catalog-react": "1.2.4",
"@backstage/theme": "^0.2.16",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
Expand Down
7 changes: 1 addition & 6 deletions plugins/quay/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import {
DiscoveryApi,
ConfigApi,
fetchApiRef,
FetchApi,
useApi,
createApiRef,
} from '@backstage/core-plugin-api';
import {
Expand Down Expand Up @@ -49,12 +46,10 @@ export class QuayApiClient implements QuayApiV1 {
private readonly discoveryApi: DiscoveryApi;

private readonly configApi: ConfigApi;
private readonly fetch: FetchApi['fetch'];

constructor(options: Options) {
this.discoveryApi = options.discoveryApi;
this.configApi = options.configApi;
this.fetch = useApi(fetchApiRef).fetch;
}

private async getBaseUrl() {
Expand All @@ -64,7 +59,7 @@ export class QuayApiClient implements QuayApiV1 {
}

private async fetcher(url: string) {
const response = await this.fetch(url, {
const response = await fetch(url, {
headers: { 'Content-Type': 'application/json' },
});
if (!response.ok) {
Expand Down
22 changes: 11 additions & 11 deletions plugins/quay/src/components/QuayDashboardPage/QuayDashboardPage.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { useEntity } from '@backstage/plugin-catalog-react'
import React from 'react'
import { QuayRepository } from '../QuayRepository'
import { useQuayAppData } from '../useQuayAppData'
import { useEntity } from '@backstage/plugin-catalog-react';
import React from 'react';
import { QuayRepository } from '../QuayRepository';
import { useQuayAppData } from '../useQuayAppData';

export const QuayDashboardPage = () => {
const { entity } = useEntity()
const { repositorySlug } = useQuayAppData({ entity })
const info = repositorySlug.split('/')
const { entity } = useEntity();
const { repositorySlug } = useQuayAppData({ entity });
const info = repositorySlug.split('/');

const organization = info.shift() as 'string'
const repository = info.join('/')
const organization = info.shift() as 'string';
const repository = info.join('/');

return (
<QuayRepository
organization={organization}
repository={repository}
widget={false}
/>
)
}
);
};
2 changes: 1 addition & 1 deletion plugins/quay/src/components/QuayDashboardPage/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { QuayDashboardPage } from './QuayDashboardPage'
export { QuayDashboardPage } from './QuayDashboardPage';
Empty file.
5 changes: 2 additions & 3 deletions plugins/quay/src/components/QuayRepository/QuayRepository.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ export function QuayRepository(props: RepositoryProps) {
const quayClient = useApi(quayApiRef);
const classes = useStyles();
const [tags, setTags] = useState<Tag[]>([]);
const title =
'Quay repository: ' + props.organization + '/' + props.repository;
const title = `Quay repository: ${props.organization}/${props.repository}`;

const { loading } = useAsync(async () => {
const tagsResponse = await quayClient.getTags(
props.organization,
props.repository,
);
if (tagsResponse.page == 1) {
if (tagsResponse.page === 1) {
setTags(tagsResponse.tags);
} else {
setTags(currentTags => [...currentTags, ...tagsResponse.tags]);
Expand Down
2 changes: 1 addition & 1 deletion plugins/quay/src/components/QuayRepository/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { QuayRepository } from './QuayRepository'
export { QuayRepository } from './QuayRepository';
47 changes: 24 additions & 23 deletions plugins/quay/src/components/QuayWidget/QuayWidget.tsx
Original file line number Diff line number Diff line change
@@ -1,44 +1,45 @@
import { Entity } from '@backstage/catalog-model'
import { MissingAnnotationEmptyState } from '@backstage/core-components'
import { useEntity } from '@backstage/plugin-catalog-react'
import { Card, CardHeader } from '@material-ui/core'
import React from 'react'
import { isQuayAvailable } from '../../plugin'
import { QuayRepository } from '../QuayRepository'
import {
QUAY_ANNOTATION_REPOSITORY,
useQuayAppData,
} from '../useQuayAppData'
import { Entity } from '@backstage/catalog-model';
import { MissingAnnotationEmptyState } from '@backstage/core-components';
import { useEntity } from '@backstage/plugin-catalog-react';
import { Card, CardHeader } from '@material-ui/core';
import React from 'react';
import { isQuayAvailable } from '../../plugin';
import { QuayRepository } from '../QuayRepository';
import { QUAY_ANNOTATION_REPOSITORY, useQuayAppData } from '../useQuayAppData';

const Widget = ({ entity }: { entity: Entity }) => {
const { repositorySlug } = useQuayAppData({ entity })
const info = repositorySlug.split('/')
const { repositorySlug } = useQuayAppData({ entity });
const info = repositorySlug.split('/');

const organization = info.shift() as 'string'
const repository = info.join('/')
const organization = info.shift() as 'string';
const repository = info.join('/');

return (
<Card>
<CardHeader title="Docker Image" />
<QuayRepository organization={organization} repository={repository} widget />
<QuayRepository
organization={organization}
repository={repository}
widget
/>
</Card>
)
}
);
};

export const QuayWidget = () => {
const { entity } = useEntity()
const { entity } = useEntity();

return !isQuayAvailable(entity) ? (
<MissingAnnotationEmptyState annotation={QUAY_ANNOTATION_REPOSITORY} />
) : (
<Widget entity={entity} />
)
}
);
};

export const QuayWidgetEntity = ({ entity }: { entity: Entity }) => {
return !isQuayAvailable(entity) ? (
<MissingAnnotationEmptyState annotation={QUAY_ANNOTATION_REPOSITORY} />
) : (
<Widget entity={entity} />
)
}
);
};
2 changes: 1 addition & 1 deletion plugins/quay/src/components/QuayWidget/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { QuayWidget } from './QuayWidget'
export { QuayWidget } from './QuayWidget';
12 changes: 6 additions & 6 deletions plugins/quay/src/components/useQuayAppData.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Entity } from '@backstage/catalog-model'
import { Entity } from '@backstage/catalog-model';

export const QUAY_ANNOTATION_REPOSITORY = 'quay.io/repository-slug'
export const QUAY_ANNOTATION_REPOSITORY = 'quay.io/repository-slug';

export const useQuayAppData = ({ entity }: { entity: Entity }) => {
const repositorySlug =
entity?.metadata.annotations?.[QUAY_ANNOTATION_REPOSITORY] ?? ''
entity?.metadata.annotations?.[QUAY_ANNOTATION_REPOSITORY] ?? '';

if (!repositorySlug) {
throw new Error("'Quay' annotations are missing")
throw new Error("'Quay' annotations are missing");
}
return { repositorySlug }
}
return { repositorySlug };
};
2 changes: 1 addition & 1 deletion plugins/quay/src/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { quayPlugin } from './plugin';

describe('quay-frontend', () => {
describe('quay', () => {
it('should export plugin', () => {
expect(quayPlugin).toBeDefined();
});
Expand Down
13 changes: 10 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2443,7 +2443,7 @@
"@backstage/errors" "^1.1.4"
cross-fetch "^3.1.5"

"@backstage/catalog-model@^1.1.3", "@backstage/catalog-model@^1.1.5":
"@backstage/catalog-model@1.1.5", "@backstage/catalog-model@^1.1.3", "@backstage/catalog-model@^1.1.5":
version "1.1.5"
resolved "https://registry.yarnpkg.com/@backstage/catalog-model/-/catalog-model-1.1.5.tgz#83203771f2fc04353d0d84e20d354f0cef15403f"
integrity sha512-rE1KFhpLlli0A7marJpbd4MCGWG+5vIRj49XZBbEdhevl7HfCCJMAA6IKyj8U7LJjwRVygppSkc8V2yAyEU/2A==
Expand Down Expand Up @@ -3090,7 +3090,7 @@
"@backstage/plugin-catalog-common" "^1.0.10"
"@backstage/types" "^1.0.2"

"@backstage/plugin-catalog-react@^1.2.1", "@backstage/plugin-catalog-react@^1.2.4":
"@backstage/plugin-catalog-react@1.2.4", "@backstage/plugin-catalog-react@^1.2.1", "@backstage/plugin-catalog-react@^1.2.4":
version "1.2.4"
resolved "https://registry.yarnpkg.com/@backstage/plugin-catalog-react/-/plugin-catalog-react-1.2.4.tgz#477582c3c015985ac92531e40e0b6ce5e6121772"
integrity sha512-u26FK7JvQXmhlpTYTxoHf969By/kmHRWv7W2wV+osJYGuRX5ckX1Bpf7dY+WodOMCScksNHgz1gyHbkLd1iXeQ==
Expand Down Expand Up @@ -7304,13 +7304,20 @@
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.4.tgz#cd667bcfdd025213aafb7ca5915a932590acdcdc"
integrity sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==

"@types/[email protected]", "@types/react-dom@<18.0.0", "@types/react-dom@^17", "@types/react-dom@^18.0.0":
"@types/[email protected]", "@types/react-dom@<18.0.0":
version "17.0.18"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.18.tgz#8f7af38f5d9b42f79162eea7492e5a1caff70dc2"
integrity sha512-rLVtIfbwyur2iFKykP2w0pl/1unw26b5td16d5xMgp7/yjTHomkyxPYChFoCr/FtEX1lN9wY6lFj1qvKdS5kDw==
dependencies:
"@types/react" "^17"

"@types/react-dom@^18.0.0":
version "18.0.10"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.10.tgz#3b66dec56aa0f16a6cc26da9e9ca96c35c0b4352"
integrity sha512-E42GW/JA4Qv15wQdqJq8DL4JhNpB3prJgjgapN3qJT9K2zO5IIAQh4VXvCEDupoqAwnz0cY4RlXeC/ajX5SFHg==
dependencies:
"@types/react" "*"

"@types/react-redux@^7.1.20":
version "7.1.25"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.25.tgz#de841631205b24f9dfb4967dd4a7901e048f9a88"
Expand Down

0 comments on commit 7030f6a

Please sign in to comment.