Skip to content

Commit

Permalink
Revert "chore: spec work"
Browse files Browse the repository at this point in the history
This reverts commit 7e35583.
  • Loading branch information
BCerki committed Sep 1, 2023
1 parent cbf5448 commit dd9b2c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 151 deletions.
6 changes: 1 addition & 5 deletions app/data/jsonSchemaForm/projectRevisionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ export const createProjectRevisionSchema = {
type: "string",
title: "Revision Type",
default: undefined,
// anyOf: undefined,
anyOf: undefined,
enum: undefined,
enumNames: undefined,
required: true,
},
},
dependencies: {
Expand All @@ -20,15 +18,13 @@ export const createProjectRevisionSchema = {
properties: {
revisionType: {
const: !"Amendment",
title: "brianna",
},
},
},
{
properties: {
revisionType: {
const: "Amendment",
title: "brianna",
},
amendmentTypes: {
type: "array",
Expand Down
169 changes: 23 additions & 146 deletions app/pages/cif/project-revision/[projectRevision]/create.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import { useRouter } from "next/router";
import { getProjectRevisionFormPageRoute } from "routes/pageRoutes";
import { useCreateProjectRevision } from "mutations/ProjectRevision/createProjectRevision";
import EmptyObjectFieldTemplate from "lib/theme/EmptyObjectFieldTemplate";
import ContextualHelp from "lib/theme/widgets/ContextualHelp";

const pageQuery = graphql`
query createProjectRevisionQuery($projectRevision: ID!) {
Expand Down Expand Up @@ -83,155 +82,37 @@ export function ProjectRevisionCreate({
},
});
};

const revisionEnum = allRevisionTypes.edges.map((e) => e.node.type);
createProjectRevisionSchema.properties.revisionType.enum = revisionEnum;

const amendmentTypeEnum = allAmendmentTypes.edges.map((e) => e.node.name);

const localSchema = JSON.parse(JSON.stringify(createProjectRevisionSchema));
localSchema.dependencies.revisionType.oneOf[1].properties.amendmentTypes.items.enum =
amendmentTypeEnum;

const existingRevisionType = existingAmendment
? "Amendment"
: existingGeneralRevision
? "General Revision"
: null;

const disabledEnums = existingRevisionType ? [existingRevisionType] : [];
// (
// <>
// {e.node.type}
// {disabledEnums.includes(e.node.type) && (
// <ContextualHelp
// text={tooltipText}
// label={e.node.type}
// placement="right"
// />
// )}
// </>
// );

const revisionAnyOf = allRevisionTypes.edges.map((e) => {
return {
type: "string",
// title: (
// <>
// {e.node.type}
// {disabledEnums.includes(e.node.type) && (
// <ContextualHelp
// text={"tooltipText"}
// label={e.node.type}
// placement="right"
// />
// )}
// </>
// ),
title: "brai",
enum: [e.node.type],
};
});

const revisionEnum = allRevisionTypes.edges.map((e) => e.node.type);
const revisionEnumNames = allRevisionTypes.edges.map((e) => {
return (
<>
{e.node.type}
{disabledEnums.includes(e.node.type) && (
<ContextualHelp
text={"tooltipText"}
label={e.node.type}
placement="right"
/>
)}
</>
);
});

// console.log("createProjectRevisionSchema", createProjectRevisionSchema);
// const amendmentTypeEnum = allAmendmentTypes.edges.map((e) => e.node.name);

// const localSchema = JSON.parse(JSON.stringify(createProjectRevisionSchema));
// localSchema.dependencies.revisionType.oneOf[1].properties.amendmentTypes.items.enum =
// amendmentTypeEnum;
createProjectRevisionSchema.properties.revisionType.enum = revisionEnum;
createProjectRevisionSchema.properties.revisionType.enumNames =
revisionEnumNames;
// console.log("createProjectRevisionSchema", createProjectRevisionSchema);

// console.log("localSchema", localSchema);

const schema = {
properties: {
field: {
type: "number",
anyOf: [
{
type: "number",
title: <div>djd</div>,
enum: [1],
},
{
type: "number",
title: "two",
enum: [2],
},
{
type: "number",
title: "three",
enum: [3],
},
],
},
},
};
// localSchema.properties.revisionType.anyOf = allRevisionTypes.edges.map(
// (e) => {
// const tooltipText = `<div><ul><li>You cannot create a new ${
// e.node.type
// } before the in-progress ${e.node.type} is ${
// e.node.type === "Amendment" ? "approved" : "applied"
// }.</li></ul></div>`;
// return {
// title: (
// <>
// {e.node.type}
// {disabledEnums.includes(e.node.type) && (
// <ContextualHelp
// text={tooltipText}
// label={e.node.type}
// placement="right"
// />
// )}
// </>
// ),
// const: e.node.type,
// };
// }
// );

// createProjectRevisionSchema.properties.revisionType.anyOf = [
// {
// type: "string",
// enum: [1],
// title: <div>djd</div>,
// },
// {
// type: "string",
// title: "two",
// enum: [2],
// },
// {
// type: "string",
// title: "three",
// enum: [3],
// },
// ];

const modifiedUiSchema = {
...projectRevisionUISchema,
// revisionType: {
// ...projectRevisionUISchema.revisionType,
// "ui:enumDisabled": disabledEnums,
// ...(existingRevisionType && {
// "ui:tooltip": {
// text: `<div><ul><li>You cannot create a new ${existingRevisionType} before the in-progress ${existingRevisionType} is ${
// existingRevisionType === "Amendment" ? "approved" : "applied"
// }.</li></ul></div>`,
// },
// }),
// },
revisionType: {
...projectRevisionUISchema.revisionType,
"ui:enumDisabled": disabledEnums,
...(existingRevisionType && {
"ui:tooltip": {
text: `<div><ul><li>You cannot create a new ${existingRevisionType} before the in-progress ${existingRevisionType} is ${
existingRevisionType === "Amendment" ? "approved" : "applied"
}.</li></ul></div>`,
},
}),
},
};

return (
Expand All @@ -243,12 +124,8 @@ export function ProjectRevisionCreate({
) : (
<FormBase
id="ProjectRevisionCreateForm"
schema={createProjectRevisionSchema as JSONSchema7}
uiSchema={{
revisionType: {
"ui:widget": "radio",
},
}}
schema={localSchema as JSONSchema7}
uiSchema={modifiedUiSchema}
onSubmit={handleCreateRevision}
ObjectFieldTemplate={EmptyObjectFieldTemplate}
>
Expand Down

0 comments on commit dd9b2c0

Please sign in to comment.