mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-02-25 16:05:21 +00:00
Type ahead cleanup (#253)
This commit is contained in:
parent
8c0e9cc493
commit
b3cc1170aa
@ -41,8 +41,8 @@ SPIFFWORKFLOW_BACKEND_URL = environ.get("SPIFFWORKFLOW_BACKEND_URL", default="ht
|
|||||||
SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_URL = environ.get(
|
SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_URL = environ.get(
|
||||||
"SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_URL", default="http://localhost:7004"
|
"SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_URL", default="http://localhost:7004"
|
||||||
)
|
)
|
||||||
SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_TYPE_AHEAD_URL = environ.get(
|
SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_TYPEAHEAD_URL = environ.get(
|
||||||
"SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_TYPE_AHEAD_URL",
|
"SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_TYPEAHEAD_URL",
|
||||||
default="https://emehvlxpwodjawtgi7ctkbvpse0vmaow.lambda-url.us-east-1.on.aws",
|
default="https://emehvlxpwodjawtgi7ctkbvpse0vmaow.lambda-url.us-east-1.on.aws",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -8,18 +8,14 @@ from flask.wrappers import Response
|
|||||||
|
|
||||||
def connector_proxy_typeahead_url() -> Any:
|
def connector_proxy_typeahead_url() -> Any:
|
||||||
"""Returns the connector proxy type ahead url."""
|
"""Returns the connector proxy type ahead url."""
|
||||||
return current_app.config["SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_TYPE_AHEAD_URL"]
|
return current_app.config["SPIFFWORKFLOW_BACKEND_CONNECTOR_PROXY_TYPEAHEAD_URL"]
|
||||||
|
|
||||||
|
|
||||||
def typeahead(category: str, prefix: str, limit: int) -> flask.wrappers.Response:
|
def typeahead(category: str, prefix: str, limit: int) -> flask.wrappers.Response:
|
||||||
url = f"{connector_proxy_typeahead_url()}/v1/type-ahead/{category}?prefix={prefix}&limit={limit}"
|
url = f"{connector_proxy_typeahead_url()}/v1/typeahead/{category}?prefix={prefix}&limit={limit}"
|
||||||
|
|
||||||
proxy_response = requests.get(url)
|
proxy_response = requests.get(url)
|
||||||
status = proxy_response.status_code
|
status = proxy_response.status_code
|
||||||
if status // 100 == 2:
|
|
||||||
response = proxy_response.text
|
response = proxy_response.text
|
||||||
else:
|
|
||||||
# supress pop up errors on the client
|
|
||||||
status = 200
|
|
||||||
response = "[]"
|
|
||||||
return Response(response, status=status, mimetype="application/json")
|
return Response(response, status=status, mimetype="application/json")
|
||||||
|
@ -23,7 +23,7 @@ import ProcessBreadcrumb from '../components/ProcessBreadcrumb';
|
|||||||
import InstructionsForEndUser from '../components/InstructionsForEndUser';
|
import InstructionsForEndUser from '../components/InstructionsForEndUser';
|
||||||
|
|
||||||
// TODO: move this somewhere else
|
// TODO: move this somewhere else
|
||||||
function TypeAheadWidget({
|
function TypeaheadWidget({
|
||||||
id,
|
id,
|
||||||
onChange,
|
onChange,
|
||||||
options: { category, itemFormat },
|
options: { category, itemFormat },
|
||||||
@ -60,7 +60,7 @@ function TypeAheadWidget({
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const typeAheadSearch = (inputText: string) => {
|
const typeaheadSearch = (inputText: string) => {
|
||||||
if (inputText) {
|
if (inputText) {
|
||||||
lastSearchTerm.current = inputText;
|
lastSearchTerm.current = inputText;
|
||||||
// TODO: check cache of prefixes -> results
|
// TODO: check cache of prefixes -> results
|
||||||
@ -74,7 +74,7 @@ function TypeAheadWidget({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ComboBox
|
<ComboBox
|
||||||
onInputChange={typeAheadSearch}
|
onInputChange={typeaheadSearch}
|
||||||
onChange={(event: any) => {
|
onChange={(event: any) => {
|
||||||
setSelectedItem(event.selectedItem);
|
setSelectedItem(event.selectedItem);
|
||||||
onChange(itemToString(event.selectedItem));
|
onChange(itemToString(event.selectedItem));
|
||||||
@ -83,7 +83,6 @@ function TypeAheadWidget({
|
|||||||
items={items}
|
items={items}
|
||||||
itemToString={itemToString}
|
itemToString={itemToString}
|
||||||
placeholder={`Start typing to search for ${category}...`}
|
placeholder={`Start typing to search for ${category}...`}
|
||||||
titleText={`Type ahead search for ${category}`}
|
|
||||||
selectedItem={selectedItem}
|
selectedItem={selectedItem}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
@ -394,7 +393,7 @@ export default function TaskShow() {
|
|||||||
return getFieldsWithDateValidations(jsonSchema, formData, errors);
|
return getFieldsWithDateValidations(jsonSchema, formData, errors);
|
||||||
};
|
};
|
||||||
|
|
||||||
const widgets = { typeAhead: TypeAheadWidget };
|
const widgets = { typeahead: TypeaheadWidget };
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid fullWidth condensed>
|
<Grid fullWidth condensed>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user