-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove references to deprectated subscription field (#361)
Signed-off-by: James Phillips <[email protected]>
- Loading branch information
1 parent
db8dc5f
commit e4bb310
Showing
12 changed files
with
610 additions
and
896 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import React from "react"; | ||
|
||
import { makeStyles } from "@material-ui/core/styles"; | ||
import match from "autosuggest-highlight/match"; | ||
import parse from "autosuggest-highlight/parse"; | ||
|
||
import MenuItem from "@material-ui/core/MenuItem"; | ||
import Paper from "@material-ui/core/Paper"; | ||
import ReactAutosuggest, { | ||
AutosuggestProps as ReactAutosuggestProps, | ||
} from "react-autosuggest"; | ||
|
||
interface RenderSuggestionOpts<T> { | ||
query: string; | ||
isHighlighted: boolean; | ||
} | ||
|
||
export function defaultRenderSuggestion<T>( | ||
suggestion: T, | ||
{ query, isHighlighted }: RenderSuggestionOpts<T>, | ||
) { | ||
const matches = match(suggestion as any, query); | ||
const parts = parse(suggestion as any, matches); | ||
|
||
return ( | ||
<MenuItem | ||
selected={isHighlighted} | ||
component="div" | ||
onMouseDown={(e: any) => e.preventDefault()} // prevent the click causing the input to be blurred | ||
> | ||
<div> | ||
{parts.map((part, idx) => { | ||
return part.highlight ? ( | ||
<span key={String(idx)} style={{ fontWeight: 800 }}> | ||
{part.text} | ||
</span> | ||
) : ( | ||
<React.Fragment key={String(idx)}>{part.text}</React.Fragment> | ||
); | ||
})} | ||
</div> | ||
</MenuItem> | ||
); | ||
} | ||
|
||
interface AutosuggestDefeaultRenderSuggestionsContainerProps { | ||
containerProps: any; | ||
children: React.ReactNode; | ||
} | ||
|
||
export const defaultRenderSuggestionsContainer = ({ | ||
containerProps, | ||
children, | ||
}: AutosuggestDefeaultRenderSuggestionsContainerProps) => { | ||
return ( | ||
<Paper {...containerProps} square> | ||
{children} | ||
</Paper> | ||
); | ||
}; | ||
|
||
const useStyles = makeStyles( | ||
(theme) => ({ | ||
container: { | ||
flexGrow: 1, | ||
position: "relative", | ||
width: "100%", | ||
//marginRight: theme.spacing(), | ||
}, | ||
suggestionsContainerOpen: { | ||
position: "absolute", | ||
marginTop: theme.spacing(), | ||
marginBottom: theme.spacing(3), | ||
left: 0, | ||
right: 0, | ||
zIndex: theme.zIndex.appBar, | ||
}, | ||
suggestion: { | ||
display: "block", | ||
}, | ||
suggestionsList: { | ||
margin: 0, | ||
padding: 0, | ||
listStyleType: "none", | ||
}, | ||
textField: { | ||
width: "100%", | ||
}, | ||
}), | ||
{ | ||
name: "Autosuggest", | ||
}, | ||
); | ||
|
||
interface AutoSuggestPropsBase { | ||
forwardRef: React.Ref<any>; | ||
} | ||
|
||
type AutosuggestProps<V, S> = ReactAutosuggestProps<V, S> & | ||
AutoSuggestPropsBase; | ||
|
||
const Autosuggest = <V, S>({ | ||
onSuggestionsClearRequested = () => {}, | ||
renderSuggestion = defaultRenderSuggestion, | ||
renderSuggestionsContainer = defaultRenderSuggestionsContainer, | ||
forwardRef, | ||
...props | ||
}: AutosuggestProps<V, S>) => { | ||
const classes = useStyles(); | ||
|
||
return ( | ||
<ReactAutosuggest | ||
theme={classes} | ||
onSuggestionsClearRequested={onSuggestionsClearRequested} | ||
renderSuggestion={renderSuggestion} | ||
renderSuggestionsContainer={renderSuggestionsContainer} | ||
{...props} | ||
ref={forwardRef} | ||
/> | ||
); | ||
}; | ||
|
||
// eslint-disable-next-line react/display-name | ||
export default React.forwardRef((props: any, ref: React.Ref<any>) => ( | ||
<Autosuggest forwardRef={ref} {...props} /> | ||
)); |
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,121 @@ | ||
import React from "react"; | ||
|
||
import { defaultRenderSuggestion } from "/lib/component/base/AutoSuggest"; | ||
import Autosuggest from "react-autosuggest"; | ||
import Divider from "@material-ui/core/Divider"; | ||
import Input from "@material-ui/core/InputBase"; | ||
import List from "@material-ui/core/List"; | ||
import ListItem from "@material-ui/core/ListItem"; | ||
import Popover from "@material-ui/core/Popover"; | ||
import Typography from "@material-ui/core/Typography"; | ||
|
||
import useAutosuggest from "/lib/component/util/useAutosuggest"; | ||
|
||
interface Props { | ||
anchorEl?: Element; | ||
|
||
open?: boolean; | ||
onChange?: (_: string) => void; | ||
onClose?: () => void; | ||
|
||
resourceType?: React.ReactNode; | ||
namespace: string; | ||
objRef: string; | ||
order?: "ALPHA_DESC" | "ALPHA_ASC" | "FREQUENCY"; | ||
limit?: number; | ||
delay?: number; | ||
} | ||
|
||
const AutosuggestionSelectMenu: React.FC<Props> = ({ | ||
anchorEl, | ||
open = true, | ||
onChange = () => false, | ||
onClose = () => false, | ||
|
||
resourceType = "resources", | ||
namespace, | ||
objRef, | ||
order = "ALPHA_DESC", | ||
limit = 20, | ||
delay = 350, | ||
}) => { | ||
const [filter, setFilter] = React.useState(""); | ||
|
||
const suggestions = useAutosuggest({ | ||
namespace, | ||
ref: objRef, | ||
order, | ||
limit, | ||
q: filter, | ||
delay, | ||
}); | ||
|
||
return ( | ||
<Popover | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={onClose} | ||
anchorOrigin={{ | ||
vertical: "bottom", | ||
horizontal: "right", | ||
}} | ||
transformOrigin={{ | ||
vertical: "top", | ||
horizontal: "right", | ||
}} | ||
PaperProps={{ | ||
style: { | ||
minWidth: 320, | ||
maxWidth: 480, | ||
maxHeight: 480, | ||
}, | ||
}} | ||
> | ||
<List> | ||
<Autosuggest | ||
alwaysRenderSuggestions | ||
focusInputOnSuggestionClick | ||
getSuggestionValue={(suggestion: string) => suggestion} | ||
inputProps={{ | ||
autoFocus: true, | ||
placeholder: `filter ${resourceType}`, | ||
onChange: (ev) => { | ||
ev.preventDefault(); | ||
setFilter(ev.currentTarget.value || ""); | ||
}, | ||
value: filter, | ||
}} | ||
onSuggestionsFetchRequested={() => true} | ||
onSuggestionSelected={(_: any, { suggestion }: any) => { | ||
onChange(suggestion); | ||
onClose(); | ||
}} | ||
renderInputComponent={(props: any) => ( | ||
<ListItem> | ||
<Input fullWidth {...props} /> | ||
</ListItem> | ||
)} | ||
renderSuggestionsContainer={({ containerProps, children }) => ( | ||
<div {...containerProps}> | ||
<Divider /> | ||
{children ? ( | ||
children | ||
) : ( | ||
<ListItem> | ||
<Typography color="textSecondary"> | ||
No {resourceType} found. | ||
</Typography> | ||
</ListItem> | ||
)} | ||
</div> | ||
)} | ||
renderSuggestion={defaultRenderSuggestion} | ||
shouldRenderSuggestions={() => true} | ||
suggestions={suggestions} | ||
/> | ||
</List> | ||
</Popover> | ||
); | ||
}; | ||
|
||
export default AutosuggestionSelectMenu; |
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
Oops, something went wrong.