Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui: Show job statuses in product list #1207

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 81 additions & 1 deletion ui/src/routes/_layout/organizations/$orgId/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import {
getCoreRowModel,
useReactTable,
} from '@tanstack/react-table';
import { EditIcon, PlusIcon } from 'lucide-react';
import { EditIcon, Loader2, PlusIcon } from 'lucide-react';

import {
useOrganizationsServiceDeleteOrganizationById,
useOrganizationsServiceGetOrganizationById,
useProductsServiceGetOrganizationProducts,
useRepositoriesServiceGetRepositoriesByProductId,
} from '@/api/queries';
import {
prefetchUseOrganizationsServiceGetOrganizationById,
Expand All @@ -54,6 +55,9 @@ import {
} from '@/components/ui/tooltip';
import { toast } from '@/lib/toast';
import { paginationSchema } from '@/schemas';
import { LastJobStatus } from './products/$productId/-components/last-job-status';
import { LastRunDate } from './products/$productId/-components/last-run-date';
import { LastRunStatus } from './products/$productId/-components/last-run-status';

const defaultPageSize = 10;

Expand All @@ -79,6 +83,82 @@ const columns: ColumnDef<Product>[] = [
</>
),
},
{
accessorKey: 'runStatus',
header: () => <div>Last Run Status</div>,
cell: function CellComponent({ row }) {
const { data, isPending, isError } =
useRepositoriesServiceGetRepositoriesByProductId({
productId: row.original.id,
limit: 1,
});

if (isPending)
return (
<>
<span className='sr-only'>Loading...</span>
<Loader2 size={16} className='mx-3 animate-spin' />
</>
);

if (isError) return <span>Error loading data.</span>;

if (data.pagination.totalCount === 1)
return <LastRunStatus repoId={data.data[0].id} />;
else
return <span>Contains {data.pagination.totalCount} repositories</span>;
},
},
{
accessorKey: 'lastRunDate',
header: () => <div>Last Run Date</div>,
cell: function CellComponent({ row }) {
const { data, isPending, isError } =
useRepositoriesServiceGetRepositoriesByProductId({
productId: row.original.id,
limit: 1,
});

if (isPending)
return (
<>
<span className='sr-only'>Loading...</span>
<Loader2 size={16} className='mx-3 animate-spin' />
</>
);

if (isError) return <span>Error loading data.</span>;

if (data.pagination.totalCount === 1)
return <LastRunDate repoId={data.data[0].id} />;
else return null;
},
},
{
accessorKey: 'jobStatus',
header: () => <div>Last Job Status</div>,
cell: function CellComponent({ row }) {
const { data, isPending, isError } =
useRepositoriesServiceGetRepositoriesByProductId({
productId: row.original.id,
limit: 1,
});

if (isPending)
return (
<>
<span className='sr-only'>Loading...</span>
<Loader2 size={16} className='mx-3 animate-spin' />
</>
);

if (isError) return <span>Error loading data.</span>;

if (data.pagination.totalCount === 1)
return <LastJobStatus repoId={data.data[0].id} />;
else return null;
},
},
];

const OrganizationComponent = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2024 The ORT Server Authors (See <https://github.com/eclipse-apoapsis/ort-server/blob/main/NOTICE>)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
* License-Filename: LICENSE
*/

import { Loader2 } from 'lucide-react';

import { useRepositoriesServiceGetOrtRunsByRepositoryId } from '@/api/queries';

export const LastRunDate = ({ repoId }: { repoId: number }) => {
const {
data: runs,
isPending: runsIsPending,
isError: runsIsError,
} = useRepositoriesServiceGetOrtRunsByRepositoryId({
repositoryId: repoId,
limit: 1,
sort: '-index',
});

if (runsIsPending) {
return (
<>
<span className='sr-only'>Loading...</span>
<Loader2 size={16} className='mx-3 animate-spin' />
</>
);
}

if (runsIsError) return <span>Error loading run.</span>;

if (runs.data.length === 0) return null;

const run = runs.data[0];

return (
<>
{run.finishedAt ? (
<div>{new Date(run.finishedAt).toLocaleString(navigator.language)}</div>
) : (
<div className='italic'>
{new Date(run.createdAt).toLocaleString(navigator.language)}
</div>
)}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
import { toast } from '@/lib/toast';
import { paginationSchema } from '@/schemas';
import { LastJobStatus } from './-components/last-job-status';
import { LastRunDate } from './-components/last-run-date';
import { LastRunStatus } from './-components/last-run-status';

const defaultPageSize = 10;
Expand Down Expand Up @@ -87,6 +88,11 @@ const columns: ColumnDef<Repository>[] = [
header: () => <div>Last Run Status</div>,
cell: ({ row }) => <LastRunStatus repoId={row.original.id} />,
},
{
accessorKey: 'lastRunDate',
header: () => <div>Last Run Date</div>,
cell: ({ row }) => <LastRunDate repoId={row.original.id} />,
},
{
accessorKey: 'jobStatus',
header: () => <div>Last Job Status</div>,
Expand Down