Skip to content

Commit

Permalink
Merge pull request #213 from bcgov/ticdi-363-365
Browse files Browse the repository at this point in the history
Ticdi 363 365
  • Loading branch information
mgtennant committed Jun 21, 2024
2 parents 55b0a40 + ade3023 commit 4797f56
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
9 changes: 8 additions & 1 deletion frontend/src/app/content/display/Provisions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Provisions: FC<ProvisionsProps> = ({ dtid, documentType, provisionGroups }

return (
<>
<div>
<div style={{ display: 'flex', alignItems: 'center' }}>
<label htmlFor="provisionGroupSelect" style={{ marginRight: '10px' }}>
Select A Group
</label>
Expand All @@ -81,6 +81,13 @@ const Provisions: FC<ProvisionsProps> = ({ dtid, documentType, provisionGroups }
</option>
))}
</select>
<div style={{ marginLeft: '10px' }}>
{selectedProvisionGroupMax
? selectedProvisionGroupMax > 100
? 'There is no max for this group.'
: `Max for this group is ${selectedProvisionGroupMax}`
: ''}
</div>
</div>
<ProvisionsTable
provisions={provisions}
Expand Down
30 changes: 24 additions & 6 deletions frontend/src/app/content/pages/LandingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import { setSelectedVariableIds, setVariables } from '../../store/reducers/varia
import { RootState } from '../../store/store';
import { setSearchState } from '../../store/reducers/searchSlice';
import { useParams } from 'react-router-dom';
// import Collapsible from './documentpreview/Collapsible';

const LandingPage: FC = () => {
const { dtidNumber, docTypeFromUrl } = useParams();
Expand All @@ -54,6 +53,7 @@ const LandingPage: FC = () => {
const [selectedDocTypeId, setSelectedDocTypeId] = useState<number | null>(null);
const [documentType, setDocumentType] = useState<DocType | null>(null);
const [documentTypes, setDocumentTypes] = useState<DocType[]>([]);
const [filteredDocumentTypes, setFilteredDocumentTypes] = useState<DocType[]>([]);

const [variableEdits, setVariableEdits] = useState<{ [variableId: number]: string }>({});

Expand Down Expand Up @@ -95,12 +95,13 @@ const LandingPage: FC = () => {
}
}, [documentTypes, docTypeFromUrl]);

// Gets all document types and sorts them
useEffect(() => {
const fetchBasicData = async () => {
try {
const documentTypes: DocType[] = await getDocumentTypes();
documentTypes.sort((a, b) => a.name.localeCompare(b.name));
setDocumentTypes(documentTypes);
const dts: DocType[] = await getDocumentTypes();
dts.sort((a, b) => a.name.localeCompare(b.name));
setDocumentTypes(dts);
} catch (error) {
console.error('Failed to fetch doc types', error);
setData(null);
Expand All @@ -117,6 +118,7 @@ const LandingPage: FC = () => {
}
}, [documentTypes, selectedDocTypeId]);

// Used when coming from the search page to automatically load data
useEffect(() => {
const applySearch = async () => {
if (searchState.searching && searchState.dtid && searchState.document_type) {
Expand Down Expand Up @@ -186,6 +188,23 @@ const LandingPage: FC = () => {
fetchDocData();
}, [documentType, dtid, dispatch]);

useEffect(() => {
if (data && data.type) {
switch (data.type) {
case 'LEASE':
// filter out document type that includes word LICENCE
setFilteredDocumentTypes(documentTypes.filter((dt) => !dt.name.toLowerCase().includes('licence')));
break;
case 'LICENCE':
// filter out document type that includes word LEASE
setFilteredDocumentTypes(documentTypes.filter((dt) => !dt.name.toLowerCase().includes('lease')));
break;
default:
setFilteredDocumentTypes(documentTypes);
}
}
}, [data, documentTypes]);

const fetchData = async (dtidValue: number) => {
try {
setLoading(true);
Expand Down Expand Up @@ -358,7 +377,6 @@ const LandingPage: FC = () => {
} else {
setGenerateError(errorMessage);
setShowGenerateError(true);
// alert(errorMessage);
}
}
} catch (err) {
Expand Down Expand Up @@ -432,7 +450,7 @@ const LandingPage: FC = () => {
onChange={handleDocTypeChange}
>
<option value="-1">Select a document type</option>
{documentTypes.map((docType) => (
{filteredDocumentTypes.map((docType) => (
<option key={docType.id} value={docType.id}>
{docType.name}
</option>
Expand Down

0 comments on commit 4797f56

Please sign in to comment.