Skip to content

Commit

Permalink
fix recursive formatting & fix search bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mgtennant committed Aug 26, 2024
1 parent 8098187 commit 659e87e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
8 changes: 8 additions & 0 deletions backend/src/report/report.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ export class ReportService {
});
}

// individual Signing block takes 2 cdogs requests to be fully filled in, so this regex
// makes sure that the db_name_tenant variable is formatted correctly
if (free_text.toLowerCase().includes('db_name_tenant}')) {
free_text = free_text.replace(/db_name_tenant}/gi, 'DB_NAME_TENANT:convCRLF()}');
} else if (free_text.toLowerCase().includes('db_name_tenant:convcrlf()}')) {
free_text = free_text.replace(/db_name_tenant:convcrlf\(\)}/gi, 'DB_NAME_TENANT:convCRLF()}');
}

const key = `SECTION_${provision_group}`;
if (!provisions[key]) {
provisions[key] = [];
Expand Down
41 changes: 32 additions & 9 deletions frontend/src/app/content/pages/ManageProvisionsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
removeProvision,
updateProvision,
} from '../../common/manage-provisions';
import SimpleSearch from '../../components/common/SimpleSearch';

interface ManageProvisionsPageProps {}

Expand All @@ -27,6 +26,7 @@ const ManageProvisionsPage: FC<ManageProvisionsPageProps> = () => {
const [showRemoveProvisionModal, setShowRemoveProvisionModal] = useState<boolean>(false);
const [refreshTrigger, setRefreshTrigger] = useState(0);
const [filteredProvisions, setFilteredProvisions] = useState<Provision[]>([]);
const [filterText, setFilterText] = useState('');

useEffect(() => {
const getData = async () => {
Expand All @@ -46,7 +46,11 @@ const ManageProvisionsPage: FC<ManageProvisionsPageProps> = () => {

useEffect(() => {
if (data.allProvisions) {
setFilteredProvisions(data.allProvisions);
if (!filterText || filterText === '') {
setFilteredProvisions(data.allProvisions);
} else {
handleFilterProvisions(filterText);
}
}
}, [data.allProvisions]);

Expand Down Expand Up @@ -76,8 +80,22 @@ const ManageProvisionsPage: FC<ManageProvisionsPageProps> = () => {
refreshTables();
};

const handleSearch = (filteredProvisions: Provision[]) => {
setFilteredProvisions(filteredProvisions);
const handleSearch = (event: React.ChangeEvent<HTMLInputElement>) => {
const text: string = event.target.value;
handleFilterProvisions(text);
};

const handleFilterProvisions = (searchTerm: string) => {
const searchKeys: string[] = ['provision_name', 'category'];
setFilterText(searchTerm);

const fp: Provision[] = data.allProvisions
? data.allProvisions.filter((item) =>
searchKeys.some((key) => (item as any)[key]?.toString().toLowerCase().includes(searchTerm.toLowerCase()))
)
: [];

setFilteredProvisions(fp);
};

const currentVariables = data.allVariables?.filter((v) => v.provision_id === currentProvision?.id) || [];
Expand All @@ -86,11 +104,16 @@ const ManageProvisionsPage: FC<ManageProvisionsPageProps> = () => {
<>
<h1>Manage Provisions</h1>
<hr />
<SimpleSearch
searchKeys={['provision_name', 'category']}
data={data.allProvisions ? data.allProvisions : []}
onSearch={handleSearch}
/>
<div>
<input
type="text"
className="form-control"
style={{ maxWidth: '200px' }}
placeholder="Search..."
value={filterText}
onChange={handleSearch}
/>
</div>
<ManageProvisionsTable
provisions={filteredProvisions}
variables={data.allVariables}
Expand Down

0 comments on commit 659e87e

Please sign in to comment.