Compare commits
1 Commits
master
...
c10bcf90db
| Author | SHA1 | Date | |
|---|---|---|---|
| c10bcf90db |
@@ -32,8 +32,8 @@ export const CrudForm: React.FC<CrudFormProps> = (props) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchSchema = async () => {
|
const fetchSchema = async () => {
|
||||||
try {
|
try {
|
||||||
const schemaFullName = id === undefined ? `${schemaName}Create` : `${schemaName}Update`;
|
const resourceSchema = id === undefined ? await jsonschemaProvider.getCreateResourceSchema(schemaName)
|
||||||
const resourceSchema = await jsonschemaProvider.getResourceSchema(schemaFullName);
|
: await jsonschemaProvider.getCardResourceSchema(schemaName);
|
||||||
setSchema(resourceSchema);
|
setSchema(resourceSchema);
|
||||||
setSchemaLoading(false);
|
setSchemaLoading(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -5,10 +5,37 @@ const API_URL = "/api/v1";
|
|||||||
|
|
||||||
|
|
||||||
export const jsonschemaProvider = {
|
export const jsonschemaProvider = {
|
||||||
getResourceSchema: async (resourceName: string): Promise<RJSFSchema> => {
|
getCardResourceSchema: async (resourceName: string): Promise<RJSFSchema> => {
|
||||||
return buildResource(await getJsonschema(), resourceName)
|
const updateSchema = await getResourceSchema(`${resourceName}Update`);
|
||||||
|
const readSchema = await getResourceSchema(`${resourceName}Read`);
|
||||||
|
|
||||||
|
for (let prop_name in readSchema.properties) {
|
||||||
|
if (! updateSchema.hasOwnProperty(prop_name)) {
|
||||||
|
if (is_reference(readSchema.properties[prop_name])) {
|
||||||
|
let subresourceName = get_reference_name(readSchema.properties[prop_name]);
|
||||||
|
readSchema.components.schemas[subresourceName].readOnly = true;
|
||||||
|
} else {
|
||||||
|
readSchema.properties[prop_name].readOnly = true;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
changePropertiesOrder(readSchema);
|
||||||
|
|
||||||
|
return readSchema
|
||||||
|
},
|
||||||
|
|
||||||
|
getUpdateResourceSchema: async (resourceName: string): Promise<RJSFSchema> => {
|
||||||
|
return getResourceSchema(`${resourceName}Update`)
|
||||||
|
},
|
||||||
|
|
||||||
|
getCreateResourceSchema: async (resourceName: string): Promise<RJSFSchema> => {
|
||||||
|
return getResourceSchema(`${resourceName}Create`)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
const getResourceSchema = async (resourceName: string): Promise<RJSFSchema> => {
|
||||||
|
return buildResource(await getJsonschema(), resourceName)
|
||||||
|
}
|
||||||
|
|
||||||
let rawSchema: RJSFSchema;
|
let rawSchema: RJSFSchema;
|
||||||
const getJsonschema = async (): Promise<RJSFSchema> => {
|
const getJsonschema = async (): Promise<RJSFSchema> => {
|
||||||
|
|||||||
Reference in New Issue
Block a user