Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix platform search #259

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/common/cqlFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ const funcParameterVocabs: ParameterVocabsIn = (vocabs: Array<Vocab>) => {
const funcPlatformFilter: PlatformFilter = (platforms: Array<string>) => {
if (!platforms || platforms.length === 0) return "";

const platformQueries = platforms.map((platform) => `platform='${platform}'`);
const platformQueries = platforms.map(
(platform) => `platform_vocabs='${platform}'`
);
return `(${platformQueries.join(" or ")})`;
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/common/store/componentParamReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
import { bboxPolygon } from "@turf/turf";
import { Feature, Polygon, GeoJsonProperties } from "geojson";
import { DatasetFrequency, mergeToSearchText } from "./searchReducer";
import { DatasetFrequency } from "./searchReducer";
import { MapDefaultConfig } from "../../map/mapbox/constants";

const UPDATE_PARAMETER_STATES = "UPDATE_PARAMETER_STATES";
Expand Down
39 changes: 8 additions & 31 deletions src/components/common/store/searchReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { ParameterState, Vocab } from "./componentParamReducer";
import {
cqlDefaultFilters,
ParameterVocabsIn,
PlatformFilter,
PolygonOperation,
TemporalAfterOrBefore,
TemporalDuring,
Expand Down Expand Up @@ -300,21 +301,6 @@ const createSuggesterParamFrom = (
// return base ? Number(base) + Number(pump) : Number(pump);
// };

// Helper function to merge search terms into search text
const mergeToSearchText = (
values: string[] | undefined,
searchText: string | undefined
): string[] => {
const terms: string[] = [];
if (searchText) {
terms.push(searchText);
}
if (values && values.length > 0) {
terms.push(...values);
}
return terms;
};

// Given a ParameterState object, we convert it to the correct Restful parameters
// always call this function and do not handcraft it elsewhere, some control isn't
// part the ParameterState and therefore express as optional argument here
Expand All @@ -324,14 +310,7 @@ const createSearchParamFrom = (
): SearchParameters => {
const p: SearchParameters = {};
p.sortby = i.sortby;

// Merge searchText with platforms
// This is a temporary solution to deal with platform since ogcapi doesn't support platform filter so just merge it into search text for a fuzzy search
// TODO: need to remove this block if ogcapi support platform filter
const searchTerms = mergeToSearchText(i.platform, i.searchText);
if (searchTerms.length > 0) {
p.text = searchTerms.join(" ");
}
p.text = i.searchText;

const c = mergeWithDefaults(
{
Expand Down Expand Up @@ -414,21 +393,19 @@ const createSearchParamFrom = (
}
}

// TODO: add platform filter if ogcapi support it
// if (i.platform && i.platform.length > 0) {
// const f = cqlDefaultFilters.get(
// "UPDATE_PLATFORM_FILTER_VARIABLES"
// ) as PlatformFilter;
// p.filter = appendFilter(p.filter, f(i.platform));
// }
if (i.platform && i.platform.length > 0) {
const f = cqlDefaultFilters.get(
"UPDATE_PLATFORM_FILTER_VARIABLES"
) as PlatformFilter;
p.filter = appendFilter(p.filter, f(i.platform));
}

return p;
};

export {
createSuggesterParamFrom,
createSearchParamFrom,
mergeToSearchText,
fetchSuggesterOptions,
fetchResultWithStore,
fetchResultNoStore,
Expand Down
2 changes: 1 addition & 1 deletion src/components/filter/tab-filters/PlatformFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const PLATFORMS = [
icon: <GliderIcon />,
},
{
value: "gloat",
value: "float",
label: "Float",
icon: <FloatIcon />,
},
Expand Down
Loading