Change useProjectName to synchronous code
Signed-off-by: KaemonIsland <kaemonlovendahl@outlook.com>
This commit is contained in:
@@ -170,22 +170,19 @@ export const WorkflowRunDetails = ({ entity }: { entity: Entity }) => {
|
||||
const hostname = readGitHubIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.github') ?? [],
|
||||
)[0].host;
|
||||
const [owner, repo] = projectName.value ? projectName.value.split('/') : [];
|
||||
const [owner, repo] = (projectName && projectName.split('/')) || [];
|
||||
const details = useWorkflowRunsDetails({ hostname, owner, repo });
|
||||
const jobs = useWorkflowRunJobs({ hostname, owner, repo });
|
||||
|
||||
const error = projectName.error || (projectName.value && details.error);
|
||||
const loading = projectName.loading || details.loading || !details.value;
|
||||
|
||||
const classes = useStyles();
|
||||
|
||||
if (error && error.message) {
|
||||
if (details.error && details.error.message) {
|
||||
return (
|
||||
<Typography variant="h6" color="error">
|
||||
Failed to load build, {error.message}
|
||||
Failed to load build, {details.error.message}
|
||||
</Typography>
|
||||
);
|
||||
} else if (loading) {
|
||||
} else if (details.loading) {
|
||||
return <LinearProgress />;
|
||||
}
|
||||
return (
|
||||
|
||||
@@ -37,7 +37,7 @@ export const useWorkflowRunJobs = ({
|
||||
repo,
|
||||
id: parseInt(id, 10),
|
||||
})
|
||||
: Promise.reject('No repo/owner provided');
|
||||
: Promise.reject(Error('No repo/owner provided'));
|
||||
}, [repo, owner, id]);
|
||||
return jobs;
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ export const useWorkflowRunsDetails = ({
|
||||
repo,
|
||||
id: parseInt(id, 10),
|
||||
})
|
||||
: Promise.reject('No repo/owner provided');
|
||||
: Promise.reject(Error('No repo/owner provided'));
|
||||
}, [repo, owner, id]);
|
||||
return details;
|
||||
};
|
||||
|
||||
@@ -83,7 +83,7 @@ export const WorkflowRunLogs = ({
|
||||
const hostname = readGitHubIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.github') ?? [],
|
||||
)[0].host;
|
||||
const [owner, repo] = projectName.value ? projectName.value.split('/') : [];
|
||||
const [owner, repo] = (projectName && projectName.split('/')) || [];
|
||||
const jobLogs = useDownloadWorkflowRunLogs({
|
||||
hostname,
|
||||
owner,
|
||||
|
||||
@@ -157,7 +157,7 @@ export const WorkflowRunsTable = ({
|
||||
branch?: string;
|
||||
}) => {
|
||||
const config = useApi(configApiRef);
|
||||
const { value: projectName, loading } = useProjectName(entity);
|
||||
const projectName = useProjectName(entity);
|
||||
// TODO: Get github hostname from metadata annotation
|
||||
const hostname = readGitHubIntegrationConfigs(
|
||||
config.getOptionalConfigArray('integrations.github') ?? [],
|
||||
@@ -172,7 +172,7 @@ export const WorkflowRunsTable = ({
|
||||
});
|
||||
|
||||
const githubHost = hostname || 'github.com';
|
||||
const hasNoRuns = !loading && !tableProps.loading && !runs;
|
||||
const hasNoRuns = !tableProps.loading && !runs;
|
||||
|
||||
return hasNoRuns ? (
|
||||
<EmptyState
|
||||
@@ -193,7 +193,7 @@ export const WorkflowRunsTable = ({
|
||||
<WorkflowRunsTableView
|
||||
{...tableProps}
|
||||
runs={runs}
|
||||
loading={loading || tableProps.loading}
|
||||
loading={tableProps.loading}
|
||||
retry={retry}
|
||||
onChangePageSize={setPageSize}
|
||||
onChangePage={setPage}
|
||||
|
||||
@@ -13,15 +13,9 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import useAsync from 'react-use/lib/useAsync';
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
|
||||
export const GITHUB_ACTIONS_ANNOTATION = 'github.com/project-slug';
|
||||
|
||||
export const useProjectName = (entity: Entity) => {
|
||||
const { value, loading, error } = useAsync(async () => {
|
||||
return entity?.metadata.annotations?.[GITHUB_ACTIONS_ANNOTATION] ?? '';
|
||||
});
|
||||
return { value, loading, error };
|
||||
};
|
||||
export const useProjectName = (entity: Entity) =>
|
||||
entity?.metadata.annotations?.[GITHUB_ACTIONS_ANNOTATION] ?? '';
|
||||
|
||||
Reference in New Issue
Block a user