-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored task sorting to inventory server (#1286)
* refactored task sorting to inventory server * added arrows to table head based on the sortKey and direction --------- Co-authored-by: PeterL <[email protected]> Co-authored-by: Marco <[email protected]>
- Loading branch information
1 parent
50ee218
commit 25a19c4
Showing
3 changed files
with
65 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { Button, Container, Flex, Icon, Input, InputGroup, InputLeftElement, useDisclosure } from '@chakra-ui/react'; | ||
import { omitNullValue, usePagination, Pagination, TaskDefinition, useNotifications } from '@frinx/shared'; | ||
import FeatherIcon from 'feather-icons-react'; | ||
import { orderBy } from 'lodash'; | ||
import { gql, useMutation, useQuery } from 'urql'; | ||
import React, { useMemo, useState } from 'react'; | ||
import AddTaskModal from './add-task-modal'; | ||
|
@@ -14,6 +13,8 @@ import { | |
DeleteTaskMutationVariables, | ||
TaskDefinitionsQuery, | ||
TaskDefinitionsQueryVariables, | ||
TasksOrderByInput, | ||
SortTasksBy, | ||
} from '../../../__generated__/graphql'; | ||
|
||
const taskDefinition: TaskDefinition = { | ||
|
@@ -35,8 +36,15 @@ const taskDefinition: TaskDefinition = { | |
}; | ||
|
||
const TASK_DEFINITIONS_QUERY = gql` | ||
query TaskDefinitions($filter: FilterTaskDefinitionsInput, $before: String, $last: Int, $after: String, $first: Int) { | ||
taskDefinitions(filter: $filter, before: $before, last: $last, after: $after, first: $first) { | ||
query TaskDefinitions( | ||
$filter: FilterTaskDefinitionsInput | ||
$orderBy: TasksOrderByInput | ||
$before: String | ||
$last: Int | ||
$after: String | ||
$first: Int | ||
) { | ||
taskDefinitions(filter: $filter, orderBy: $orderBy, before: $before, last: $last, after: $after, first: $first) { | ||
edges { | ||
node { | ||
id | ||
|
@@ -85,7 +93,7 @@ const CREATE_TASK_DEFINITION_MUTATION = gql` | |
|
||
const TaskList = () => { | ||
const context = useMemo(() => ({ additionalTypenames: ['TaskDefinition'] }), []); | ||
const [sorted, setSorted] = useState(false); | ||
const [orderBy, setOrderBy] = useState<TasksOrderByInput | null>(null); | ||
const [task, setTask] = useState<TaskDefinition>(); | ||
const [keyword, setKeyword] = useState(''); | ||
const [searchTerm, setSearchTerm] = useState(''); | ||
|
@@ -101,6 +109,7 @@ const TaskList = () => { | |
filter: { | ||
keyword, | ||
}, | ||
orderBy, | ||
}, | ||
}); | ||
|
||
|
@@ -118,7 +127,9 @@ const TaskList = () => { | |
CREATE_TASK_DEFINITION_MUTATION, | ||
); | ||
|
||
const sortedTasks = taskDefinitions.sort((a, b) => a.name.localeCompare(b.name)) || [].filter(omitNullValue); | ||
const handleSort = (value: SortTasksBy) => { | ||
setOrderBy({ sortKey: value, direction: orderBy?.direction === 'ASC' ? 'DESC' : 'ASC' }); | ||
}; | ||
|
||
const handleTaskModal = (tsk: TaskDefinition) => { | ||
setTask(tsk); | ||
|
@@ -152,12 +163,6 @@ const TaskList = () => { | |
}); | ||
}; | ||
|
||
const sortArray = (key: string) => { | ||
const sortedArray = sorted ? orderBy(sortedTasks, [key], ['desc']) : orderBy(sortedTasks, [key], ['asc']); | ||
setSorted(!sorted); | ||
return sortedArray; | ||
}; | ||
|
||
const addTask = (tsk: TaskDefinition) => { | ||
if (tsk.name !== '') { | ||
const ownerEmail = tsk.ownerEmail || '[email protected]'; | ||
|
@@ -214,7 +219,7 @@ const TaskList = () => { | |
task={taskDefinition} | ||
/> | ||
{task && <TaskConfigModal isOpen={taskConfigModal.isOpen} onClose={taskConfigModal.onClose} task={task} />} | ||
<Flex marginBottom={8}> | ||
<Flex justify="space-between" gap="20px" marginBottom={8}> | ||
<InputGroup> | ||
<InputLeftElement> | ||
<Icon size={20} as={FeatherIcon} icon="Search" color="grey" /> | ||
|
@@ -226,9 +231,8 @@ const TaskList = () => { | |
background="white" | ||
/> | ||
</InputGroup> | ||
<Flex gap={2}> | ||
<Flex gap={1}> | ||
<Button | ||
marginLeft={4} | ||
colorScheme="blue" | ||
onClick={() => { | ||
setKeyword(searchTerm); | ||
|
@@ -237,7 +241,6 @@ const TaskList = () => { | |
Search | ||
</Button> | ||
<Button | ||
marginLeft={4} | ||
colorScheme="red" | ||
variant="outline" | ||
onClick={() => { | ||
|
@@ -247,17 +250,18 @@ const TaskList = () => { | |
> | ||
Reset | ||
</Button> | ||
<Button marginLeft={4} colorScheme="blue" variant="outline" onClick={addTaskModal.onOpen}> | ||
<Button colorScheme="blue" variant="outline" onClick={addTaskModal.onOpen}> | ||
New | ||
</Button> | ||
</Flex> | ||
</Flex> | ||
|
||
<TaskTable | ||
tasks={sortedTasks} | ||
tasks={taskDefinitions} | ||
onTaskConfigClick={handleTaskModal} | ||
onTaskDelete={handleDeleteTask} | ||
sortArray={sortArray} | ||
onSort={handleSort} | ||
orderBy={orderBy} | ||
/> | ||
{taskData && ( | ||
<Pagination | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters