added support for sqlite

Signed-off-by: Lykke Axlin <lykkeaxlin@hotmail.com>

Co-authored-by: klaraab <klarabroman@live.se>
This commit is contained in:
Lykke Axlin
2021-10-15 10:41:48 +02:00
parent e5679eb27c
commit 49511f5081
14 changed files with 375 additions and 205 deletions
+5 -1
View File
@@ -101,6 +101,10 @@ The metadata related to the Bazaar is stored in a database. Right now there are
## Future work and ideas
- Workflow
- Make it possible to add a Bazaar project without linking it to a Backstage entity, this would make it easier to just add an idea to the Bazaar.
- Bazaar landing page
- Add a tab 'My page', where your personal data is displayed. For example: your projects and its latest activities, projects or tags you are following etc.
@@ -117,7 +121,7 @@ The metadata related to the Bazaar is stored in a database. Right now there are
- Dialogues
- Extend the dialogue for adding a project with more fields, e.g. chat link and the possibility to add images
- Extend the dialogue for adding a project with more fields, e.g. the possibility to add images
- Testing
- Add tests to all the components
+2 -2
View File
@@ -22,7 +22,7 @@
},
"dependencies": {
"@backstage/catalog-model": "^0.9.0",
"@backstage/cli": "^0.7.2",
"@backstage/cli": "^0.7.15",
"@backstage/core-components": "^0.6.1",
"@backstage/core-plugin-api": "^0.1.10",
"@backstage/plugin-catalog": "^0.7.0",
@@ -30,7 +30,7 @@
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.57",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/jest-dom": "^5.10.1",
"luxon": "^2.0.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
+4 -28
View File
@@ -20,7 +20,7 @@ import {
DiscoveryApi,
IdentityApi,
} from '@backstage/core-plugin-api';
import { BazaarProject, Status } from './types';
import { BazaarProject } from './types';
export const bazaarApiRef = createApiRef<BazaarApi>({
id: 'bazaar',
@@ -28,13 +28,7 @@ export const bazaarApiRef = createApiRef<BazaarApi>({
});
export interface BazaarApi {
updateMetadata(
entity: Entity,
name: string,
community: string,
announcement: string,
status: Status,
): Promise<any>;
updateMetadata(bazaarProject: BazaarProject): Promise<any>;
getMetadata(entity: Entity): Promise<any>;
@@ -61,13 +55,7 @@ export class BazaarClient implements BazaarApi {
this.discoveryApi = options.discoveryApi;
}
async updateMetadata(
entity: Entity,
name: string,
community: string,
announcement: string,
status: Status,
): Promise<any> {
async updateMetadata(bazaarProject: BazaarProject): Promise<any> {
const baseUrl = await this.discoveryApi.getBaseUrl('bazaar');
return await fetch(`${baseUrl}/metadata`, {
@@ -76,13 +64,7 @@ export class BazaarClient implements BazaarApi {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
entity_ref: stringifyEntityRef(entity),
name: name,
announcement: announcement,
community: community,
status: status,
}),
body: JSON.stringify(bazaarProject),
}).then(resp => resp.json());
}
@@ -155,11 +137,5 @@ export class BazaarClient implements BazaarApi {
await fetch(`${baseUrl}/metadata/${encodeURIComponent(entityRef)}`, {
method: 'DELETE',
});
if (bazaarProject.membersCount > 0) {
await fetch(`${baseUrl}/members/${encodeURIComponent(entityRef)}`, {
method: 'DELETE',
});
}
}
}
@@ -15,7 +15,7 @@
*/
import React, { useState, useEffect } from 'react';
import { Entity } from '@backstage/catalog-model';
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
import { SubmitHandler } from 'react-hook-form';
import { useApi } from '@backstage/core-plugin-api';
import { ProjectDialog } from '../ProjectDialog';
@@ -70,13 +70,14 @@ export const AddProjectDialog = ({
const formValues = getValues();
if (selectedEntity) {
await bazaarApi.updateMetadata(
selectedEntity,
selectedEntity.metadata.name,
formValues.community,
formValues.announcement,
formValues.status,
);
await bazaarApi.updateMetadata({
name: selectedEntity.metadata.name,
entityRef: stringifyEntityRef(selectedEntity),
announcement: formValues.announcement,
status: formValues.status,
community: formValues.community,
membersCount: 0,
} as BazaarProject);
fetchBazaarProjects();
fetchCatalogEntities();
@@ -15,7 +15,7 @@
*/
import React, { useState, useEffect } from 'react';
import { Entity } from '@backstage/catalog-model';
import { Entity, stringifyEntityRef } from '@backstage/catalog-model';
import { useApi } from '@backstage/core-plugin-api';
import { ProjectDialog } from '../ProjectDialog';
import { BazaarProject, FormValues } from '../../types';
@@ -56,13 +56,14 @@ export const EditProjectDialog = ({
const handleSave: any = async (getValues: any, _: any) => {
const formValues = getValues();
const updateResponse = await bazaarApi.updateMetadata(
entity!,
entity.metadata.name,
formValues.community,
formValues.announcement,
formValues.status,
);
const updateResponse = await bazaarApi.updateMetadata({
name: entity.metadata.name,
entityRef: stringifyEntityRef(entity),
announcement: formValues.announcement,
status: formValues.status,
community: formValues.community,
membersCount: bazaarProject.membersCount,
});
if (updateResponse.status === 'ok') fetchBazaarProject();
handleClose();
@@ -73,7 +73,9 @@ export const ProjectCard = ({ bazaarProject }: Props) => {
>
<ItemCardHeader
title={name}
subtitle={`updated ${DateTime.fromISO(updatedAt!).toRelative({
subtitle={`updated ${DateTime.fromISO(
new Date(updatedAt!).toISOString(),
).toRelative({
base: DateTime.now(),
})}`}
/>
@@ -39,12 +39,15 @@ const useStyles = makeStyles({
},
});
const filterCatalogEntities = (bazaarProjects: any, catalogEntities: any) => {
const bazaarProjectRefs = bazaarProjects?.value?.map(
const filterCatalogEntities = (
bazaarProjects: BazaarProject[],
catalogEntities: Entity[],
) => {
const bazaarProjectRefs = bazaarProjects.map(
(project: BazaarProject) => project.entityRef,
);
const filtered = catalogEntities?.value?.filter((entity: Entity) => {
const filtered = catalogEntities.filter((entity: Entity) => {
return !bazaarProjectRefs?.includes(stringifyEntityRef(entity));
});
@@ -110,8 +113,8 @@ export const SortView = () => {
useEffect(() => {
const filteredCatalogEntities = filterCatalogEntities(
bazaarProjects,
catalogEntities,
bazaarProjects.value || [],
catalogEntities.value || [],
);
if (filteredCatalogEntities) {
+1
View File
@@ -16,3 +16,4 @@
export { bazaarPlugin, BazaarPage } from './plugin';
export { EntityBazaarInfoCard } from './components/EntityBazaarInfoCard';
export type { BazaarProject } from './types';