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
+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';