Skip to content

Commit

Permalink
feat: remove read-only revision type radio buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Sepehr-Sobhani committed Jun 29, 2023
1 parent 4c1dcb3 commit 648d9f4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 78 deletions.
38 changes: 0 additions & 38 deletions app/data/jsonSchemaForm/projectRevisionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,7 @@ export const createProjectRevisionSchema = {
export const viewProjectRevisionSchema = {
$schema: "http://json-schema.org/draft-07/schema",
type: "object",
required: ["revisionType"],
properties: {
revisionType: {
type: "string",
title: "Revision Type",
default: undefined,
anyOf: undefined,
enum: undefined,
},
changeReason: {
type: "string",
title: "General Comments",
Expand Down Expand Up @@ -106,36 +98,6 @@ export const viewProjectRevisionSchema = {
uniqueItems: true,
},
},
dependencies: {
revisionType: {
oneOf: [
{
properties: {
revisionType: {
const: !"Amendment",
},
},
},
{
properties: {
revisionType: {
const: "Amendment",
},
amendmentTypes: {
type: "array",
title: "Amendment Types",
items: {
type: "string",
enum: [],
},
uniqueItems: true,
},
},
required: ["amendmentTypes"],
},
],
},
},
};

export const projectRevisionUISchema = {
Expand Down
11 changes: 3 additions & 8 deletions app/pages/cif/project-revision/[projectRevision]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import { useState } from "react";
import { graphql, usePreloadedQuery } from "react-relay/hooks";
import { RelayProps, withRelay } from "relay-nextjs";
import { editProjectRevisionQuery } from "__generated__/editProjectRevisionQuery.graphql";
import {
buildProjectRevisionSchema,
createProjectRevisionUISchema,
} from "./view";
import { buildProjectRevisionSchema } from "./view";
import DangerAlert from "lib/theme/ConfirmationAlert";
import { Button } from "@button-inc/bcgov-theme";
import { useDeleteProjectRevisionMutation } from "mutations/ProjectRevision/deleteProjectRevision";
Expand Down Expand Up @@ -83,8 +80,7 @@ export function ProjectRevisionEdit({
}: RelayProps<{}, editProjectRevisionQuery>) {
const router = useRouter();
const query = usePreloadedQuery(EditProjectRevisionQuery, preloadedQuery);
const { session, projectRevision, allRevisionTypes, allRevisionStatuses } =
query;
const { session, projectRevision, allRevisionStatuses } = query;

const { id, revisionType, rowId, typeRowNumber, projectByProjectId } =
projectRevision;
Expand Down Expand Up @@ -143,11 +139,10 @@ export function ProjectRevisionEdit({
id={`form-${id}`}
className="project-revision-edit-form"
schema={buildProjectRevisionSchema(
allRevisionTypes.edges,
filteredRevisionStatuses,
revisionType
)}
uiSchema={createProjectRevisionUISchema(projectRevisionUISchema)}
uiSchema={projectRevisionUISchema}
ObjectFieldTemplate={EmptyObjectFieldTemplate}
theme={readOnlyTheme}
onChange={onChange}
Expand Down
34 changes: 2 additions & 32 deletions app/pages/cif/project-revision/[projectRevision]/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ export const ViewProjectRevisionQuery = graphql`
...ChangeReasonWidget_projectRevision
...RevisionRecordHistory_projectRevision
}
allRevisionTypes {
# type is passed to the helper function that builds the schema
# eslint-disable-next-line relay/unused-fields
edges {
node {
type
}
}
}
allRevisionStatuses(orderBy: SORTING_ORDER_ASC) {
# node is passed to the helper function that builds the schema
# eslint-disable-next-line relay/unused-fields
Expand All @@ -73,23 +64,10 @@ export const ViewProjectRevisionQuery = graphql`
`;

export const buildProjectRevisionSchema = (
allRevisionTypesEdges: viewProjectRevisionQuery$data["allRevisionTypes"]["edges"],
allRevisionStatusesEdges: viewProjectRevisionQuery$data["allRevisionStatuses"]["edges"],
revisionType: string
): JSONSchema7 => {
const schema = viewProjectRevisionSchema;
schema.properties.revisionType = {
...schema.properties.revisionType,
anyOf: allRevisionTypesEdges.map(({ node }) => {
return {
type: "string",
title: node.type,
enum: [node.type],
value: node.type,
} as JSONSchema7Definition;
}),
};

schema.properties.revisionStatus = {
...schema.properties.revisionStatus,
anyOf: allRevisionStatusesEdges.map(({ node }) => {
Expand All @@ -109,18 +87,11 @@ export const buildProjectRevisionSchema = (
return schema as JSONSchema7;
};

export const createProjectRevisionUISchema = (uiSchema) => {
const localUiSchema = JSON.parse(JSON.stringify(uiSchema));
localUiSchema.revisionType["ui:readonly"] = true;
return localUiSchema;
};

export function ProjectRevisionView({
preloadedQuery,
}: RelayProps<{}, viewProjectRevisionQuery>) {
const query = usePreloadedQuery(ViewProjectRevisionQuery, preloadedQuery);
const { session, projectRevision, allRevisionTypes, allRevisionStatuses } =
query;
const { session, projectRevision, allRevisionStatuses } = query;

const taskList = (
<TaskList
Expand All @@ -147,18 +118,17 @@ export function ProjectRevisionView({
<FormBase
className="project-revision-view-form"
schema={buildProjectRevisionSchema(
allRevisionTypes.edges,
allRevisionStatuses.edges,
projectRevision.revisionType
)}
fields={customFields}
formContext={{ projectRevision, query }}
formData={projectRevision}
id={`form-${projectRevision.id}`}
uiSchema={projectRevisionUISchema}
ObjectFieldTemplate={EmptyObjectFieldTemplate}
theme={readOnlyTheme}
tagName={"dl"}
uiSchema={createProjectRevisionUISchema(projectRevisionUISchema)}
widgets={{
RevisionStatusWidget,
UpdatedFormsWidget,
Expand Down

0 comments on commit 648d9f4

Please sign in to comment.