Skip to content

Commit

Permalink
refactor(ui): Align validation schemas
Browse files Browse the repository at this point in the history
Rename the Zod validation schemas used in the UI, to better distinguish
between "type schemas" and schemas used for search parameter validation.

Signed-off-by: Jyrki Keisala <[email protected]>
  • Loading branch information
Etsija committed Nov 15, 2024
1 parent 5ac8833 commit ef35b72
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 78 deletions.
4 changes: 2 additions & 2 deletions ui/src/routes/_layout/admin/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
import { StatisticsCard } from '@/components/statistics-card';
import { ToastError } from '@/components/toast-error';
import { toast } from '@/lib/toast';
import { ortRunStatus } from '@/schemas';
import { runStatusSchema } from '@/schemas';

const OverviewContent = () => {
const {
Expand Down Expand Up @@ -115,7 +115,7 @@ const OverviewContent = () => {
</Link>
<Link
to='/admin/runs'
search={{ status: [ortRunStatus.Values.ACTIVE] }}
search={{ status: [runStatusSchema.Values.ACTIVE] }}
>
<StatisticsCard
title='Active runs'
Expand Down
12 changes: 9 additions & 3 deletions ui/src/routes/_layout/admin/runs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ import {
import { config } from '@/config';
import { getStatusBackgroundColor } from '@/helpers/get-status-class';
import { toast } from '@/lib/toast';
import { ortRunStatus, paginationSchema, statusSchema } from '@/schemas';
import {
paginationSearchParameterSchema,
runStatusSchema,
statusSearchParameterSchema,
} from '@/schemas';

const defaultPageSize = 10;
const pollInterval = config.pollInterval;
Expand Down Expand Up @@ -262,7 +266,7 @@ const RunsComponent = () => {
filters={
<FilterMultiSelect
title='Run Status'
options={ortRunStatus.options.map((status) => ({
options={runStatusSchema.options.map((status) => ({
label: status,
value: status,
}))}
Expand Down Expand Up @@ -307,7 +311,9 @@ const RunsComponent = () => {
};

export const Route = createFileRoute('/_layout/admin/runs/')({
validateSearch: paginationSchema.merge(statusSchema),
validateSearch: paginationSearchParameterSchema.merge(
statusSearchParameterSchema
),
loaderDeps: ({ search: { page, pageSize, status } }) => ({
page,
pageSize,
Expand Down
4 changes: 2 additions & 2 deletions ui/src/routes/_layout/admin/users/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
TooltipTrigger,
} from '@/components/ui/tooltip';
import { toast } from '@/lib/toast';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } from '@/schemas';

const defaultPageSize = 10;

Expand Down Expand Up @@ -196,7 +196,7 @@ const Users = () => {
};

export const Route = createFileRoute('/_layout/admin/users/')({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loader: async ({ context }) => {
prefetchUseAdminServiceGetUsers(context.queryClient);
},
Expand Down
4 changes: 2 additions & 2 deletions ui/src/routes/_layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import {
TooltipContent,
TooltipTrigger,
} from '@/components/ui/tooltip';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } from '@/schemas';

const defaultPageSize = 10;

Expand Down Expand Up @@ -138,7 +138,7 @@ export const IndexPage = () => {
};

export const Route = createFileRoute('/_layout/')({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loaderDeps: ({ search: { page, pageSize } }) => ({ page, pageSize }),
loader: async ({ context, deps: { page, pageSize } }) => {
prefetchUseOrganizationsServiceGetOrganizations(context.queryClient, {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/routes/_layout/organizations/$orgId/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
TooltipTrigger,
} from '@/components/ui/tooltip';
import { toast } from '@/lib/toast';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } 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';
Expand Down Expand Up @@ -359,7 +359,7 @@ const OrganizationComponent = () => {
};

export const Route = createFileRoute('/_layout/organizations/$orgId/')({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loaderDeps: ({ search: { page, pageSize } }) => ({ page, pageSize }),
loader: async ({ context, params, deps: { page, pageSize } }) => {
await Promise.allSettled([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
} from '@/components/ui/tooltip';
import { toast } from '@/lib/toast';
import { cn } from '@/lib/utils';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } from '@/schemas';

const defaultPageSize = 10;

Expand Down Expand Up @@ -328,7 +328,7 @@ const InfrastructureServices = () => {
export const Route = createFileRoute(
'/_layout/organizations/$orgId/infrastructure-services/'
)({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loaderDeps: ({ search: { page, pageSize } }) => ({ page, pageSize }),
loader: async ({ context, params, deps: { page, pageSize } }) => {
await Promise.allSettled([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
TooltipTrigger,
} from '@/components/ui/tooltip';
import { toast } from '@/lib/toast';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } from '@/schemas';
import { LastJobStatus } from './-components/last-job-status';
import { LastRunDate } from './-components/last-run-date';
import { LastRunStatus } from './-components/last-run-status';
Expand Down Expand Up @@ -290,7 +290,7 @@ const ProductComponent = () => {
export const Route = createFileRoute(
'/_layout/organizations/$orgId/products/$productId/'
)({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loaderDeps: ({ search: { page, pageSize } }) => ({ page, pageSize }),
loader: async ({ context, params, deps: { page, pageSize } }) => {
await Promise.allSettled([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ import { identifierToString } from '@/helpers/identifier-to-string';
import { compareSeverity } from '@/helpers/sorting-functions';
import { toast } from '@/lib/toast';
import {
issueSeverity,
issueSeveritySchema,
paginationSchema,
tableSortingSchema,
paginationSearchParameterSchema,
severitySchema,
severitySearchParameterSchema,
sortingSearchParameterSchema,
} from '@/schemas';

const defaultPageSize = 10;
Expand Down Expand Up @@ -248,7 +248,7 @@ const IssuesComponent = () => {
filters={
<FilterMultiSelect
title='Issue Severity'
options={issueSeverity.options.map((severity) => ({
options={severitySchema.options.map((severity) => ({
label: severity,
value: severity,
}))}
Expand Down Expand Up @@ -319,9 +319,9 @@ const IssuesComponent = () => {
export const Route = createFileRoute(
'/_layout/organizations/$orgId/products/$productId/repositories/$repoId/_layout/runs/$runIndex/issues/'
)({
validateSearch: paginationSchema
.merge(issueSeveritySchema)
.merge(tableSortingSchema),
validateSearch: paginationSearchParameterSchema
.merge(severitySearchParameterSchema)
.merge(sortingSearchParameterSchema),
loader: async ({ context, params }) => {
await prefetchUseRepositoriesServiceGetOrtRunByIndex(context.queryClient, {
repositoryId: Number.parseInt(params.repoId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import {
} from '@/components/ui/card';
import { identifierToString } from '@/helpers/identifier-to-string';
import { toast } from '@/lib/toast';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } from '@/schemas';

const defaultPageSize = 10;

Expand Down Expand Up @@ -262,7 +262,7 @@ const PackagesComponent = () => {
export const Route = createFileRoute(
'/_layout/organizations/$orgId/products/$productId/repositories/$repoId/_layout/runs/$runIndex/packages/'
)({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loader: async ({ context, params }) => {
await prefetchUseRepositoriesServiceGetOrtRunByIndex(context.queryClient, {
repositoryId: Number.parseInt(params.repoId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ import { getRuleViolationSeverityBackgroundColor } from '@/helpers/get-status-cl
import { identifierToString } from '@/helpers/identifier-to-string';
import { compareSeverity } from '@/helpers/sorting-functions';
import {
paginationSchema,
ruleViolationSeverity,
ruleViolationSeveritySchema,
tableSortingSchema,
paginationSearchParameterSchema,
severitySchema,
severitySearchParameterSchema,
sortingSearchParameterSchema,
} from '@/schemas';

const defaultPageSize = 10;
Expand Down Expand Up @@ -233,7 +233,7 @@ const RuleViolationsComponent = () => {
filters={
<FilterMultiSelect
title='Rule Violation Severity'
options={ruleViolationSeverity.options.map((severity) => ({
options={severitySchema.options.map((severity) => ({
label: severity,
value: severity,
}))}
Expand Down Expand Up @@ -306,9 +306,9 @@ const RuleViolationsComponent = () => {
export const Route = createFileRoute(
'/_layout/organizations/$orgId/products/$productId/repositories/$repoId/_layout/runs/$runIndex/rule-violations/'
)({
validateSearch: paginationSchema
.merge(ruleViolationSeveritySchema)
.merge(tableSortingSchema),
validateSearch: paginationSearchParameterSchema
.merge(severitySearchParameterSchema)
.merge(sortingSearchParameterSchema),
loader: async ({ context, params }) => {
await prefetchUseRepositoriesServiceGetOrtRunByIndex(context.queryClient, {
repositoryId: Number.parseInt(params.repoId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ import { getVulnerabilityRatingBackgroundColor } from '@/helpers/get-status-clas
import { identifierToString } from '@/helpers/identifier-to-string';
import { compareVulnerabilityRating } from '@/helpers/sorting-functions';
import { toast } from '@/lib/toast';
import { paginationSchema, tableSortingSchema } from '@/schemas';
import {
paginationSearchParameterSchema,
sortingSearchParameterSchema,
} from '@/schemas';

const defaultPageSize = 10;

Expand Down Expand Up @@ -353,7 +356,9 @@ const VulnerabilitiesComponent = () => {
export const Route = createFileRoute(
'/_layout/organizations/$orgId/products/$productId/repositories/$repoId/_layout/runs/$runIndex/vulnerabilities/'
)({
validateSearch: paginationSchema.merge(tableSortingSchema),
validateSearch: paginationSearchParameterSchema.merge(
sortingSearchParameterSchema
),
loader: async ({ context, params }) => {
await prefetchUseRepositoriesServiceGetOrtRunByIndex(context.queryClient, {
repositoryId: Number.parseInt(params.repoId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
import { config } from '@/config';
import { getStatusBackgroundColor } from '@/helpers/get-status-class';
import { toast } from '@/lib/toast';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } from '@/schemas';

const defaultPageSize = 10;
const pollInterval = config.pollInterval;
Expand Down Expand Up @@ -358,7 +358,7 @@ const RepoComponent = () => {
export const Route = createFileRoute(
'/_layout/organizations/$orgId/products/$productId/repositories/$repoId/'
)({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loaderDeps: ({ search: { page, pageSize } }) => ({ page, pageSize }),
loader: async ({ context, params, deps: { page, pageSize } }) => {
await Promise.allSettled([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import {
} from '@/components/ui/tooltip';
import { toast } from '@/lib/toast';
import { cn } from '@/lib/utils';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } from '@/schemas';

const defaultPageSize = 10;

Expand Down Expand Up @@ -259,7 +259,7 @@ const RepositorySecrets = () => {
export const Route = createFileRoute(
'/_layout/organizations/$orgId/products/$productId/repositories/$repoId/secrets/'
)({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loaderDeps: ({ search: { page, pageSize } }) => ({ page, pageSize }),
loader: async ({ context, params, deps: { page, pageSize } }) => {
await Promise.allSettled([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import {
} from '@/components/ui/tooltip';
import { toast } from '@/lib/toast';
import { cn } from '@/lib/utils';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } from '@/schemas';

const defaultPageSize = 10;

Expand Down Expand Up @@ -256,7 +256,7 @@ const ProductSecrets = () => {
export const Route = createFileRoute(
'/_layout/organizations/$orgId/products/$productId/secrets/'
)({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loaderDeps: ({ search: { page, pageSize } }) => ({ page, pageSize }),
loader: async ({ context, params, deps: { page, pageSize } }) => {
await Promise.allSettled([
Expand Down
4 changes: 2 additions & 2 deletions ui/src/routes/_layout/organizations/$orgId/secrets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ import {
} from '@/components/ui/tooltip';
import { toast } from '@/lib/toast';
import { cn } from '@/lib/utils';
import { paginationSchema } from '@/schemas';
import { paginationSearchParameterSchema } from '@/schemas';

const defaultPageSize = 10;

Expand Down Expand Up @@ -250,7 +250,7 @@ const OrganizationSecrets = () => {
};

export const Route = createFileRoute('/_layout/organizations/$orgId/secrets/')({
validateSearch: paginationSchema,
validateSearch: paginationSearchParameterSchema,
loaderDeps: ({ search: { page, pageSize } }) => ({ page, pageSize }),
loader: async ({ context, params, deps: { page, pageSize } }) => {
await Promise.allSettled([
Expand Down
Loading

0 comments on commit ef35b72

Please sign in to comment.