Simplify to one annotation

Signed-off-by: Jonathan Mezach <jonathan.mezach@rr-wfm.com>
This commit is contained in:
Jonathan Mezach
2023-04-24 18:45:55 +02:00
parent 2f18f97f98
commit 43aa5cab96
4 changed files with 16 additions and 29 deletions
@@ -15,23 +15,19 @@
*/
import { useEntity } from '@backstage/plugin-catalog-react';
import { useReleases } from '../../hooks/useReleases';
import {
getProjectIdAnnotationFromEntity,
getSpaceIdAnnotationFromEntity,
} from '../../utils/getAnnotationFromEntity';
import { getProjectReferenceAnnotationFromEntity } from '../../utils/getAnnotationFromEntity';
import React from 'react';
import { ReleaseTable } from '../ReleaseTable';
export const EntityPageOctopusDeploy = (props: { defaultLimit?: number }) => {
const { entity } = useEntity();
const projectId = getProjectIdAnnotationFromEntity(entity);
const spaceId = getSpaceIdAnnotationFromEntity(entity);
const projectReference = getProjectReferenceAnnotationFromEntity(entity);
const { environments, releases, loading, error } = useReleases(
projectId,
projectReference.projectId,
props.defaultLimit ?? 3,
spaceId,
projectReference.spaceId,
);
return (
-2
View File
@@ -16,5 +16,3 @@
/** @public */
export const OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION = 'octopus.com/project-id';
/** @public */
export const OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION = 'octopus.com/space-id';
+1 -4
View File
@@ -21,7 +21,4 @@ export {
export * from './api';
export {
OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION,
OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION,
} from './constants';
export { OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION } from './constants';
@@ -13,14 +13,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION,
OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION,
} from '../constants';
import { OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION } from '../constants';
import { Entity } from '@backstage/catalog-model';
export function getProjectIdAnnotationFromEntity(entity: Entity): string {
export type ProjectReference = { projectId: string; spaceId?: string };
export function getProjectReferenceAnnotationFromEntity(
entity: Entity,
): ProjectReference {
const annotation =
entity.metadata.annotations?.[OCTOPUS_DEPLOY_PROJECT_ID_ANNOTATION];
if (!annotation) {
@@ -29,14 +30,9 @@ export function getProjectIdAnnotationFromEntity(entity: Entity): string {
);
}
return annotation;
}
export function getSpaceIdAnnotationFromEntity(
entity: Entity,
): string | undefined {
const annotation =
entity.metadata.annotations?.[OCTOPUS_DEPLOY_SPACE_ID_ANNOTATION];
return annotation || undefined;
const referencedProject = annotation.split('/', 2);
if (referencedProject.length === 2) {
return { projectId: referencedProject[1], spaceId: referencedProject[0] };
}
return { projectId: referencedProject[0] };
}