Skip to content

Commit eab635f

Browse files
committed
Add cache for filter options and fix name filter text highlight
1 parent fb57608 commit eab635f

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

epictrack-api/src/api/resources/project.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# limitations under the License.
1414
"""Resource for project endpoints."""
1515
from http import HTTPStatus
16+
from api.utils.caching import AppCache
1617

1718
from flask import jsonify, request
1819
from flask_restx import Namespace, Resource, cors
@@ -21,7 +22,7 @@
2122
from api.schemas import response as res
2223
from api.schemas.work_type import WorkTypeSchema
2324
from api.services import ProjectService
24-
from api.utils import auth, profiletime
25+
from api.utils import auth, constants, profiletime
2526
from api.utils.util import cors_preflight
2627

2728

@@ -223,6 +224,7 @@ class ProjectTypes(Resource):
223224
@cors.crossdomain(origin="*")
224225
@auth.require
225226
@profiletime
227+
@AppCache.cache.cached(timeout=constants.CACHE_DAY_TIMEOUT, query_string=True)
226228
def get():
227229
"""Return all project types."""
228230
project_types = ProjectService.find_all_project_types()

epictrack-api/src/api/resources/work.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"""Resource for work endpoints."""
1515
from http import HTTPStatus
1616
from io import BytesIO
17+
from api.utils.caching import AppCache
1718

1819
from flask import jsonify, request, send_file
1920
from flask_restx import Namespace, Resource, cors
@@ -24,7 +25,7 @@
2425
from api.schemas import response as res
2526
from api.services import WorkService
2627
from api.services.work_phase import WorkPhaseService
27-
from api.utils import auth, profiletime
28+
from api.utils import auth, constants, profiletime
2829
from api.utils.datetime_helper import get_start_of_day
2930
from api.utils.util import cors_preflight
3031

@@ -470,6 +471,7 @@ class WorkTypes(Resource):
470471
@staticmethod
471472
@cors.crossdomain(origin="*")
472473
@auth.require
474+
@AppCache.cache.cached(timeout=constants.CACHE_DAY_TIMEOUT)
473475
@profiletime
474476
def get():
475477
"""Return all active works."""

epictrack-web/src/components/myWorkplans/Filters/NameFilter.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import React, { useState, useEffect, useContext } from "react";
2-
import { Autocomplete, Box, InputAdornment, TextField } from "@mui/material";
2+
import {
3+
Autocomplete,
4+
Box,
5+
InputAdornment,
6+
MenuItem,
7+
TextField,
8+
} from "@mui/material";
39
import {
410
MyWorkplansContext,
511
WorkPlanSearchOptions,
@@ -84,7 +90,9 @@ export const NameFilter = () => {
8490
clearOnBlur
8591
noOptionsText=""
8692
renderOption={(props, option, state) => (
87-
<li {...props}>{highlightText(option, state.inputValue)}</li>
93+
<MenuItem {...props}>
94+
{highlightText(option, state.inputValue)}
95+
</MenuItem>
8896
)}
8997
disabled={loading}
9098
/>

epictrack-web/src/utils/MatchingTextHighlight.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ export const highlightText = (text: string, query: string) => {
44
const index = text.toLowerCase().indexOf(query.toLowerCase());
55
if (index !== -1) {
66
return (
7-
<>
7+
<span style={{ whiteSpace: "pre-wrap" }}>
88
{text.substring(0, index)}
99
<span style={{ backgroundColor: Palette.secondary.main }}>
1010
{text.substring(index, index + query.length)}
1111
</span>
1212
{text.substring(index + query.length)}
13-
</>
13+
</span>
1414
);
1515
}
1616
return text;

0 commit comments

Comments
 (0)