@digital-ai/plugin-dai-deploy
Version:
Frontend functionalities for the dai-deploy backstage plugin
110 lines (107 loc) • 4.3 kB
JavaScript
import { DAI_DEPLOY_CI_ID_ANNOTATION } from '@digital-ai/plugin-dai-deploy-common';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { daiDeployApiRef } from '../api/DaiDeployApi.esm.js';
import '@backstage/errors';
import 'moment';
import { useApi } from '@backstage/core-plugin-api';
import { useAsyncRetry } from 'react-use';
import { useState } from 'react';
var activeDeploymentOrderBy = /* @__PURE__ */ ((activeDeploymentOrderBy2) => {
activeDeploymentOrderBy2[activeDeploymentOrderBy2["package"] = 0] = "package";
activeDeploymentOrderBy2[activeDeploymentOrderBy2["environment"] = 1] = "environment";
activeDeploymentOrderBy2[activeDeploymentOrderBy2["type"] = 2] = "type";
activeDeploymentOrderBy2[activeDeploymentOrderBy2["user"] = 3] = "user";
activeDeploymentOrderBy2[activeDeploymentOrderBy2["state"] = 4] = "state";
activeDeploymentOrderBy2[activeDeploymentOrderBy2["scheduled"] = 5] = "scheduled";
activeDeploymentOrderBy2[activeDeploymentOrderBy2["begin"] = 6] = "begin";
activeDeploymentOrderBy2[activeDeploymentOrderBy2["end"] = 7] = "end";
return activeDeploymentOrderBy2;
})(activeDeploymentOrderBy || {});
var archivedDeploymentOrderBy = /* @__PURE__ */ ((archivedDeploymentOrderBy2) => {
archivedDeploymentOrderBy2[archivedDeploymentOrderBy2["application"] = 0] = "application";
archivedDeploymentOrderBy2[archivedDeploymentOrderBy2["environment_id"] = 1] = "environment_id";
archivedDeploymentOrderBy2[archivedDeploymentOrderBy2["taskType"] = 2] = "taskType";
archivedDeploymentOrderBy2[archivedDeploymentOrderBy2["owner"] = 3] = "owner";
archivedDeploymentOrderBy2[archivedDeploymentOrderBy2["state"] = 4] = "state";
archivedDeploymentOrderBy2[archivedDeploymentOrderBy2["startDate"] = 5] = "startDate";
archivedDeploymentOrderBy2[archivedDeploymentOrderBy2["completionDate"] = 6] = "completionDate";
return archivedDeploymentOrderBy2;
})(archivedDeploymentOrderBy || {});
function useCurrentDeployments(entity) {
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(5);
const [orderBy, setOrderBy] = useState(7);
const [orderDirection, setOrderDirection] = useState("desc");
const api = useApi(daiDeployApiRef);
const ciId = entity.metadata.annotations?.[DAI_DEPLOY_CI_ID_ANNOTATION];
const direction = orderDirection === "" ? "desc" : orderDirection;
const sortColumn = orderBy !== -1 ? activeDeploymentOrderBy[orderBy] : "begin";
if (!ciId) {
throw new Error(
`Value for annotation "${DAI_DEPLOY_CI_ID_ANNOTATION}" was not found`
);
}
const entityRef = stringifyEntityRef(entity);
const { value, loading, error, retry } = useAsyncRetry(async () => {
return api.getCurrentDeployments(
ciId,
page,
rowsPerPage,
sortColumn,
direction,
entityRef
);
}, [api, page, rowsPerPage, orderBy, orderDirection]);
return {
items: value?.items,
loading,
error,
retry,
page,
setPage,
rowsPerPage,
setRowsPerPage,
setOrderDirection,
setOrderBy
};
}
function useDeploymentsReports(entity) {
const [page, setPage] = useState(0);
const [rowsPerPage, setRowsPerPage] = useState(5);
const [orderBy, setOrderBy] = useState(5);
const [orderDirection, setOrderDirection] = useState("desc");
const api = useApi(daiDeployApiRef);
const ciId = entity.metadata.annotations?.[DAI_DEPLOY_CI_ID_ANNOTATION];
const direction = orderDirection === "" ? "desc" : orderDirection;
const sortColumn = orderBy !== -1 ? archivedDeploymentOrderBy[orderBy] : "startDate";
if (!ciId) {
throw new Error(
`Value for annotation "${DAI_DEPLOY_CI_ID_ANNOTATION}" was not found`
);
}
const entityRef = stringifyEntityRef(entity);
const { value, loading, error, retry } = useAsyncRetry(async () => {
return api.getDeploymentsReports(
ciId,
page,
rowsPerPage,
sortColumn,
direction,
entityRef
);
}, [api, page, rowsPerPage, orderBy, orderDirection]);
return {
items: value?.items,
loading,
error,
retry,
page,
setPage,
rowsPerPage,
setRowsPerPage,
setOrderDirection,
setOrderBy
};
}
export { useCurrentDeployments, useDeploymentsReports };
//# sourceMappingURL=useDeployments.esm.js.map