From fb2dbe87c9cde1933487711356810e1f586c81d1 Mon Sep 17 00:00:00 2001 From: 0x1eef <0x1eef@protonmail.com> Date: Thu, 11 Jan 2024 04:59:52 -0300 Subject: [PATCH] back|frontend: update 'tasks' query to filter by status --- .../lib/twenty-backend/graphql/type/query.rb | 8 +- .../share/twenty-backend/schema.graphql | 2 +- twenty-frontend/Gemfile | 2 +- twenty-frontend/Gemfile.lock | 4 +- twenty-frontend/src/js/components/Tasks.tsx | 4 +- .../src/js/hooks/queries/useTasks.ts | 9 +- twenty-frontend/src/js/types/schema.ts | 109 +++++++++--------- 7 files changed, 69 insertions(+), 69 deletions(-) diff --git a/twenty-backend/lib/twenty-backend/graphql/type/query.rb b/twenty-backend/lib/twenty-backend/graphql/type/query.rb index 07f02fd..610e200 100644 --- a/twenty-backend/lib/twenty-backend/graphql/type/query.rb +++ b/twenty-backend/lib/twenty-backend/graphql/type/query.rb @@ -3,16 +3,18 @@ module Twenty::GraphQL::Type field :find_task, Task, null: true do argument :task_id, Int end - field :tasks, [Task], null: false + field :tasks, [Task], null: false do + argument :status, TaskStatus + end field :projects, [Project], null: false def find_task(task_id:) Twenty::Task.find_by(id: task_id) end - def tasks + def tasks(status:) Twenty::Task - .ready + .where(status:) .order(updated_at: :desc) end diff --git a/twenty-backend/share/twenty-backend/schema.graphql b/twenty-backend/share/twenty-backend/schema.graphql index b139b9c..26dcd19 100644 --- a/twenty-backend/share/twenty-backend/schema.graphql +++ b/twenty-backend/share/twenty-backend/schema.graphql @@ -44,7 +44,7 @@ type Project { type Query { findTask(taskId: Int!): Task projects: [Project!]! - tasks: [Task!]! + tasks(status: TaskStatus!): [Task!]! } type Task { diff --git a/twenty-frontend/Gemfile b/twenty-frontend/Gemfile index 174680c..359ed7b 100644 --- a/twenty-frontend/Gemfile +++ b/twenty-frontend/Gemfile @@ -3,6 +3,6 @@ source "https://rubygems.org" gemspec gem "nanoc", "~> 4.12" gem "nanoc-live", "~> 1.0" -gem "nanoc-webpack.rb", "~> 0.4" +gem "nanoc-webpack.rb", "~> 0.5" gem "sass", "~> 3.7" gem "rainpress", "~> 1.0" diff --git a/twenty-frontend/Gemfile.lock b/twenty-frontend/Gemfile.lock index 28f525b..4d14c1a 100644 --- a/twenty-frontend/Gemfile.lock +++ b/twenty-frontend/Gemfile.lock @@ -75,7 +75,7 @@ GEM listen (~> 3.0) nanoc-cli (~> 4.11, >= 4.11.14) nanoc-core (~> 4.11, >= 4.11.14) - nanoc-webpack.rb (0.4.5) + nanoc-webpack.rb (0.5.5) ryo.rb (~> 0.4) parallel (1.24.0) pastel (0.8.0) @@ -123,7 +123,7 @@ PLATFORMS DEPENDENCIES nanoc (~> 4.12) nanoc-live (~> 1.0) - nanoc-webpack.rb (~> 0.4) + nanoc-webpack.rb (~> 0.5) rainpress (~> 1.0) rake (~> 13.0) sass (~> 3.7) diff --git a/twenty-frontend/src/js/components/Tasks.tsx b/twenty-frontend/src/js/components/Tasks.tsx index ba01ec3..f81bac4 100644 --- a/twenty-frontend/src/js/components/Tasks.tsx +++ b/twenty-frontend/src/js/components/Tasks.tsx @@ -4,12 +4,12 @@ import { useDestroyTask } from "/hooks/mutations/useDestroyTask"; import { TrashIcon, DoneIcon } from "/components/Icons"; import { NavBar } from "/components/NavBar"; import { DateTime } from "luxon"; -import { Task } from "/types/schema"; +import { Task, TaskStatus } from "/types/schema"; import classnames from "classnames"; import { useCompleteTask } from "/hooks/mutations/useCompleteTask"; export function Tasks() { - const { refetch, loading, data } = useTasks(); + const { refetch, loading, data } = useTasks({variables: {status: TaskStatus.Ready}}); const tasks = data?.tasks; const [destroyTask] = useDestroyTask(); const [completeTask] = useCompleteTask(); diff --git a/twenty-frontend/src/js/hooks/queries/useTasks.ts b/twenty-frontend/src/js/hooks/queries/useTasks.ts index c56bb50..fa78446 100644 --- a/twenty-frontend/src/js/hooks/queries/useTasks.ts +++ b/twenty-frontend/src/js/hooks/queries/useTasks.ts @@ -1,8 +1,9 @@ import { useQuery, gql } from "@apollo/client"; +import { Task, TaskStatus } from "/types/schema"; const GQL = gql` - query Query { - tasks { + query Query($status: TaskStatus!) { + tasks(status: $status) { id title status @@ -15,6 +16,6 @@ const GQL = gql` } `; -export function useTasks() { - return useQuery(GQL); +export function useTasks({...rest}) { + return useQuery<{tasks: Task[]}>(GQL, rest); } diff --git a/twenty-frontend/src/js/types/schema.ts b/twenty-frontend/src/js/types/schema.ts index 43ab7fe..c351736 100644 --- a/twenty-frontend/src/js/types/schema.ts +++ b/twenty-frontend/src/js/types/schema.ts @@ -1,123 +1,120 @@ export type Maybe = T | null; export type InputMaybe = Maybe; -export type Exact = { - [K in keyof T]: T[K]; -}; -export type MakeOptional = Omit & { - [SubKey in K]?: Maybe; -}; -export type MakeMaybe = Omit & { - [SubKey in K]: Maybe; -}; -export type MakeEmpty< - T extends { [key: string]: unknown }, - K extends keyof T, -> = { [_ in K]?: never }; -export type Incremental = - | T - | { - [P in keyof T]?: P extends " $fragmentName" | "__typename" ? T[P] : never; - }; +export type Exact = { [K in keyof T]: T[K] }; +export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; +export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; +export type MakeEmpty = { [_ in K]?: never }; +export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { - ID: { input: string; output: string }; - String: { input: string; output: string }; - Boolean: { input: boolean; output: boolean }; - Int: { input: number; output: number }; - Float: { input: number; output: number }; + ID: { input: string; output: string; } + String: { input: string; output: string; } + Boolean: { input: boolean; output: boolean; } + Int: { input: number; output: number; } + Float: { input: number; output: number; } /** An ISO 8601-encoded datetime */ - ISO8601DateTime: { input: any; output: any }; + ISO8601DateTime: { input: any; output: any; } }; /** Autogenerated return type of CompleteTask. */ export type CompleteTaskPayload = { - __typename?: "CompleteTaskPayload"; - errors?: Maybe>; - ok?: Maybe; + __typename?: 'CompleteTaskPayload'; + errors?: Maybe>; + ok?: Maybe; }; /** Autogenerated return type of CreateTask. */ export type CreateTaskPayload = { - __typename?: "CreateTaskPayload"; - errors: Array; + __typename?: 'CreateTaskPayload'; + errors: Array; }; /** Autogenerated return type of DestroyTask. */ export type DestroyTaskPayload = { - __typename?: "DestroyTaskPayload"; - errors?: Maybe>; - ok?: Maybe; + __typename?: 'DestroyTaskPayload'; + errors?: Maybe>; + ok?: Maybe; }; export type Mutation = { - __typename?: "Mutation"; + __typename?: 'Mutation'; completeTask?: Maybe; createTask?: Maybe; destroyTask?: Maybe; updateTask?: Maybe; }; + export type MutationCompleteTaskArgs = { - taskId: Scalars["Int"]["input"]; + taskId: Scalars['Int']['input']; }; + export type MutationCreateTaskArgs = { input: TaskInput; }; + export type MutationDestroyTaskArgs = { - taskId: Scalars["Int"]["input"]; + taskId: Scalars['Int']['input']; }; + export type MutationUpdateTaskArgs = { input: TaskInput; - taskId: Scalars["Int"]["input"]; + taskId: Scalars['Int']['input']; }; export type Project = { - __typename?: "Project"; - color: Scalars["String"]["output"]; - id: Scalars["Int"]["output"]; - name: Scalars["String"]["output"]; - path: Scalars["String"]["output"]; + __typename?: 'Project'; + color: Scalars['String']['output']; + id: Scalars['Int']['output']; + name: Scalars['String']['output']; + path: Scalars['String']['output']; tasks: Array; }; export type Query = { - __typename?: "Query"; + __typename?: 'Query'; findTask?: Maybe; projects: Array; tasks: Array; }; + export type QueryFindTaskArgs = { - taskId: Scalars["Int"]["input"]; + taskId: Scalars['Int']['input']; +}; + + +export type QueryTasksArgs = { + status: TaskStatus; }; export type Task = { - __typename?: "Task"; - content: Scalars["String"]["output"]; - id: Scalars["Int"]["output"]; + __typename?: 'Task'; + content: Scalars['String']['output']; + id: Scalars['Int']['output']; project: Project; status: TaskStatus; - title: Scalars["String"]["output"]; - updatedAt: Scalars["ISO8601DateTime"]["output"]; + title: Scalars['String']['output']; + updatedAt: Scalars['ISO8601DateTime']['output']; }; export type TaskInput = { - content: Scalars["String"]["input"]; - projectId: Scalars["Int"]["input"]; - title: Scalars["String"]["input"]; + content: Scalars['String']['input']; + projectId: Scalars['Int']['input']; + title: Scalars['String']['input']; }; export enum TaskStatus { - Complete = "complete", - InProgress = "in_progress", - Ready = "ready", + Complete = 'complete', + InProgress = 'in_progress', + Ready = 'ready' } /** Autogenerated return type of UpdateTask. */ export type UpdateTaskPayload = { - __typename?: "UpdateTaskPayload"; - errors: Array; + __typename?: 'UpdateTaskPayload'; + errors: Array; };