Skip to content

Commit

Permalink
Remove references to deprectated subscription field (#361)
Browse files Browse the repository at this point in the history
Signed-off-by: James Phillips <[email protected]>
  • Loading branch information
jamesdphillips authored Feb 15, 2021
1 parent db8dc5f commit e4bb310
Show file tree
Hide file tree
Showing 12 changed files with 610 additions and 896 deletions.
4 changes: 1 addition & 3 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ module.exports = {
[
"@babel/preset-env",
{
targets: {
ie: "11",
},
targets: "> 0.5%, not IE 11",
// Disable polyfill transforms.
useBuiltIns: false,
// Do not transform es6 modules, required for webpack "tree shaking".
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"@storybook/react": "^5.3.13",
"@storybook/theming": "^5.3.13",
"@testing-library/react": "^8.0.1",
"@types/autosuggest-highlight": "^3.1.1",
"@types/classnames": "^2.2.7",
"@types/d3-scale": "^2.1.1",
"@types/es6-error": "^4.0.2",
Expand All @@ -79,6 +80,7 @@
"@types/lodash": "^4.14.145",
"@types/mousetrap": "^1.6.3",
"@types/react": "^16.8.19",
"@types/react-autosuggest": "^10.1.1",
"@types/react-dom": "^16.8.4",
"@types/react-router-dom": "^5.1.3",
"@typescript-eslint/eslint-plugin": "^1.9.0",
Expand All @@ -92,6 +94,7 @@
"apollo-link-batch-http": "^1.2.11",
"apollo-link-context": "^1.0.18",
"autoprefixer": "^7.1.2",
"autosuggest-highlight": "^3.1.1",
"aws-sdk": "^2.437.0",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.8.0",
Expand Down Expand Up @@ -158,6 +161,7 @@
"raw-loader": "^0.5.1",
"react": "^16.8.6",
"react-apollo": "^2.5.6",
"react-autosuggest": "^10.1.0",
"react-dom": "^16.8.6",
"react-event-listener": "^0.6.3",
"react-media": "^1.8.0",
Expand All @@ -173,7 +177,7 @@
"ts-jest": "^24.0.2",
"ts-md5": "^1.2.4",
"typeface-roboto": "^0.0.54",
"typescript": "^3.5.1",
"typescript": "^3.9.7",
"uglifyjs-webpack-plugin": "^1.2.5",
"url-loader": "^1.0.1",
"url-search-params-polyfill": "^2.0.3",
Expand Down Expand Up @@ -218,5 +222,5 @@
"graphql-import/**/graphql": "14.4.2",
"serialize-javascript": "3.1.0"
},
"graphQLSchemaRef": "0655e33"
"graphQLSchemaRef": "4fbba86"
}
126 changes: 126 additions & 0 deletions src/lib/component/base/AutoSuggest.tsx
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} />
));
121 changes: 121 additions & 0 deletions src/lib/component/partial/AutosuggestSelectMenu.tsx
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;
42 changes: 25 additions & 17 deletions src/lib/component/partial/ChecksList/ChecksListHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,24 @@ import PropTypes from "prop-types";
import gql from "/vendor/graphql-tag";

import {
SelectMenuItem,
DisclosureMenuItem,
PublishMenuItem,
QueueExecutionMenuItem,
SelectMenuItem,
SilenceMenuItem,
UnpublishMenuItem,
UnsilenceMenuItem,
QueueExecutionMenuItem,
} from "/lib/component/partial/ToolbarMenuItems";

import ListHeader from "/lib/component/partial/ListHeader";
import ListSortSelector from "/lib/component/partial/ListSortSelector";
import { ToolbarSelectOption } from "/lib/component/partial/ToolbarSelect";
import ToolbarMenu from "/lib/component/partial/ToolbarMenu";

import AutosuggestSelectMenu from "/lib/component/partial/AutosuggestSelectMenu";
import MenuController from "/lib/component/controller/MenuController";
import RootRef from "@material-ui/core/RootRef";

import { toggleParam } from "/lib/util/filterParams";

class ChecksListHeader extends React.PureComponent {
Expand All @@ -41,9 +46,7 @@ class ChecksListHeader extends React.PureComponent {
static fragments = {
namespace: gql`
fragment ChecksListHeader_namespace on Namespace {
subscriptions(orderBy: OCCURRENCES, omitEntity: true) {
values(limit: 25)
}
name
}
`,
check: gql`
Expand All @@ -60,7 +63,6 @@ class ChecksListHeader extends React.PureComponent {
renderActions = () => {
const { filters, namespace, onChangeFilters, order } = this.props;

const subscriptions = namespace ? namespace.subscriptions.values : [];
return (
<ToolbarMenu>
<ToolbarMenu.Item key="filter-by-published" visible="if-room">
Expand All @@ -82,18 +84,24 @@ class ChecksListHeader extends React.PureComponent {
</SelectMenuItem>
</ToolbarMenu.Item>
<ToolbarMenu.Item key="filter-by-subscription" visible="if-room">
<SelectMenuItem
title="Subscription"
onChange={toggleParam("subscription", onChangeFilters)}
>
{subscriptions.map(val => (
<ToolbarSelectOption
key={val}
value={val}
selected={val === filters.subscription}
<MenuController
renderMenu={({ anchorEl, close }) => (
<AutosuggestSelectMenu
anchorEl={anchorEl}
onClose={close}
resourceType="subscriptions"
objRef="core/v2/check_config/subscriptions"
onChange={toggleParam("subscription", onChangeFilters)}
namespace={namespace && namespace.name}
/>
))}
</SelectMenuItem>
)}
>
{({ open, ref }) => (
<RootRef rootRef={ref}>
<DisclosureMenuItem onClick={open} title="Subscription" />
</RootRef>
)}
</MenuController>
</ToolbarMenu.Item>
<ToolbarMenu.Item key="sort" visible="if-room">
<ListSortSelector
Expand Down
Loading

0 comments on commit e4bb310

Please sign in to comment.