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

Advanced search changes #2831

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: 2 additions & 2 deletions apps/fishing-map/features/search/SearchDownload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function SearchDownload() {
const vesselsParsed = vesselsSelected.map((vessel) => {
return {
name: formatInfoField(getVesselProperty(vessel, 'shipname'), 'shipname'),
ssvid: getVesselProperty(vessel, 'ssvid'),
mmsi: getVesselProperty(vessel, 'ssvid'),
imo: getVesselProperty(vessel, 'imo'),
'call sign': getVesselProperty(vessel, 'callsign'),
flag: t(`flags:${getVesselProperty(vessel, 'flag')}` as any),
Expand All @@ -42,7 +42,7 @@ function SearchDownload() {
label: JSON.stringify(
vesselsParsed.map((vessel) => ({
name: vessel.name,
mmsi: vessel.ssvid,
mmsi: vessel.mmsi,
imo: vessel.imo,
callsign: vessel['call sign'],
owner: vessel.owner,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ function AdvancedFilterInputField({
const value = searchFilters[field] || ''
const invalid = searchFilterErrors[field]

const PLACEHOLDER_BY_FIELD: Record<string, string> = useMemo(
() => ({
ssvid: '123456789, 987654321, ...',
imo: '1234567, 7654321, ...',
callsign: 'A1BC2, X2YZ, ...',
owner: t('search.placeholderFilterMultiple', 'One or more values (comma separated)'),
}),
[t]
)

return (
<InputText
onChange={onChange}
Expand All @@ -95,7 +105,8 @@ function AdvancedFilterInputField({
: ''
}
value={value}
label={t(`vessel.${field}`, field)}
placeholder={PLACEHOLDER_BY_FIELD[field as string]}
label={t(`vessel.${field === 'ssvid' ? 'mmsi' : field}`, field)}
/>
)
}
Expand Down
10 changes: 7 additions & 3 deletions apps/fishing-map/features/search/search.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { getRelatedDatasetByType, isFieldInFieldsAllowed } from 'features/datase
import { IdentityVesselData, VesselDataIdentity } from 'features/vessel/vessel.slice'
import { getVesselId, getVesselIdentities } from 'features/vessel/vessel.utils'
import { VesselSearchState } from 'features/search/search.types'
import { ADVANCED_SEARCH_FIELDS } from 'features/search/advanced/advanced-search.utils'

export type VesselLastIdentity = Omit<IdentityVesselData, 'identities' | 'dataset'> & {
dataset: Dataset | string
Expand Down Expand Up @@ -98,9 +99,12 @@ export const fetchVesselSearchThunk = createAsyncThunk(
const filter = (filters as any)[cleanField]
if (filter && isInFieldsAllowed) {
let value = filter
// Supports searching by multiple values separated by comma in owners
if (field === 'owner' && value?.includes(', ')) {
value = (value as string).split(', ')
// Supports searching by multiple values separated by comma
if (ADVANCED_SEARCH_FIELDS.includes(field as any) && value?.includes(',')) {
value = (value as string)
.split(',')
.map((v) => v.trim())
.filter(Boolean)
}
return { key: field as AdvancedSearchQueryFieldKey, value }
}
Expand Down
8 changes: 4 additions & 4 deletions apps/fishing-map/features/vessel/vessel.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export function getLatestIdentityPrioritised(vessel: IdentityVessel | IdentityVe
const latestSelfReportesIdentity = getVesselIdentity(vessel, {
identitySource: VesselIdentitySourceEnum.SelfReported,
})
const identity = latestRegistryIdentity || latestSelfReportesIdentity
const identitySource = latestRegistryIdentity
? VesselIdentitySourceEnum.Registry
: VesselIdentitySourceEnum.SelfReported
const identity = latestSelfReportesIdentity || latestRegistryIdentity
const identitySource = latestSelfReportesIdentity
? VesselIdentitySourceEnum.SelfReported
: VesselIdentitySourceEnum.Registry
const geartypes = getVesselProperty(vessel, 'geartypes', {
identitySource,
identityId: identity?.id,
Expand Down
1 change: 1 addition & 0 deletions apps/fishing-map/public/locales/source/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@
"notValidFilter": "At least one of your selected sources doesn't allow one of your filters",
"notValidFilterSelection": "At least one of your selected sources doesn't allow one of your filters",
"placeholder": "Type to search vessels",
"placeholderFilterMultiple": "One or more values (comma separated)",
"result_one": "result",
"result_other": "results",
"searching": "Searching more than 100K vessels ...",
Expand Down
Loading