-
Notifications
You must be signed in to change notification settings - Fork 36
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
Add new configuration setup forms #6201
base: production
Are you sure you want to change the base?
Changes from all commits
ea22561
7de19a1
cbe7aeb
33cb8bb
137f166
13065ae
60fa90d
c1109d4
24a11c6
fdebed5
5e2b8fa
575cd97
73c1b86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from 'react'; | ||
|
||
import { configurationText } from '../../localization/configurationText'; | ||
import { ajax } from '../../utils/ajax'; | ||
import { Http } from '../../utils/ajax/definitions'; | ||
import { Container, H2 } from '../Atoms'; | ||
import type { SpecifyResource } from '../DataModel/legacyTypes'; | ||
import { tables } from '../DataModel/tables'; | ||
import type { Collection } from '../DataModel/types'; | ||
import { adminUser, collection, discipline, division, institution } from '../FormParse/webOnlyViews'; | ||
import { ResourceView } from '../Forms/ResourceView'; | ||
|
||
export function ConfigurationTool(): JSX.Element { | ||
|
||
const onInstitutionSaved = async (data: any) => ajax('/specify/institution/create/', { | ||
method: 'POST', | ||
headers: { Accept: 'application/json' }, | ||
body: JSON.stringify(data), | ||
errorMode: 'visible', | ||
expectedErrors: | ||
[Http.CREATED], | ||
}) | ||
.then(({ data, status }) => { | ||
if (status === Http.OK) { | ||
console.log('Institution created successfully:', data); | ||
} else { | ||
console.error('Error creating institution:', data); | ||
} | ||
}).catch(error => { | ||
console.error('Request failed:', error); | ||
}); | ||
|
||
const resources = [ | ||
{ resource: new tables.Institution.Resource(), viewName: institution, onClick: () => console.log('click') }, | ||
{ resource: new tables.Division.Resource(), viewName: division, onClick: () => console.log('click') }, | ||
{ resource: new tables.Discipline.Resource(), viewName: discipline, onClick: () => console.log('click') }, | ||
{ resource: new tables.Collection.Resource(), viewName: collection, onClick: () => console.log('click') }, | ||
{ resource: new tables.SpecifyUser.Resource(), viewName: adminUser, onClick: () => console.log('click') } | ||
]; | ||
|
||
const onClose = ():void => { | ||
console.log('close') | ||
} | ||
|
||
return ( | ||
<Container.FullGray> | ||
<H2 className="text-2xl">{configurationText.specifySetUp()}</H2> | ||
{resources.map((resource, index) => ( | ||
<ResourceView | ||
dialog={false} | ||
isDependent={false} | ||
isSubForm={false} | ||
key={index} | ||
resource={resource.resource as SpecifyResource<Collection>} | ||
viewName={resource.viewName} | ||
onAdd={undefined} | ||
onClose={() => onClose()} | ||
onDeleted={undefined} | ||
onSaved={async () => resource.onClick()} | ||
|
||
/* | ||
* Example on how to call another function and not the normal save logic: | ||
* onSaving={async () => resource.onClick()} | ||
* onSaving={(unsetUnloadProtect): false => { | ||
* unsetUnloadProtect(); | ||
* loading( | ||
* ajax<number>(`/api/workbench/create_recordset/${datasetId}/`, { | ||
* method: 'POST', | ||
* headers: { Accept: 'application/json' }, | ||
* body: formData({ name: recordSet.get('name') }), | ||
* errorMode: 'dismissible', | ||
* }).then(({ data }) => | ||
* unsafeNavigate(`/specify/record-set/${data}/`) | ||
* ) | ||
* ); | ||
* return false; | ||
* }} | ||
*/ | ||
/> | ||
))} | ||
</Container.FullGray> | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,37 @@ export const webOnlyViews = f.store(() => | |
'edit', | ||
['name'] | ||
), | ||
[adminUser]: autoGenerateViewDefinition( | ||
tables.SpecifyUser, | ||
'form', | ||
'edit', | ||
['name', 'password', 'agents'] | ||
), | ||
[institution]: autoGenerateViewDefinition( | ||
tables.Institution, | ||
'form', | ||
'edit', | ||
['name', 'code', 'isAccessionsGlobal', 'isSingleGeographyTree', 'isSecurityOn', 'isServerBased'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
), | ||
[division]: autoGenerateViewDefinition( | ||
tables.Division, | ||
'form', | ||
'edit', | ||
['name', 'abbrev'] | ||
), | ||
[discipline]: autoGenerateViewDefinition( | ||
tables.Discipline, | ||
'form', | ||
'edit', | ||
// Required field: institution id | ||
['name', 'type'] | ||
), | ||
[collection]: autoGenerateViewDefinition( | ||
tables.Collection, | ||
'form', | ||
'edit', | ||
['collectionName', 'code', 'catalogNumFormatName'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
), | ||
} as const) | ||
); | ||
|
||
|
@@ -92,3 +123,8 @@ export const attachmentView = 'ObjectAttachment'; | |
export const spAppResourceView = '_SpAppResourceView_name'; | ||
export const spViewSetNameView = '_SpViewSetObj_name'; | ||
export const recordSetView = '_RecordSet_name'; | ||
export const adminUser = '_AdminUser_setup'; | ||
export const institution = '_Institution_setup'; | ||
export const division = '_Division_setup'; | ||
export const discipline = '_Discipline_setup'; | ||
export const collection = '_Collection_setup'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Localization strings for the preferences menu | ||
* | ||
* @module | ||
*/ | ||
|
||
import { createDictionary } from './utils'; | ||
|
||
// Refer to "Guidelines for Programmers" in ./README.md before editing this file | ||
|
||
export const configurationText = createDictionary({ | ||
configurationTool: { | ||
'en-us': 'Configuration Tool' | ||
}, | ||
specifySetUp: { | ||
'en-us': 'Specify Setup' | ||
}, | ||
} as const) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Field captions are usually determined by the schema configuration, but in the case the user sees this upon a first run, the captions will just be verbatim the name (e.g. "IsAccessionsGlobal" rather than a user-assigned schema). How are we going to set the labels?