diff --git a/client/src/components/jobs-list-paginated/jobs-list-paginated.component.jsx b/client/src/components/jobs-list-paginated/jobs-list-paginated.component.jsx
index 96701e83a..03885283d 100644
--- a/client/src/components/jobs-list-paginated/jobs-list-paginated.component.jsx
+++ b/client/src/components/jobs-list-paginated/jobs-list-paginated.component.jsx
@@ -3,12 +3,11 @@ import { Button, Input, Table } from "antd";
import queryString from "query-string";
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
-import { Link, useLocation } from "react-router-dom";
+import { Link, useHistory, useLocation } from "react-router-dom";
import CurrencyFormatter from "../../utils/CurrencyFormatter";
import PhoneFormatter from "../../utils/PhoneFormatter";
import { alphaSort } from "../../utils/sorters";
import StartChatButton from "../chat-open-button/chat-open-button.component";
-import { useHistory } from "react-router-dom";
export default function JobsList({ refetch, loading, jobs, total }) {
const search = queryString.parse(useLocation().search);
diff --git a/client/src/components/tech-sider/tech-sider.component.jsx b/client/src/components/tech-sider/tech-sider.component.jsx
index 9c118914a..06e714358 100644
--- a/client/src/components/tech-sider/tech-sider.component.jsx
+++ b/client/src/components/tech-sider/tech-sider.component.jsx
@@ -45,13 +45,6 @@ export function TechSider({ technician, techLogout }) {
>
{t("menus.tech.jobclockin")}
-
+
{
- //setSearchText(e.target.value);
+ onSearch={(value) => {
+ search.search = value;
+ history.push({ search: queryString.stringify(search) });
}}
- //vale={searchText}
enterButton
/>
);
}}
- size='small'
- pagination={{ position: "top" }}
+ size="small"
+ pagination={{
+ position: "top",
+ pageSize: 25,
+ current: parseInt(page || 1),
+ total: total,
+ }}
columns={columns}
- rowKey='id'
+ rowKey="id"
scroll={{ x: true }}
dataSource={vehicles}
onChange={handleTableChange}
diff --git a/client/src/components/vehicles-list/vehicles-list.container.jsx b/client/src/components/vehicles-list/vehicles-list.container.jsx
index 3226b1cb3..c6a0896e5 100644
--- a/client/src/components/vehicles-list/vehicles-list.container.jsx
+++ b/client/src/components/vehicles-list/vehicles-list.container.jsx
@@ -2,18 +2,40 @@ import React from "react";
import VehiclesListComponent from "./vehicles-list.component";
import { useQuery } from "@apollo/react-hooks";
import AlertComponent from "../alert/alert.component";
-import { QUERY_ALL_VEHICLES } from "../../graphql/vehicles.queries";
+import { QUERY_ALL_VEHICLES_PAGINATED } from "../../graphql/vehicles.queries";
+import queryString from "query-string";
+import { useLocation } from "react-router-dom";
export default function VehiclesListContainer() {
- const { loading, error, data, refetch } = useQuery(QUERY_ALL_VEHICLES, {
- fetchPolicy: "network-only"
- });
+ const searchParams = queryString.parse(useLocation().search);
+ const { page, sortcolumn, sortorder, search } = searchParams;
+
+ const { loading, error, data, refetch } = useQuery(
+ QUERY_ALL_VEHICLES_PAGINATED,
+ {
+ variables: {
+ search: search || "",
+ offset: page ? (page - 1) * 25 : 0,
+ limit: 25,
+ order: [
+ {
+ [sortcolumn || "created_at"]: sortorder
+ ? sortorder === "descend"
+ ? "desc"
+ : "asc"
+ : "desc",
+ },
+ ],
+ },
+ }
+ );
if (error) return
;
return (
);
diff --git a/client/src/graphql/vehicles.queries.js b/client/src/graphql/vehicles.queries.js
index 024e65a60..f6afd3e98 100644
--- a/client/src/graphql/vehicles.queries.js
+++ b/client/src/graphql/vehicles.queries.js
@@ -71,6 +71,38 @@ export const QUERY_ALL_VEHICLES = gql`
}
`;
+export const QUERY_ALL_VEHICLES_PAGINATED = gql`
+ query QUERY_ALL_VEHICLES(
+ $search: String
+ $offset: Int
+ $limit: Int
+ $order: [vehicles_order_by!]!
+ ) {
+ search_vehicles(
+ args: { search: $search }
+ offset: $offset
+ limit: $limit
+ order_by: $order
+ ) {
+ id
+ plate_no
+ plate_st
+ v_vin
+ v_model_yr
+ v_model_desc
+ v_make_desc
+ v_color
+ v_bstyle
+ updated_at
+ }
+ search_vehicles_aggregate(args: { search: $search }) {
+ aggregate {
+ count(distinct: true)
+ }
+ }
+ }
+`;
+
export const SEARCH_VEHICLE_BY_VIN = gql`
query SEARCH_VEHICLE_BY_VIN($vin: String!) {
vehicles(where: { v_vin: { _ilike: $vin } }) {
diff --git a/hasura/migrations/1594680139254_run_sql_migration/down.yaml b/hasura/migrations/1594680139254_run_sql_migration/down.yaml
new file mode 100644
index 000000000..fe51488c7
--- /dev/null
+++ b/hasura/migrations/1594680139254_run_sql_migration/down.yaml
@@ -0,0 +1 @@
+[]
diff --git a/hasura/migrations/1594680139254_run_sql_migration/up.yaml b/hasura/migrations/1594680139254_run_sql_migration/up.yaml
new file mode 100644
index 000000000..6c88b4996
--- /dev/null
+++ b/hasura/migrations/1594680139254_run_sql_migration/up.yaml
@@ -0,0 +1,7 @@
+- args:
+ cascade: true
+ read_only: false
+ sql: |-
+ CREATE INDEX idx_vehicles_vin ON vehicles USING GIN (v_vin gin_trgm_ops);
+ CREATE INDEX idx_vehicles_plateno ON vehicles USING GIN (plate_no gin_trgm_ops);
+ type: run_sql
diff --git a/hasura/migrations/1594680221027_run_sql_migration/down.yaml b/hasura/migrations/1594680221027_run_sql_migration/down.yaml
new file mode 100644
index 000000000..fe51488c7
--- /dev/null
+++ b/hasura/migrations/1594680221027_run_sql_migration/down.yaml
@@ -0,0 +1 @@
+[]
diff --git a/hasura/migrations/1594680221027_run_sql_migration/up.yaml b/hasura/migrations/1594680221027_run_sql_migration/up.yaml
new file mode 100644
index 000000000..0750cc6cf
--- /dev/null
+++ b/hasura/migrations/1594680221027_run_sql_migration/up.yaml
@@ -0,0 +1,13 @@
+- args:
+ cascade: true
+ read_only: false
+ sql: "CREATE OR REPLACE FUNCTION public.search_vehicles(search text)\n RETURNS
+ SETOF vehicles\n LANGUAGE plpgsql\n STABLE\nAS $function$\n\nBEGIN\n if search
+ = '' then\n return query select * from vehicles ;\n else \n return query
+ SELECT\n *\nFROM\n vehicles\nWHERE\n search <% (v_vin) OR\n search <% (plate_no);\n
+ \ end if;\n\n\tEND\n$function$;"
+ type: run_sql
+- args:
+ name: search_vehicles
+ schema: public
+ type: track_function
diff --git a/hasura/migrations/1594680369038_update_permission_user_public_table_vehicles/down.yaml b/hasura/migrations/1594680369038_update_permission_user_public_table_vehicles/down.yaml
new file mode 100644
index 000000000..bec9ebae2
--- /dev/null
+++ b/hasura/migrations/1594680369038_update_permission_user_public_table_vehicles/down.yaml
@@ -0,0 +1,50 @@
+- args:
+ role: user
+ table:
+ name: vehicles
+ schema: public
+ type: drop_select_permission
+- args:
+ permission:
+ allow_aggregations: false
+ columns:
+ - v_paint_codes
+ - db_v_code
+ - plate_no
+ - plate_st
+ - trim_color
+ - v_bstyle
+ - v_color
+ - v_cond
+ - v_engine
+ - v_makecode
+ - v_make_desc
+ - v_mldgcode
+ - v_model_desc
+ - v_model_yr
+ - v_options
+ - v_prod_dt
+ - v_stage
+ - v_tone
+ - v_trimcode
+ - v_type
+ - v_vin
+ - created_at
+ - updated_at
+ - id
+ - shopid
+ computed_fields: []
+ filter:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ role: user
+ table:
+ name: vehicles
+ schema: public
+ type: create_select_permission
diff --git a/hasura/migrations/1594680369038_update_permission_user_public_table_vehicles/up.yaml b/hasura/migrations/1594680369038_update_permission_user_public_table_vehicles/up.yaml
new file mode 100644
index 000000000..47038ddc5
--- /dev/null
+++ b/hasura/migrations/1594680369038_update_permission_user_public_table_vehicles/up.yaml
@@ -0,0 +1,50 @@
+- args:
+ role: user
+ table:
+ name: vehicles
+ schema: public
+ type: drop_select_permission
+- args:
+ permission:
+ allow_aggregations: true
+ columns:
+ - v_paint_codes
+ - db_v_code
+ - plate_no
+ - plate_st
+ - trim_color
+ - v_bstyle
+ - v_color
+ - v_cond
+ - v_engine
+ - v_makecode
+ - v_make_desc
+ - v_mldgcode
+ - v_model_desc
+ - v_model_yr
+ - v_options
+ - v_prod_dt
+ - v_stage
+ - v_tone
+ - v_trimcode
+ - v_type
+ - v_vin
+ - created_at
+ - updated_at
+ - id
+ - shopid
+ computed_fields: []
+ filter:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ role: user
+ table:
+ name: vehicles
+ schema: public
+ type: create_select_permission
diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml
index 9393fe9f4..abae684f3 100644
--- a/hasura/migrations/metadata.yaml
+++ b/hasura/migrations/metadata.yaml
@@ -3790,6 +3790,7 @@ tables:
_eq: X-Hasura-User-Id
- active:
_eq: true
+ allow_aggregations: true
update_permissions:
- role: user
permission:
@@ -3985,3 +3986,6 @@ functions:
- function:
schema: public
name: search_payments
+- function:
+ schema: public
+ name: search_vehicles