-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(lxl-web, supersearch): Display qualifier labels (LWS-274) (#1186)
* Add getLabelsFromMapping util function * Refactor lxlQualifier plugin * Svelte 5-migration of lxlweb/Search component * Update codemirror state on lxlweb navigation * Adjust response from server.ts
- Loading branch information
1 parent
3aef8ac
commit acb4405
Showing
18 changed files
with
588 additions
and
208 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,47 @@ | ||
.lxl-qualifier, | ||
.lxl-qualifier-remove { | ||
background: rgba(14, 113, 128, 0.15); | ||
padding: 2px 5px; | ||
.lxl-qualifier { | ||
display: inline-flex; | ||
color: rgb(0, 128, 0); | ||
background: rgba(14, 113, 128, 0.1); | ||
padding-top: 3px; | ||
padding-bottom: 3px; | ||
} | ||
|
||
.lxl-qualifier-key { | ||
color: green; | ||
padding-left: 5px; | ||
border-top-left-radius: 5px; | ||
border-bottom-left-radius: 5px; | ||
} | ||
|
||
.lxl-qualifier-value, | ||
.lxl-qualifier-remove { | ||
padding-right: 5px; | ||
border-top-right-radius: 5px; | ||
border-bottom-right-radius: 5px; | ||
} | ||
|
||
.lxl-qualifier-remove, | ||
.lxl-qualifier-value.atomic { | ||
padding-left: 5px; | ||
} | ||
|
||
.lxl-qualifier-value:has(~ .lxl-qualifier-remove) { | ||
border-radius: 0; | ||
} | ||
|
||
.invalid > .lxl-qualifier-key { | ||
text-decoration: underline 2px solid; | ||
text-decoration-color: rgba(255, 0, 0, 0.326); | ||
} | ||
|
||
.atomic { | ||
background: rgba(14, 113, 128, 0.2); | ||
user-select: none; | ||
} | ||
|
||
.lxl-boolean-query { | ||
color: purple; | ||
color: rgb(128, 0, 128); | ||
} | ||
|
||
.lxl-wildcard { | ||
color: purple; | ||
color: rgb(128, 0, 128); | ||
} |
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,62 @@ | ||
import type { DisplayMapping } from '$lib/types/search'; | ||
|
||
let prevSuggestMapping: DisplayMapping[] | undefined; | ||
|
||
function getLabelFromMappings( | ||
key: string, | ||
value?: string, | ||
pageMapping?: DisplayMapping[], | ||
suggestMapping?: DisplayMapping[] | ||
) { | ||
const pageLabels = iterateMapping(key, value, pageMapping); | ||
const suggestLabels = iterateMapping(key, value, suggestMapping || prevSuggestMapping); | ||
|
||
const keyLabel = suggestLabels.keyLabel || pageLabels.keyLabel; | ||
const valueLabel = suggestLabels.valueLabel || pageLabels.valueLabel; | ||
// only page data have 'up' links we can use | ||
const removeLink = pageLabels.keyLabel ? pageLabels.removeLink : undefined; | ||
|
||
if (suggestMapping) { | ||
// TODO remove when invalid qualifier no longer result in empty error response | ||
// until when we need to save latest 'successful' suggest mapping | ||
prevSuggestMapping = suggestMapping; | ||
} | ||
|
||
return { keyLabel, valueLabel, removeLink }; | ||
} | ||
|
||
function iterateMapping( | ||
key: string, | ||
value: string | undefined, | ||
mapping: DisplayMapping[] | undefined | null | ||
) { | ||
let keyLabel: string | undefined; | ||
let valueLabel: string | undefined; | ||
let removeLink: string | undefined; | ||
|
||
if (mapping && Array.isArray(mapping)) { | ||
_iterate(mapping); | ||
|
||
function _iterate(m: DisplayMapping[]) { | ||
m.forEach((el) => { | ||
if (el.children) { | ||
_iterate(el.children); | ||
} else if (el.property === key) { | ||
keyLabel = el.label; | ||
const isLinked = !!el.display?.['@id']; | ||
if (isLinked) { | ||
if (el.displayStr) { | ||
// only use atomic ranges for linked values | ||
valueLabel = el.displayStr; | ||
} | ||
// only show remove btn for pills that can't be edited | ||
removeLink = el.up?.['@id']; | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
return { keyLabel, valueLabel, removeLink }; | ||
} | ||
|
||
export default getLabelFromMappings; |
Oops, something went wrong.