Skip to content

Commit

Permalink
feat: Allow filter by status (#872)
Browse files Browse the repository at this point in the history
Add status JobOption to filter from ui and API
  • Loading branch information
Victor Castell authored Dec 19, 2020
1 parent 360163b commit b4da936
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 74 deletions.
13 changes: 5 additions & 8 deletions dkron/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,23 +165,20 @@ func (h *HTTPTransport) indexHandler(c *gin.Context) {

func (h *HTTPTransport) jobsHandler(c *gin.Context) {
metadata := c.QueryMap("metadata")
sort, ok := c.GetQuery("_sort")
if !ok || sort == "id" {
sort := c.DefaultQuery("_sort", "id")
if sort == "id" {
sort = "name"
}
order, ok := c.GetQuery("_order")
if !ok {
order = "ASC"
}

q, _ := c.GetQuery("q")
order := c.DefaultQuery("_order", "ASC")
q := c.Query("q")

jobs, err := h.agent.Store.GetJobs(
&JobOptions{
Metadata: metadata,
Sort: sort,
Order: order,
Query: q,
Status: c.Query("status"),
},
)
if err != nil {
Expand Down
130 changes: 65 additions & 65 deletions dkron/assets_ui/assets_vfsdata.go

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion dkron/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type JobOptions struct {
Sort string
Order string
Query string
Status string
}

type kv struct {
Expand Down Expand Up @@ -316,7 +317,9 @@ func (s *Store) GetJobs(options *JobOptions) ([]*Job, error) {

if options == nil ||
(options.Metadata == nil || len(options.Metadata) == 0 || s.jobHasMetadata(job, options.Metadata)) &&
(options.Query == "" || strings.Contains(job.Name, options.Query)) {
(options.Query == "" || strings.Contains(job.Name, options.Query)) &&
(options.Status == "" || job.Status == options.Status) {

jobs = append(jobs, job)
}
return true
Expand Down
5 changes: 5 additions & 0 deletions ui/src/jobs/JobList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import {
Filter,
TextInput,
List,
SelectInput
} from 'react-admin';
import ToggleButton from "./ToggleButton"
import RunButton from "./RunButton"

const PostFilter = (props: any) => (
<Filter {...props}>
<TextInput label="Search" source="q" alwaysOn />
<SelectInput source="status" choices={[
{ id: 'success', name: 'Success' },
{ id: 'failed', name: 'Failed' },
]} />
</Filter>
);

Expand Down

0 comments on commit b4da936

Please sign in to comment.