-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into change/401-remove-legacy-plugins
- Loading branch information
Showing
85 changed files
with
14,269 additions
and
868 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
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
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
68 changes: 47 additions & 21 deletions
68
plugins/main/public/components/search-bar/query-language/index.ts
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,32 +1,58 @@ | ||
import { suggestItem } from '../../wz-search-bar'; | ||
import { AQL } from './aql'; | ||
import { WQL } from './wql'; | ||
|
||
type SearchBarQueryLanguage = { | ||
description: string; | ||
documentationLink?: string; | ||
interface SearchBarProps { | ||
suggestions: suggestItem[]; | ||
onItemClick: (currentInput: string) => (item: suggestItem) => void; | ||
prepend?: React.ReactNode; | ||
disableFocusTrap?: boolean; | ||
isInvalid?: boolean; | ||
onKeyPress?: (event: React.KeyboardEvent<HTMLInputElement>) => void; | ||
} | ||
|
||
interface SearchBarQueryLanguage { | ||
id: string; | ||
label: string; | ||
description: string; | ||
documentationLink?: string; | ||
getConfiguration?: () => any; | ||
run: (input: string | undefined, params: any) => Promise<{ | ||
searchBarProps: any, | ||
run: ( | ||
input: string | undefined, | ||
params: any, | ||
) => Promise<{ | ||
filterButtons?: React.ReactElement | null; | ||
searchBarProps: SearchBarProps; | ||
output: { | ||
language: string, | ||
unifiedQuery: string, | ||
query: string | ||
} | ||
language: string; | ||
unifiedQuery?: string; | ||
apiQuery?: { | ||
q: string; | ||
}; | ||
query: string; | ||
}; | ||
}>; | ||
transformInput: (unifiedQuery: string, options: {configuration: any, parameters: any}) => string; | ||
}; | ||
transformInput?: ( | ||
unifiedQuery: string, | ||
options: { configuration: any; parameters: any }, | ||
) => string; | ||
transformUQLToQL?: (unifiedQuery: string) => string; | ||
} | ||
|
||
// Register the query languages | ||
export const searchBarQueryLanguages: { | ||
[key: string]: SearchBarQueryLanguage; | ||
} = [AQL, WQL].reduce((accum, item) => { | ||
if (accum[item.id]) { | ||
throw new Error(`Query language with id: ${item.id} already registered.`); | ||
function initializeSearchBarQueryLanguages() { | ||
const languages = [AQL, WQL]; | ||
const result: Record<string, SearchBarQueryLanguage> = {}; | ||
|
||
for (const item of languages) { | ||
if (result[item.id]) { | ||
throw new Error(`Query language with id: ${item.id} already registered.`); | ||
} | ||
|
||
result[item.id] = item; | ||
} | ||
return { | ||
...accum, | ||
[item.id]: item, | ||
}; | ||
}, {}); | ||
|
||
return result; | ||
} | ||
|
||
export const searchBarQueryLanguages = initializeSearchBarQueryLanguages(); |
Oops, something went wrong.