-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EN-5157 Bring views over from pdd-web (#2507)
Sorry this PR is so large! It doesn't have any functional changes from the code that has already been reviewed and put into `pdd-web`. - Add Documents, Document, Preview, and Documents Add views from `pdd-web` - Hook into AcceleratorRouter behind feature flag - Visible at `/accelerator/documents`, APIs currently don't work as backend isn't hooked up ![SCR-20240411-onpb.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/wJnPX9wLZAkiGXEBFJxL/e00cc8a2-7809-4a68-ba73-572a8c6dccde.png)
- Loading branch information
Showing
69 changed files
with
6,152 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/components/DocumentProducer/DocumentMetadataEdit/helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { DropdownItem } from '@terraware/web-components/components/types'; | ||
|
||
import { User } from 'src/types/User'; | ||
import { Methodology } from 'src/types/documentProducer/Methodology'; | ||
import { getUserDisplayName } from 'src/utils/user'; | ||
|
||
export const getMethodologyOptions = (methodologies: Methodology[]): DropdownItem[] => | ||
methodologies.map((methodology) => ({ | ||
label: methodology.name, | ||
value: methodology.id.toString(), | ||
})); | ||
|
||
export const getDocumentOwnerOptions = (users: User[]): DropdownItem[] => | ||
users.map((user) => ({ | ||
label: getUserDisplayName(user) ?? '', | ||
value: user.id.toString(), | ||
})); | ||
|
||
export const getMethodologyName = (methodologies: Methodology[], id?: string | number): string => | ||
methodologies.find((methodology) => methodology.id.toString() === id?.toString())?.name ?? ''; |
164 changes: 164 additions & 0 deletions
164
src/components/DocumentProducer/DocumentMetadataEdit/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
import React, { useEffect, useMemo } from 'react'; | ||
|
||
import { Box, useTheme } from '@mui/material'; | ||
import { styled } from '@mui/material/styles'; | ||
import { Dropdown, Textfield } from '@terraware/web-components'; | ||
import isString from 'lodash/isString'; | ||
|
||
import { selectMethodologies } from 'src/redux/features/documentProducer/methodologies/methodologiesSelector'; | ||
import { requestListMethodologies } from 'src/redux/features/documentProducer/methodologies/methodologiesThunks'; | ||
import { useAppDispatch, useAppSelector } from 'src/redux/store'; | ||
import strings from 'src/strings'; | ||
import { User } from 'src/types/User'; | ||
import useSnackbar from 'src/utils/useSnackbar'; | ||
|
||
import { getDocumentOwnerOptions, getMethodologyName, getMethodologyOptions } from './helpers'; | ||
|
||
export type DocumentMetadataEditProps = { | ||
associatedOrganization?: string; | ||
setAssociatedOrganization: (organization: string) => void; | ||
documentName?: string; | ||
setDocumentName: (name: string) => void; | ||
documentOwner?: string; | ||
setDocumentOwner: (userId: string) => void; | ||
methodologyId?: string; | ||
setMethodologyId?: (methodlogyId: string) => void; | ||
isEdit?: boolean; | ||
formValid?: boolean; | ||
}; | ||
|
||
const DocumentMetadataEdit = ({ | ||
associatedOrganization, | ||
setAssociatedOrganization, | ||
documentName, | ||
setDocumentName, | ||
documentOwner, | ||
setDocumentOwner, | ||
methodologyId, | ||
setMethodologyId, | ||
isEdit, | ||
formValid, | ||
}: DocumentMetadataEditProps): JSX.Element => { | ||
const dispatch = useAppDispatch(); | ||
const theme = useTheme(); | ||
const snackbar = useSnackbar(); | ||
const { methodologies, error: getMethodologiesError } = useAppSelector(selectMethodologies); | ||
|
||
// TODO we don't have redux for this, should it only be TF accelerator users? Or all admins? | ||
// const { data: users, error: getUsersError } = useAppSelector(selectUsers); | ||
const users: User[] = useMemo(() => [], []); | ||
const getUsersError = null; | ||
|
||
const methodologyOptions = useMemo(() => getMethodologyOptions(methodologies || []), [methodologies]); | ||
const documentOwnerOptions = useMemo(() => getDocumentOwnerOptions(users || []), [users]); | ||
|
||
useEffect(() => { | ||
dispatch(requestListMethodologies()); | ||
// TODO we don't have redux for this, should it only be TF accelerator users? Or all admins? | ||
// dispatch(requestListUsers()); | ||
}, [dispatch]); | ||
|
||
useEffect(() => { | ||
if (getMethodologiesError) { | ||
snackbar.toastError(strings.GENERIC_ERROR); | ||
} | ||
}, [snackbar, getMethodologiesError]); | ||
|
||
useEffect(() => { | ||
if (getUsersError) { | ||
snackbar.toastError(strings.GENERIC_ERROR); | ||
} | ||
}, [snackbar, getUsersError]); | ||
|
||
// All fields are required in this form | ||
const getErrorText = (value: unknown): string => (formValid === false && !value ? strings.REQUIRED_FIELD : ''); | ||
|
||
// This probably seems like overkill, I just didn't want to cast value to string in the Textfield onChange. | ||
// Since it comes back as unknown, use typeguard | ||
// TODO maybe Textfield should return back an explicit type? | ||
function handleTextFieldChange(value: unknown, setter: (value: string) => void): void { | ||
if (isString(value)) { | ||
setter(value); | ||
} | ||
} | ||
|
||
const FormField = useMemo( | ||
() => | ||
styled(Box)({ | ||
marginBottom: theme.spacing(2), | ||
textAlign: 'left', | ||
}), | ||
[theme] | ||
); | ||
|
||
return ( | ||
<> | ||
<FormField> | ||
<Textfield | ||
id='associated-organization' | ||
label={strings.DOCUMENTS_ADD_FORM_ASSOC_ORG} | ||
type='text' | ||
value={associatedOrganization} | ||
errorText={getErrorText(associatedOrganization)} | ||
onChange={(value: unknown) => handleTextFieldChange(value, setAssociatedOrganization)} | ||
required | ||
/> | ||
</FormField> | ||
|
||
<FormField> | ||
{isEdit ? ( | ||
<Textfield | ||
id='methodology' | ||
label={strings.DOCUMENTS_ADD_FORM_METHODOLOGY} | ||
type='text' | ||
value={getMethodologyName(methodologies ?? [], methodologyId)} | ||
display={true} | ||
required | ||
/> | ||
) : ( | ||
<Dropdown | ||
id='methodology' | ||
placeholder={strings.SELECT} | ||
selectedValue={methodologyId} | ||
options={methodologyOptions} | ||
onChange={(value: string) => setMethodologyId && setMethodologyId(value)} | ||
hideClearIcon={true} | ||
label={strings.DOCUMENTS_ADD_FORM_METHODOLOGY} | ||
errorText={getErrorText(methodologyId)} | ||
autocomplete | ||
required | ||
/> | ||
)} | ||
</FormField> | ||
|
||
<FormField> | ||
<Textfield | ||
id='document-name' | ||
label={strings.DOCUMENTS_ADD_FORM_DOC_NAME} | ||
type='text' | ||
value={documentName} | ||
errorText={getErrorText(documentName)} | ||
onChange={(value: unknown) => handleTextFieldChange(value, setDocumentName)} | ||
required | ||
/> | ||
</FormField> | ||
|
||
<FormField> | ||
<Dropdown | ||
id='document-owner' | ||
placeholder={strings.SELECT} | ||
selectedValue={documentOwner} | ||
options={documentOwnerOptions} | ||
onChange={(value: string) => setDocumentOwner(value)} | ||
hideClearIcon={true} | ||
label={strings.DOCUMENTS_ADD_FORM_DOC_OWNER} | ||
errorText={getErrorText(documentOwner)} | ||
autocomplete | ||
required | ||
/> | ||
</FormField> | ||
</> | ||
); | ||
}; | ||
|
||
export default DocumentMetadataEdit; |
Oops, something went wrong.