Skip to content

Commit

Permalink
updated workflow list to sort by name (#332)
Browse files Browse the repository at this point in the history
* updated workflow list to sort by name

* lint fix

* use shared sort direction type

---------

Co-authored-by: PeterL <[email protected]>
Co-authored-by: Martin Sottnik <[email protected]>
  • Loading branch information
3 people authored Aug 4, 2023
1 parent 727da25 commit 878c705
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 10 deletions.
18 changes: 17 additions & 1 deletion src/schema/api.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,14 @@ type Query {
uniconfigShellSession: String
workflowInstanceDetail(shouldIncludeTasks: Boolean, workflowId: String!): WorkflowInstanceDetail
workflowLabels: [String!]!
workflows(after: String, before: String, filter: FilterWorkflowsInput, first: Int, last: Int): WorkflowConnection!
workflows(
after: String
before: String
filter: FilterWorkflowsInput
first: Int
last: Int
orderBy: WorkflowsOrderByInput!
): WorkflowConnection!
zones(after: String, before: String, first: Int, last: Int): ZonesConnection!
}

Expand Down Expand Up @@ -1072,6 +1079,10 @@ enum SortPollsDirection {
desc
}

enum SortWorkflowsBy {
name
}

input StartWorkflowRequestInput {
workflow: ExecuteNewWorkflowInput!
workflowDefinition: WorkflowDefinitionInput
Expand Down Expand Up @@ -1360,6 +1371,11 @@ enum WorkflowTaskType {
WAIT
}

input WorkflowsOrderByInput {
direction: SortDirection!
sortKey: SortWorkflowsBy!
}

type Zone implements Node {
createdAt: String!
id: ID!
Expand Down
6 changes: 1 addition & 5 deletions src/schema/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { CSVParserToPromise, CSVValuesToJSON, isHeaderValid } from '../helpers/i
import { getUniconfigURL } from '../helpers/zone.helpers';
import { sshClient } from '../uniconfig-shell';
import { Blueprint } from './blueprint';
import { Node, PageInfo, PaginationConnectionArgs } from './global-types';
import { Node, PageInfo, PaginationConnectionArgs, SortDirection } from './global-types';
import { LabelConnection } from './label';
import { Location } from './location';
import { Zone } from './zone';
Expand Down Expand Up @@ -177,10 +177,6 @@ export const SortDeviceBy = enumType({
name: 'SortDeviceBy',
members: ['NAME', 'CREATED_AT'],
});
export const SortDirection = enumType({
name: 'SortDirection',
members: ['ASC', 'DESC'],
});
export const DeviceOrderByInput = inputObjectType({
name: 'DeviceOrderByInput',
definition: (t) => {
Expand Down
7 changes: 6 additions & 1 deletion src/schema/global-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import countries from 'i18n-iso-countries';
import { extendType, idArg, intArg, interfaceType, nonNull, objectType, stringArg } from 'nexus';
import { enumType, extendType, idArg, intArg, interfaceType, nonNull, objectType, stringArg } from 'nexus';
import config from '../config';
import conductorAPI from '../external-api/conductor';
import { fromGraphId, getType } from '../helpers/id-helper';
Expand Down Expand Up @@ -180,3 +180,8 @@ export const IsOkResponse = objectType({
t.nonNull.boolean('isOk');
},
});

export const SortDirection = enumType({
name: 'SortDirection',
members: ['ASC', 'DESC'],
});
7 changes: 7 additions & 0 deletions src/schema/nexus-typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ export interface NexusGenInputs {
updatedAt?: string | null; // String
version?: number | null; // Int
};
WorkflowsOrderByInput: {
// input type
direction: NexusGenEnums['SortDirection']; // SortDirection!
sortKey: NexusGenEnums['SortWorkflowsBy']; // SortWorkflowsBy!
};
}

export interface NexusGenEnums {
Expand Down Expand Up @@ -460,6 +465,7 @@ export interface NexusGenEnums {
SortExecutedWorkflowsDirection: 'asc' | 'desc';
SortPollsBy: 'lastPollTime' | 'queueName' | 'workerId';
SortPollsDirection: 'asc' | 'desc';
SortWorkflowsBy: 'name';
TaskTimeoutPolicy: 'ALERT_ONLY' | 'RETRY' | 'TIME_OUT_WF';
TimeoutPolicy: 'ALERT_ONLY' | 'TIME_OUT_WF';
WorkflowTaskType:
Expand Down Expand Up @@ -2931,6 +2937,7 @@ export interface NexusGenArgTypes {
filter?: NexusGenInputs['FilterWorkflowsInput'] | null; // FilterWorkflowsInput
first?: number | null; // Int
last?: number | null; // Int
orderBy: NexusGenInputs['WorkflowsOrderByInput']; // WorkflowsOrderByInput!
};
zones: {
// args
Expand Down
26 changes: 23 additions & 3 deletions src/schema/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import config from '../config';
import { WorkflowDetailInput } from '../external-api/conductor-network-types';
import { fromGraphId, toGraphId } from '../helpers/id-helper';
import getLogger from '../get-logger';
import { IsOkResponse, Node, PageInfo, PaginationConnectionArgs } from './global-types';
import { IsOkResponse, Node, PageInfo, PaginationConnectionArgs, SortDirection } from './global-types';
import { TaskInput, ExecutedWorkflowTask } from './task';
import {
convertToApiOutputParameters,
Expand Down Expand Up @@ -146,6 +146,19 @@ export const FilterWorkflowsInput = inputObjectType({
},
});

export const SortWorkflowsBy = enumType({
name: 'SortWorkflowsBy',
members: ['name'],
});

export const WorkflowsOrderByInput = inputObjectType({
name: 'WorkflowsOrderByInput',
definition: (t) => {
t.nonNull.field('sortKey', { type: SortWorkflowsBy });
t.nonNull.field('direction', { type: SortDirection });
},
});

export const WorkflowsQuery = extendType({
type: 'Query',
definition: (t) => {
Expand All @@ -154,15 +167,22 @@ export const WorkflowsQuery = extendType({
args: {
...PaginationConnectionArgs,
filter: FilterWorkflowsInput,
orderBy: nonNull(WorkflowsOrderByInput),
},
resolve: async (_, args, { conductorAPI }) => {
const { filter, ...paginationArgs } = args;
const { filter, orderBy: orderingArgs, ...paginationArgs } = args;
const workflows = await conductorAPI.getWorkflowMetadata(config.conductorApiURL);

const filteredWorkflows =
filter?.labels || filter?.keyword ? getFilteredWorkflows(workflows, filter) : workflows;

const workflowsWithId = filteredWorkflows.map((w) => ({
const orderedData = orderBy(
filteredWorkflows,
[orderingArgs.sortKey],
[orderingArgs.direction === 'ASC' ? 'asc' : 'desc'],
);

const workflowsWithId = orderedData.map((w) => ({
...w,
id: w.name,
}));
Expand Down

0 comments on commit 878c705

Please sign in to comment.