Skip to content

Commit

Permalink
move types to common package
Browse files Browse the repository at this point in the history
Signed-off-by: zeshanziya <[email protected]>
  • Loading branch information
zeshanziya committed Sep 11, 2024
1 parent 7cf8167 commit 6807423
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 92 deletions.
1 change: 1 addition & 0 deletions plugins/platformsh-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@backstage/backend-common": "^0.24.0",
"@backstage/backend-defaults": "^0.4.2",
"@backstage/backend-plugin-api": "^0.8.0",
"@internal/backstage-plugin-platformsh-common": "^0.1.0",
"express": "^4.17.1",
"express-promise-router": "^4.1.0",
"node-fetch": "^2.6.7",
Expand Down
5 changes: 4 additions & 1 deletion plugins/platformsh-backend/src/PlatformshHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
import Client from 'platformsh-client';
import Activity from 'platformsh-client/types/model/Activity';
import Environment from 'platformsh-client/types/model/Environment';
import { EnvironmentMethods, PlatformshEnvironment } from './model';
import {
EnvironmentMethods,
PlatformshEnvironment,
} from '@internal/backstage-plugin-platformsh-common';

type PlatformshAccessToken = {
access_token: string;
Expand Down
19 changes: 0 additions & 19 deletions plugins/platformsh-backend/src/model.ts

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/platformsh-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import express, { Request } from 'express';
import Router from 'express-promise-router';
import { PlatformshHelper } from '../PlatformshHelper';
import { EnvironmentMethods } from '../model';
import { EnvironmentMethods } from '@internal/backstage-plugin-platformsh-common';

export interface RouterOptions {
logger: LoggerService;
Expand Down
57 changes: 55 additions & 2 deletions plugins/platformsh-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,63 @@
* In this package you might for example declare types that are common
* between the frontend and backend plugin packages.
*/
export type CommonType = {
field: string;
export type PlatformshProject = {
id: string;
status: string;
plan: string;
project_id: string;
project_title: string;
project_region_label: string;
project_ui: string;
size?: string;
environment?: {
count: number;
used: number;
};
url?: string;
};

export type PlatformshEnvironment = {
id: string;
name: string;
machine_name: string;
default_domain: string;
edge_hostname: string;
status: string;
type: string;
created_at: string;
updated_at: string;
parent: string;
};

export type EnvironmentActionResponse = {
result: {
actionResult: {
valid: number;
message: string;
};
};
};

export type ListProjectsResponse = {
result: { projects: PlatformshProject[] };
};

export type ProjectInfoResponse = {
result: { projectData: PlatformshProject };
};

export type ProjectEnvironmentsResponse = {
result: { environments: PlatformshEnvironment[] };
};

export type EnvironmentMethods =
| 'pause'
| 'resume'
| 'activate'
| 'deactivate'
| 'delete';

/**
* Or you might declare some common constants.
*/
Expand Down
1 change: 1 addition & 0 deletions plugins/platformsh/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@backstage/core-plugin-api": "^1.9.3",
"@backstage/plugin-catalog-react": "^1.12.3",
"@backstage/theme": "^0.5.6",
"@internal/backstage-plugin-platformsh-common": "^0.1.0",
"@material-ui/core": "^4.9.13",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.61",
Expand Down
12 changes: 6 additions & 6 deletions plugins/platformsh/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {
EnvironmentActionResponse,
ListProjectsResponse,
PlatformshEnvironment,
PlatformShProject,
PlatformshProject,
ProjectEnvironmentsResponse,
ProjectInfoResponse,
} from './models';
} from '@internal/backstage-plugin-platformsh-common';

export interface PlatformshApi {
listProjects(): Promise<PlatformShProject[]>;
getProjectInfo(id: string): Promise<PlatformShProject>;
listProjects(): Promise<PlatformshProject[]>;
getProjectInfo(id: string): Promise<PlatformshProject>;
getProjectEnvironments(id: string): Promise<PlatformshEnvironment[]>;
doEnvironmentAction(
projectId: string,
Expand Down Expand Up @@ -53,12 +53,12 @@ export class PlatformshClient implements PlatformshApi {
return response.json();
}

async listProjects(): Promise<PlatformShProject[]> {
async listProjects(): Promise<PlatformshProject[]> {
const data = await this.fetchApiData<ListProjectsResponse>('/projects');
return data.result.projects;
}

async getProjectInfo(id: string): Promise<PlatformShProject> {
async getProjectInfo(id: string): Promise<PlatformshProject> {
const data = await this.fetchApiData<ProjectInfoResponse>(`/project/${id}`);
return data.result.projectData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
MenuItem,
} from '@material-ui/core';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import { PlatformshEnvironment } from '../../../models';
import { PlatformshEnvironment } from '@internal/backstage-plugin-platformsh-common';
import useAsyncFn from 'react-use/lib/useAsyncFn';

export const ActionButtons = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TestApiProvider,
} from '@backstage/test-utils';
import { platformshApiRef } from '../../../api';
import { PlatformshEnvironment } from '../../../models';
import { PlatformshEnvironment } from '@internal/backstage-plugin-platformsh-common';

describe('ProjectDetailsCard', () => {
const server = setupServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Progress,
ResponseErrorPanel,
} from '@backstage/core-components';
import { PlatformshEnvironment } from '../../../models';
import { PlatformshEnvironment } from '@internal/backstage-plugin-platformsh-common';
import { alertApiRef, useApi } from '@backstage/core-plugin-api';
import { platformshApiRef } from '../../../api';
import { ActionButtons } from './ActionButtons';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TestApiProvider,
} from '@backstage/test-utils';
import { platformshApiRef } from '../../../api';
import { PlatformShProject } from '../../../models';
import { PlatformshProject } from '@internal/backstage-plugin-platformsh-common';

describe('ProjectDetailsCard', () => {
const server = setupServer();
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('ProjectDetailsCard', () => {
});

it('should render', async () => {
const project: PlatformShProject = {
const project: PlatformshProject = {
id: 'proj-123',
status: 'active',
plan: 'standard',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { Typography, Box, makeStyles, Link } from '@material-ui/core';
import { platformshApiRef } from '../../../api';
import { useApi } from '@backstage/core-plugin-api';
import { PlatformShProject } from '../../../models';
import { PlatformshProject } from '@internal/backstage-plugin-platformsh-common';
import useAsync from 'react-use/lib/useAsync';

const useStyles = makeStyles(theme => ({
Expand Down Expand Up @@ -61,7 +61,7 @@ export const ProjectDetailsCard = ({ projectId }: { projectId: string }) => {
const classes = useStyles();

const { value, loading, error } =
useAsync(async (): Promise<PlatformShProject> => {
useAsync(async (): Promise<PlatformshProject> => {
return platformshApi.getProjectInfo(projectId);
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
TestApiProvider,
} from '@backstage/test-utils';
import { platformshApiRef } from '../../api';
import { PlatformShProject } from '../../models';
import { PlatformshProject } from '@internal/backstage-plugin-platformsh-common';

jest.mock('@backstage/plugin-catalog-react', () => ({
useEntity: () => {
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('EntityTabComponent', () => {
});

it('should render', async () => {
const project: PlatformShProject = {
const project: PlatformshProject = {
id: 'proj-123',
status: 'active',
plan: 'standard',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen } from '@testing-library/react';
import { ProjectsComponent } from './ProjectsComponent';
import { platformshApiRef } from '../../api';
import { TestApiProvider } from '@backstage/test-utils';
import { PlatformShProject } from '../../models';
import { PlatformshProject } from '@internal/backstage-plugin-platformsh-common';

describe('ProjectsComponent', () => {
const platformshApi: jest.Mocked<typeof platformshApiRef.T> = {
Expand All @@ -24,7 +24,7 @@ describe('ProjectsComponent', () => {
});

it('renders the projects table', async () => {
const projects: PlatformShProject[] = [
const projects: PlatformshProject[] = [
{
id: 'a1b2c3d4',
status: 'requested',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import {
ResponseErrorPanel,
} from '@backstage/core-components';
import useAsync from 'react-use/lib/useAsync';
import { PlatformShProject } from '../../models';
import { PlatformshProject } from '@internal/backstage-plugin-platformsh-common';
import { useApi } from '@backstage/core-plugin-api';
import { platformshApiRef } from '../../api';

type DenseTableProps = {
projects: PlatformShProject[];
projects: PlatformshProject[];
};

export const DenseTable = ({ projects }: DenseTableProps) => {
Expand Down Expand Up @@ -47,7 +47,7 @@ export const ProjectsComponent = () => {
const platformshApi = useApi(platformshApiRef);

const { value, loading, error } = useAsync(async (): Promise<
PlatformShProject[]
PlatformshProject[]
> => {
return platformshApi.listProjects();
}, []);
Expand Down
49 changes: 0 additions & 49 deletions plugins/platformsh/src/models.ts

This file was deleted.

0 comments on commit 6807423

Please sign in to comment.