-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:theopensystemslab/planx-new into je…
…ss/selectable-planning-constraints
- Loading branch information
Showing
24 changed files
with
512 additions
and
79 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
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
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,90 @@ | ||
# How to add fields to the Editor search index | ||
|
||
## Overview | ||
|
||
This guide outlines the process of adding new searchable fields to the PlanX Editors' frontend search functionality, which uses Fuse.js for indexing and searching. This is a required step with adding a new component to PlanX, or adding new fields to an existing component. | ||
|
||
## Background | ||
|
||
- Search is currently implemented in the frontend using Fuse.js | ||
- Only certain fields are searchable: | ||
- Text fields (simple text) | ||
- Rich text fields (HTML) | ||
- Data values (e.g. `data.fn`) | ||
|
||
## Process | ||
|
||
### 1. Update facets configuration | ||
|
||
Location: `src/pages/FlowEditor/components/Sidebar/Search/facets.ts` | ||
|
||
#### Guidelines: | ||
- Use key paths to the new fields (e.g. `data.myNewField`) | ||
- Wrap rich text fields with `richTextField()` helper - this strips HTML tags | ||
- Add data fields to `DATA_FACETS` | ||
- Add text fields to `ALL_FACETS` | ||
- Avoid adding duplicate values already held in `ALL_FACETS` (e.g., `data.title`, `data.description`) | ||
|
||
#### Example: | ||
|
||
```ts | ||
// facets.ts | ||
|
||
const myNewComponent: SearchFacets = [ | ||
richTextField("data.myRichTextField"), | ||
"data.myPlainTextField" | ||
]; | ||
|
||
export const ALL_FACETS: SearchFacets = [ | ||
...otherComponents, | ||
...myNewComponent, | ||
...DATA_FACETS, | ||
]; | ||
``` | ||
|
||
### 2. Assign display values | ||
|
||
Location: `src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/getDisplayDetailsForResult.tsx` | ||
|
||
#### Add key formatters: | ||
|
||
```ts | ||
// getDisplayDetailsForResult.tsx | ||
|
||
const keyFormatters: KeyMap = { | ||
...existingFormatters, | ||
"data.myNewField": { | ||
getDisplayKey: () => "My New Field", | ||
}, | ||
}; | ||
``` | ||
|
||
### 3. Update tests | ||
|
||
Locations: | ||
- `src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/allFacets.test.ts` | ||
- `src/pages/FlowEditor/components/Sidebar/Search/SearchResultCard/dataFacets.test.ts` | ||
|
||
#### Test steps: | ||
1. Add new component to `mockFlow` | ||
2. Create mock search result | ||
- Example: `mockMyComponentResult: SearchResult<IndexedNode>` | ||
|
||
### Debugging tip | ||
|
||
A search result can be easily logged to the console from `SearchResultCard`. Simply search for one of your new fields, and click on the card. | ||
|
||
```ts | ||
// SearchResultCard/index.tsx | ||
|
||
const handleClick = () => { | ||
const url = getURLForNode(result.item.id); | ||
// Temporarily disable navigation | ||
// navigate(url); | ||
|
||
// Log the full search result to console | ||
console.log({ result }); | ||
}; | ||
``` | ||
|
||
For reference, [please see this PR](https://github.com/theopensystemslab/planx-new/pull/4015) which added the text fields for the `Feedback` component to the search index. |
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
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
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
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
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
32 changes: 32 additions & 0 deletions
32
editor.planx.uk/src/@planx/components/Pay/Editor/FeeBreakdownSection.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,32 @@ | ||
import ReceiptLongIcon from "@mui/icons-material/ReceiptLong"; | ||
import { useFormikContext } from "formik"; | ||
import { hasFeatureFlag } from "lib/featureFlags"; | ||
import React from "react"; | ||
import ModalSection from "ui/editor/ModalSection"; | ||
import ModalSectionContent from "ui/editor/ModalSectionContent"; | ||
import InputRow from "ui/shared/InputRow"; | ||
import { Switch } from "ui/shared/Switch"; | ||
|
||
import { Pay } from "../model"; | ||
|
||
export const FeeBreakdownSection: React.FC = () => { | ||
const { values, setFieldValue } = useFormikContext<Pay>(); | ||
|
||
if (!hasFeatureFlag("FEE_BREAKDOWN")) return null; | ||
|
||
return ( | ||
<ModalSection> | ||
<ModalSectionContent title="Fee breakdown" Icon={ReceiptLongIcon}> | ||
<InputRow> | ||
<Switch | ||
checked={values.showFeeBreakdown} | ||
onChange={() => | ||
setFieldValue("showFeeBreakdown", !values.showFeeBreakdown) | ||
} | ||
label="Display a breakdown of the fee to the applicant" | ||
/> | ||
</InputRow> | ||
</ModalSectionContent> | ||
</ModalSection> | ||
); | ||
}; |
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
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
Oops, something went wrong.