feat: added support for sorting and filtering workspaces.

* Also added a LabelFilter interface
This commit is contained in:
Andrey Melnikov
2020-09-28 12:09:16 -07:00
parent 1b7e96cab9
commit 8b4a70d958
5 changed files with 141 additions and 28 deletions

View File

@@ -65,24 +65,11 @@ func typeWorkflow(wf *wfv1.Workflow) (workflow *WorkflowExecution) {
// WorkflowExecutionFilter represents the available ways we can filter WorkflowExecutions
type WorkflowExecutionFilter struct {
Labels []*Label
Phase string //empty string means none
Phase string // empty string means none
}
// applyWorkflowExecutionLabelSelectQuery returns a query builder that adds where statements to filter by labels in the request,
// if there are any
func applyWorkflowExecutionLabelSelectQuery(sb sq.SelectBuilder, filter *WorkflowExecutionFilter) (sq.SelectBuilder, error) {
if len(filter.Labels) == 0 {
return sb, nil
}
labelsJSON, err := LabelsToJSONString(filter.Labels)
if err != nil {
return sb, err
}
sb = sb.Where("we.labels @> ?", labelsJSON)
return sb, nil
func (wf *WorkflowExecutionFilter) GetLabels() []*Label {
return wf.Labels
}
func applyWorkflowExecutionFilter(sb sq.SelectBuilder, request *request.Request) (sq.SelectBuilder, error) {
@@ -95,7 +82,7 @@ func applyWorkflowExecutionFilter(sb sq.SelectBuilder, request *request.Request)
return sb, nil
}
sb, err := applyWorkflowExecutionLabelSelectQuery(sb, &filter)
sb, err := ApplyLabelSelectQuery("we.labels", sb, &filter)
if err != nil {
return sb, err
}