Skip to content

Commit

Permalink
Added support for filtering by url in ingress routes and displayed co…
Browse files Browse the repository at this point in the history
…unt of rows in ingress routes (#206)
  • Loading branch information
Jayesh Choudhary authored Oct 8, 2020
1 parent fa8f311 commit 677c771
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mission-control",
"version": "0.19.4",
"version": "0.19.5",
"private": true,
"dependencies": {
"@ant-design/icons": "^4.1.0",
Expand Down
43 changes: 42 additions & 1 deletion src/components/ingress-routing/FilterForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DeleteOutlined, PlusOutlined } from "@ant-design/icons";

const { Option } = Select;

const formInitialValues = { services: [], targetHosts: [], requestHosts: [] }
const formInitialValues = { services: [], requestUrls: [], targetHosts: [], requestHosts: [] }

const FilterForm = ({ handleCancel, handleSubmit, serviceNames = [], initialValues = formInitialValues }) => {
const [form] = Form.useForm();
Expand Down Expand Up @@ -40,6 +40,47 @@ const FilterForm = ({ handleCancel, handleSubmit, serviceNames = [], initialValu
{serviceNames.map(val => <Option key={val}>{val}</Option>)}
</Select>
</Form.Item>
<FormItemLabel name="Filter by request URLs" />
<Form.List name="requestUrls">
{(fields, { add, remove }) => {
return (
<div>
{fields.map((field) => (
<Form.Item key={field.key} style={{ marginBottom: 8 }}>
<Form.Item
{...field}
validateTrigger={['onChange', 'onBlur']}
rules={[
{
required: true,
message: "Please input a request URL/prefix",
}
]}
noStyle
>
<Input placeholder="Request URL/prefix" style={{ width: "90%" }} />
</Form.Item>
<DeleteOutlined
style={{ marginLeft: 16 }}
onClick={() => {
remove(field.name);
}}
/>
</Form.Item>
))}
<Form.Item>
<Button onClick={() => {
form.validateFields(fields.map(obj => ["targetHosts", obj.name]))
.then(() => add())
.catch(ex => console.log("Exception", ex))
}}>
<PlusOutlined /> Add request URL
</Button>
</Form.Item>
</div>
);
}}
</Form.List>
<FormItemLabel name="Filter by target hosts" />
<Form.List name="targetHosts">
{(fields, { add, remove }) => {
Expand Down
11 changes: 6 additions & 5 deletions src/pages/routing/overview/Overview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ const calculateRequestURL = (routeType, url) => {
return routeType === "prefix" ? url + "*" : url;
};

const applyFilters = (data, projectId, filters = { services: [], targetHosts: [], requestHosts: [] }) => {
const { services, targetHosts, requestHosts } = filters
const applyFilters = (data, projectId, filters = { services: [], requestUrls: [], targetHosts: [], requestHosts: [] }) => {
const { services, requestUrls, targetHosts, requestHosts } = filters
const serviceHosts = services.map(serviceId => `${serviceId}.${projectId}.svc.cluster.local`)
const dataFilteredByServices = services.length === 0 ? data : data.filter(obj => obj.targets.some(target => serviceHosts.some(host => host === target.host)))
const dataFilteredByTargetHosts = targetHosts.length === 0 ? dataFilteredByServices : dataFilteredByServices.filter(obj => obj.targets.some(target => targetHosts.some(host => host === target.host)))
const dataFilteredByRequestHosts = requestHosts.length === 0 ? dataFilteredByTargetHosts : dataFilteredByTargetHosts.filter(obj => obj.allowedHosts.some(allowedHost => requestHosts.some(host => allowedHost === "*" || allowedHost === host)))
const dataFilteredByRequestUrls = requestUrls.length === 0 ? dataFilteredByServices : dataFilteredByServices.filter(obj => requestUrls.some(url => obj.url.includes(url)))
const dataFilteredByTargetHosts = targetHosts.length === 0 ? dataFilteredByRequestUrls : dataFilteredByRequestUrls.filter(obj => obj.targets.some(target => targetHosts.some(host => host === target.host)))
const dataFilteredByRequestHosts = requestHosts.length === 0 ? dataFilteredByTargetHosts : dataFilteredByTargetHosts.filter(obj => !obj.allowedHosts || !obj.allowedHosts.length || obj.allowedHosts.some(allowedHost => requestHosts.some(host => allowedHost === "*" || allowedHost === host)))
return dataFilteredByRequestHosts
}

Expand Down Expand Up @@ -223,7 +224,7 @@ function RoutingOverview() {
justifyContent: "space-between"
}}
>
Ingress Routing rules
Ingress routes {filteredData.length ? `(${filteredData.length})` : ""}
<span>
<Space>
<Button onClick={() => setFilterModalVisible(true)}>
Expand Down

0 comments on commit 677c771

Please sign in to comment.