Link ticket fixes #1

This commit is contained in:
Darren Clarke 2023-10-02 14:22:48 +02:00
parent 1443a61164
commit d9ce2f5883
21 changed files with 617 additions and 583 deletions

View file

@ -17,14 +17,14 @@
"@emotion/react": "^11.11.1",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@fontsource/playfair-display": "^5.0.12",
"@fontsource/playfair-display": "^5.0.13",
"@fontsource/poppins": "^5.0.8",
"@fontsource/roboto": "^5.0.8",
"@mui/icons-material": "^5",
"@mui/lab": "^5.0.0-alpha.146",
"@mui/material": "^5",
"@mui/x-data-grid-pro": "^6.15.0",
"@mui/x-date-pickers-pro": "^6.15.0",
"@mui/x-data-grid-pro": "^6.16.0",
"@mui/x-date-pickers-pro": "^6.16.0",
"@opensearch-project/opensearch": "^2.3.1",
"cryptr": "^6.3.0",
"date-fns": "^2.30.0",
@ -40,7 +40,7 @@
"react-cookie-consent": "^8.0.1",
"react-dom": "18.2.0",
"react-iframe": "^1.8.5",
"react-markdown": "^8.0.7",
"react-markdown": "^9.0.0",
"react-polyglot": "^0.7.2",
"sharp": "^0.32.6",
"swr": "^2.2.4",
@ -49,8 +49,8 @@
},
"devDependencies": {
"@babel/core": "^7.23.0",
"@types/node": "^20.7.0",
"@types/react": "18.2.23",
"@types/node": "^20.8.0",
"@types/react": "18.2.24",
"@types/uuid": "^9.0.4",
"babel-loader": "^9.1.3",
"eslint": "^8.50.0",

View file

@ -25,6 +25,7 @@ import {
Dvr as DvrIcon,
Assessment as AssessmentIcon,
LibraryBooks as LibraryBooksIcon,
School as SchoolIcon,
} from "@mui/icons-material";
import { usePathname } from "next/navigation";
import Link from "next/link";
@ -33,6 +34,7 @@ import LinkLogo from "public/link-logo-small.png";
import { useSession, signOut } from "next-auth/react";
import { getTicketOverviewCountsQuery } from "app/_graphql/getTicketOverviewCountsQuery";
console.log;
const openWidth = 270;
const closedWidth = 100;
@ -163,7 +165,6 @@ interface SidebarProps {
export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
const pathname = usePathname();
const { data: session } = useSession();
console.log({ session });
const username = session?.user?.name || "User";
// @ts-ignore
const roles = session?.user?.roles || [];
@ -436,11 +437,19 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
<MenuItem
name="Knowledge Base"
href="/knowledge"
Icon={LibraryBooksIcon}
Icon={SchoolIcon}
iconSize={20}
selected={pathname.endsWith("/knowledge")}
open={open}
/>
<MenuItem
name="Documentation"
href="/docs"
Icon={LibraryBooksIcon}
iconSize={20}
selected={pathname.endsWith("/docs")}
open={open}
/>
<MenuItem
name="Reporting"
href="/reporting"

View file

@ -27,7 +27,7 @@ export const StyledDataGrid: FC<StyledDataGridProps> = ({
columns,
rows,
onRowClick,
height = "calc(100vh - 20px)",
height = "100%",
selectedRows,
setSelectedRows,
}) => {
@ -43,6 +43,9 @@ export const StyledDataGrid: FC<StyledDataGridProps> = ({
border: 0,
width: "100%",
height,
".MuiDataGrid-row": {
cursor: "pointer",
},
".MuiDataGrid-row:nth-of-type(1n)": {
backgroundColor: "#f3f3f3",
},
@ -66,12 +69,14 @@ export const StyledDataGrid: FC<StyledDataGridProps> = ({
rows={rows}
columns={columns}
density="compact"
hideFooter
pagination
initialState={{
pagination: { paginationModel: { pageSize: 20 } },
}}
pageSizeOptions={[5, 10, 25]}
paginationMode="client"
sx={{ height }}
rowBuffer={30}
checkboxSelection={!!setSelectedRows}
onRowSelectionModelChange={setSelectedRows}
rowSelectionModel={selectedRows}
rowHeight={46}
scrollbarSize={0}
disableVirtualization

View file

@ -0,0 +1,24 @@
"use client";
import { FC } from "react";
import { Grid } from "@mui/material";
import Iframe from "react-iframe";
export const DocsWrapper: FC = () => (
<Grid
container
spacing={0}
sx={{ height: "100%", width: "100%" }}
direction="column"
>
<Grid item sx={{ height: "100vh", width: "100%" }}>
<Iframe
id="docs"
url={"https://digiresilience.org/docs/link/about/"}
width="100%"
height="100%"
frameBorder={0}
/>
</Grid>
</Grid>
);

View file

@ -0,0 +1,10 @@
import { Metadata } from "next";
import { DocsWrapper } from "./_components/DocsWrapper";
export const metadata: Metadata = {
title: "Documentation",
};
export default function Page() {
return <DocsWrapper />;
}

View file

@ -19,24 +19,24 @@ export const TicketList: FC<TicketListProps> = ({ title, tickets }) => {
{
field: "number",
headerName: "Number",
flex: 1,
flex: 0.3,
},
{
field: "title",
headerName: "Title",
flex: 1,
flex: 1.5,
},
{
field: "customer",
headerName: "Sender",
valueGetter: (params) => params.row?.customer?.fullname,
flex: 1,
flex: 0.6,
},
{
field: "group",
headerName: "Group",
valueGetter: (params) => params.row?.group?.name,
flex: 1,
flex: 0.3,
},
];
console.log({ tickets });

View file

@ -14,7 +14,7 @@ export const ZammadOverview: FC<ZammadOverviewProps> = ({ name, id }) => {
const { data: ticketData, error: ticketError }: any = useSWR(
{
document: getTicketsByOverviewQuery,
variables: { overviewId: `gid://zammad/Overview/${id}` },
variables: { overviewId: `gid://zammad/Overview/${id}`, pageSize: 250 },
},
{ refreshInterval: 10000 },
);
@ -23,10 +23,20 @@ export const ZammadOverview: FC<ZammadOverviewProps> = ({ name, id }) => {
const tickets =
ticketData?.ticketsByOverview?.edges.map((edge: any) => edge.node) || [];
const sortedTickets = tickets.sort((a: any, b: any) => {
if (a.internalId < b.internalId) {
return 1;
}
if (a.internalId > b.internalId) {
return -1;
}
return 0;
});
return (
<>
{shouldRender && <TicketList title={name} tickets={tickets} />}
{ticketError && <div>{ticketError.toString()}</div>}
{shouldRender && <TicketList title={name} tickets={sortedTickets} />}
{/*ticketError && <div>{ticketError.toString()}</div>*/}
</>
);
};

View file

@ -33,7 +33,7 @@ export const TicketDetail: FC<TicketDetailProps> = ({ id }) => {
document: getTicketQuery,
variables: { ticketId: `gid://zammad/Ticket/${id}` },
},
{ refreshInterval: 100000 },
{ refreshInterval: 10000 },
);
const { data: ticketArticlesData, error: ticketArticlesError }: any = useSWR(
{

View file

@ -14,6 +14,7 @@ import { MuiChipsInput } from "mui-chips-input";
import useSWR, { useSWRConfig } from "swr";
import { getTicketQuery } from "../../../../../_graphql/getTicketQuery";
import { updateTicketMutation } from "../../../../../_graphql/updateTicketMutation";
import { updateTagsMutation } from "../../../../../_graphql/updateTagsMutation";
import "@chatscope/chat-ui-kit-styles/dist/default/styles.min.css";
interface TicketEditProps {
@ -43,7 +44,7 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
document: getTicketQuery,
variables: { ticketId: `gid://zammad/Ticket/${id}` },
},
{ refreshInterval: 100000 },
{ refreshInterval: 10000 },
);
useEffect(() => {
const ticket = ticketData?.ticket;
@ -59,14 +60,8 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
setSelectedTags(ticket.tags);
}
}, [ticketData, ticketError]);
const updateTicket = async () => {
const input = {
ownerId: `gid://zammad/User/${selectedOwner}`,
priorityId: `gid://zammad/Ticket::Priority/${selectedPriority}`,
stateId: `gid://zammad/Ticket::State/${selectedState}`,
groupId: `gid://zammad/Group/${selectedGroup}`,
// tags: selectedTags,
};
const updateTicket = async (input: any) => {
console.log({ input });
const res = await fetcher({
document: updateTicketMutation,
variables: {
@ -76,6 +71,17 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
});
console.log({ res });
};
const updateTags = async (tags: string[]) => {
console.log({ tags });
const res = await fetcher({
document: updateTagsMutation,
variables: {
objectId: `gid://zammad/Ticket/${id}`,
tags,
},
});
console.log({ res });
};
const shouldRender = ticketData && !ticketError;
return (
@ -88,8 +94,11 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
defaultValue={selectedGroup}
value={selectedGroup}
onChange={(e: any) => {
setSelectedGroup(e.target.value);
updateTicket();
const newGroup = e.target.value;
setSelectedGroup(newGroup);
updateTicket({
groupId: `gid://zammad/Group/${newGroup}`,
});
}}
size="small"
sx={{
@ -109,8 +118,9 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
<Select
value={selectedOwner}
onChange={(e: any) => {
setSelectedOwner(e.target.value);
updateTicket();
const newOwner = e.target.value;
setSelectedOwner(newOwner);
updateTicket({ ownerId: `gid://zammad/User/${newOwner}` });
}}
size="small"
sx={{
@ -130,8 +140,11 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
<Select
value={selectedState}
onChange={(e: any) => {
setSelectedState(e.target.value);
updateTicket();
const newState = e.target.value;
setSelectedState(newState);
updateTicket({
stateId: `gid://zammad/Ticket::State/${newState}`,
});
}}
size="small"
sx={{
@ -151,8 +164,11 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
<Select
value={selectedPriority}
onChange={(e: any) => {
setSelectedPriority(e.target.value);
updateTicket();
const newPriority = e.target.value;
setSelectedPriority(newPriority);
updateTicket({
priorityId: `gid://zammad/Ticket::Priority/${newPriority}`,
});
}}
size="small"
sx={{
@ -175,7 +191,7 @@ export const TicketEdit: FC<TicketEditProps> = ({ id }) => {
value={selectedTags}
onChange={(tags: any) => {
setSelectedTags(tags);
updateTicket();
updateTags(tags);
}}
/>
</Grid>

View file

@ -0,0 +1,12 @@
import { gql } from "graphql-request";
export const updateTagsMutation = gql`
mutation UpdateTags($objectId: ID!, $tags: [String!]!) {
tagAssignmentUpdate(objectId: $objectId, tags: $tags) {
success
errors {
message
field
}
}
}`;

View file

@ -5,6 +5,9 @@ mutation UpdateTicket($ticketId: ID!, $input: TicketUpdateInput!) {
ticketUpdate(ticketId: $ticketId, input: $input) {
ticket {
id
priority {
id
}
}
}
}`;

View file

@ -2,6 +2,11 @@ import { NextResponse } from 'next/server';
import { withAuth, NextRequestWithAuth } from "next-auth/middleware";
const rewriteURL = (request: NextRequestWithAuth, originBaseURL: string, destinationBaseURL: string, headers: any = {}) => {
if (request.nextUrl.pathname.startsWith('/api/v1/reports/sets')) {
console.log(request.nextUrl.searchParams.get("sheet"));
NextResponse.next();
}
const destinationURL = request.url.replace(originBaseURL, destinationBaseURL);
console.log(`Rewriting ${request.url} to ${destinationURL}`);
@ -35,6 +40,7 @@ const checkRewrites = async (request: NextRequestWithAuth) => {
} else if (request.nextUrl.pathname.startsWith('/proxy/api') || request.nextUrl.pathname.startsWith('/proxy/assets')) {
return rewriteURL(request, `${linkBaseURL}/proxy`, zammadURL);
} else if (request.nextUrl.pathname.startsWith('/api/v1') || request.nextUrl.pathname.startsWith('/auth/sso') || request.nextUrl.pathname.startsWith('/mobile')) {
console.log("THIS PATH");
return rewriteURL(request, linkBaseURL, zammadURL, headers);
}
@ -56,8 +62,9 @@ export default withAuth(
const noAuthPaths = ["/login", "/api/v1"];
const parsedURL = new URL(url);
const path = parsedURL.pathname;
console.log({ p: parsedURL.pathname });
if (noAuthPaths.some((p: string) => path.startsWith(p))) {
console.log({ p: parsedURL.pathname, auth: "no" });
return true;
}

View file

@ -15,14 +15,14 @@
"@emotion/react": "^11.11.1",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@fontsource/playfair-display": "^5.0.12",
"@fontsource/playfair-display": "^5.0.13",
"@fontsource/poppins": "^5.0.8",
"@fontsource/roboto": "^5.0.8",
"@mui/icons-material": "^5",
"@mui/lab": "^5.0.0-alpha.146",
"@mui/material": "^5",
"@mui/x-data-grid-pro": "^6.15.0",
"@mui/x-date-pickers-pro": "^6.15.0",
"@mui/x-data-grid-pro": "^6.16.0",
"@mui/x-date-pickers-pro": "^6.16.0",
"cryptr": "^6.3.0",
"date-fns": "^2.30.0",
"graphql-request": "^6.1.0",
@ -32,12 +32,12 @@
"next": "13.5.3",
"next-auth": "^4.23.1",
"ra-data-graphql": "^4.14.3",
"ra-i18n-polyglot": "^4.14.3",
"ra-input-rich-text": "^4.14.3",
"ra-language-english": "^4.14.3",
"ra-i18n-polyglot": "^4.14.4",
"ra-input-rich-text": "^4.14.4",
"ra-language-english": "^4.14.4",
"ra-postgraphile": "^6.1.1",
"react": "18.2.0",
"react-admin": "^4.14.3",
"react-admin": "^4.14.4",
"react-cookie": "^6.1.1",
"react-digit-input": "^2.1.0",
"react-dom": "18.2.0",
@ -52,8 +52,8 @@
},
"devDependencies": {
"@babel/core": "^7.23.0",
"@types/node": "^20.7.0",
"@types/react": "18.2.23",
"@types/node": "^20.8.0",
"@types/react": "18.2.24",
"@types/uuid": "^9.0.4",
"babel-loader": "^9.1.3",
"eslint": "^8.50.0",

View file

@ -22,7 +22,7 @@
"@hapipal/schmervice": "^3.0.0",
"@hapipal/toys": "^4.0.0",
"blipp": "^4.0.2",
"camelcase-keys": "^9.0.0",
"camelcase-keys": "^9.1.0",
"expiry-map": "^2.0.0",
"fluent-ffmpeg": "^2.1.2",
"graphile-migrate": "^1.4.1",
@ -43,13 +43,13 @@
"remeda": "^1.27.0",
"twilio": "^4.18.0",
"typeorm": "^0.3.17",
"@whiskeysockets/baileys": "^6.4.1"
"@whiskeysockets/baileys": "^6.5.0"
},
"devDependencies": {
"@types/long": "^4.0.2",
"@types/node": "*",
"babel-preset-link": "*",
"camelcase-keys": "^9.0.0",
"camelcase-keys": "^9.1.0",
"eslint-config-link": "*",
"jest-config-link": "*",
"nodemon": "^3.0.1",