Skip to content
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 basic tree creation functionality #5080

Open
wants to merge 49 commits into
base: production
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
1e459c8
Fixes #1600
Areyes42 Jul 3, 2024
4ca7ef5
Undo test commit message
Areyes42 Jul 3, 2024
6069a5d
Merge branch 'production' into issue-4833
Areyes42 Jul 9, 2024
8d22dcb
Create add tree button
Areyes42 Jul 15, 2024
4193c80
Lint code with ESLint and Prettier
Areyes42 Jul 15, 2024
7ea5f2a
Merge branch 'production' into issue-4833
Areyes42 Jul 15, 2024
58163f8
Add an empty dialog box
Areyes42 Jul 15, 2024
d93cd03
Added to tree text localization and edited dialog
combs-a Jul 16, 2024
032e785
Lint code with ESLint and Prettier
combs-a Jul 16, 2024
f4e2e53
Separate tree creation into its own file
combs-a Jul 16, 2024
fc72d47
Lint code with ESLint and Prettier
combs-a Jul 16, 2024
5a83d5b
Changed dialog open/close handler
combs-a Jul 17, 2024
e99c3ed
Lint code with ESLint and Prettier
combs-a Jul 17, 2024
53ed46f
Add second dialog menu for tree rank form
Areyes42 Jul 17, 2024
d8ca138
Finished basic dialogs
combs-a Jul 22, 2024
20b5cf2
Lint code with ESLint and Prettier
combs-a Jul 22, 2024
6446193
Only show table creation button on Taxon tree
combs-a Jul 24, 2024
2f20526
Lint code with ESLint and Prettier
combs-a Jul 24, 2024
dc79360
Check for institutional admin permissions
Areyes42 Jul 24, 2024
6edb541
Lint code with ESLint and Prettier
Areyes42 Jul 24, 2024
9c25eed
Add JSONs for tree defaults
Areyes42 Jul 29, 2024
b732e3b
Lint code with ESLint and Prettier
Areyes42 Jul 29, 2024
4866074
Replace tree default JSONs to objects
Areyes42 Aug 2, 2024
894b147
Merge branch 'production' into issue-4833
combs-a Aug 5, 2024
f2899de
Fixed missed bracket
combs-a Aug 5, 2024
7f9a40a
Remove tree JSONs
Areyes42 Aug 5, 2024
0cad9c3
Changed second dialog to use ResourceView
combs-a Aug 5, 2024
f581daf
Have ResourceView work with SerializedResource
combs-a Aug 6, 2024
db5def9
Change resourceview to handle multiple SerializedResources
Areyes42 Aug 7, 2024
3698041
Added list of defaults to first dialog + changed TreeDefaults file to…
combs-a Aug 16, 2024
693607f
Changed types to avoid a million errors
combs-a Aug 16, 2024
a6e907d
Merge branch 'production' into issue-4833
combs-a Aug 16, 2024
8664c9d
Merge branch 'production' into issue-4833
grantfitzsimmons Aug 19, 2024
96361a5
Use localized on resource.name to prevent type error
combs-a Aug 26, 2024
6b080ff
Change filename of TreeDefaults, add localized import
combs-a Aug 26, 2024
eae2870
Removed newTree from localization since it wasn't necessary and chang…
combs-a Aug 27, 2024
b46f560
Lint code with ESLint and Prettier
combs-a Aug 27, 2024
7557c75
Merge branch 'production' into issue-4833
combs-a Sep 3, 2024
15dd61d
Added tree names and default remarks to localization
combs-a Sep 9, 2024
b231d93
Add TreeDefItem check for table permission
Areyes42 Sep 12, 2024
08e2609
Disabled add button for gridview/subview TaxonTreeDefItems
combs-a Sep 12, 2024
ecdb8e3
Merge branch 'production' into issue-4833
combs-a Sep 16, 2024
f393c27
Replace TaxonTreeDefItem table check with strict equality
Areyes42 Sep 17, 2024
5039c40
Lint code with ESLint and Prettier
Areyes42 Sep 17, 2024
f0731e5
Work on unique name support
combs-a Sep 30, 2024
682a4f2
Lint code with ESLint and Prettier
combs-a Sep 30, 2024
e1c28dc
Reverse order setName and setSelected
CarolineDenis Oct 1, 2024
dd44985
Add empty tree to defaults
Areyes42 Oct 1, 2024
b58654e
Lint code with ESLint and Prettier
Areyes42 Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export function IntegratedRecordSelector({

const [isDialogOpen, handleOpenDialog, handleCloseDialog] = useBooleanState();

const isTaxonTreeDefItemTable =
collection.table.specifyTable.name.includes('TaxonTreeDefItem');
Areyes42 marked this conversation as resolved.
Show resolved Hide resolved

const isAttachmentTable =
collection.table.specifyTable.name.includes('Attachment');

Expand Down Expand Up @@ -185,6 +188,7 @@ export function IntegratedRecordSelector({
<DataEntry.Add
disabled={
isReadOnly ||
isTaxonTreeDefItemTable ||
(isToOne && collection.models.length > 0)
}
onClick={(): void => {
Expand Down Expand Up @@ -252,7 +256,8 @@ export function IntegratedRecordSelector({
preHeaderButtons={collapsibleButton}
sortField={sortField}
viewName={viewName}
onAdd={(resources): void => {
onAdd={isTaxonTreeDefItemTable ? undefined :
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

considering that the TaxonTreeDefItems have their own specific adding setup, we did this so that there wouldn't be any weirdness with ranks (if you add a rank via the TreeDef editor then the new rank will be the lowest rank + 10 automatically and you can't edit it unless forms have been changed)

We don't think our changes will affect anything else but let us know 👍

(resources): void => {
if (!isInteraction) collection.add(resources);
handleAdd?.(resources);
}}
Expand Down
88 changes: 88 additions & 0 deletions specifyweb/frontend/js_src/lib/components/TreeView/CreateTree.tsx
combs-a marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react';

import { commonText } from '../../localization/common';
import { treeText } from '../../localization/tree';
import type { DeepPartial } from '../../utils/types';
import { localized } from '../../utils/types';
import { Ul } from '../Atoms';
import { Button } from '../Atoms/Button';
import { className } from '../Atoms/className';
import type {
AnySchema,
AnyTree,
SerializedResource,
} from '../DataModel/helperTypes';
import type { SpecifyResource } from '../DataModel/legacyTypes';
import { deserializeResource } from '../DataModel/serializers';
import type { TaxonTreeDef } from '../DataModel/types';
import { ResourceView } from '../Forms/ResourceView';
import { userInformation } from '../InitialContext/userInformation';
import { Dialog } from '../Molecules/Dialog';
import { defaultTreeDefs } from './defaults';

export function CreateTree<SCHEMA extends AnyTree>({
tableName,
}: {
readonly tableName: SCHEMA['tableName'];
}): JSX.Element {
const [isActive, setIsActive] = React.useState(0);
const [selectedResource, setSelectedResource] = React.useState<
SpecifyResource<AnySchema> | undefined
>(undefined);

const handleClick = (
resource: DeepPartial<SerializedResource<TaxonTreeDef>>
) => {
const dsResource = deserializeResource(resource);
setSelectedResource(dsResource);
setIsActive(2);
};

return (
<>
{tableName === 'Taxon' && userInformation.isadmin ? (
<Button.Icon
className={className.dataEntryAdd}
icon="plus"
title={treeText.addTree()}
onClick={() => {
setIsActive(1);
}}
/>
) : null}
{isActive === 1 ? (
<Dialog
buttons={
<Button.DialogClose component={Button.BorderedGray}>
{commonText.cancel()}
</Button.DialogClose>
}
header={treeText.addTree()}
onClose={() => setIsActive(0)}
>
<Ul className="flex flex-col gap-2">
{defaultTreeDefs.map((resource, index) => (
<li key={index}>
<Button.LikeLink onClick={(): void => handleClick(resource)}>
{localized(resource.name)}
</Button.LikeLink>
</li>
))}
</Ul>
</Dialog>
) : null}
{isActive === 2 && selectedResource !== undefined ? (
<ResourceView
dialog="modal"
isDependent={false}
isSubForm={false}
resource={selectedResource}
onAdd={undefined}
onClose={() => setIsActive(0)}
onDeleted={undefined}
onSaved={(): void => globalThis.location.reload()}
/>
) : null}
</>
);
}
Loading
Loading