Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multiproject & storage #38

Merged
merged 58 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 55 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
b6c0291
feat: withAuth with acceptedRoles
manolo-battista Sep 12, 2023
c4ceada
feat: permissions page
manolo-battista Sep 14, 2023
45aef3c
wip: create permission table component and relative components
manolo-battista Sep 18, 2023
5b6d0af
feat: separate PermissionTable for future uses and optimize code
manolo-battista Sep 27, 2023
8791aac
fix: update refLink with link_ref
manolo-battista Oct 4, 2023
32ab74a
feat: Add dropzone component to manage files type
manolo-battista Oct 5, 2023
238e7e7
fix: add toast for missing permission
manolo-battista Oct 16, 2023
1a31d87
fix: control for link_ref.id
manolo-battista Oct 17, 2023
afa586a
feat: storage and formdata
manolo-battista Oct 24, 2023
7a71741
feat: optimize utils and extend types for storage
manolo-battista Oct 24, 2023
2dbdf24
fix: update @arkejs/client and clean code
manolo-battista Oct 24, 2023
390b576
fix: acceptedRoles
manolo-battista Oct 24, 2023
24cce12
chore: add license on ExpandIcon
manolo-battista Oct 24, 2023
76d6891
fix: license on files
manolo-battista Oct 24, 2023
18f2089
feat: multiproject
manolo-battista Oct 24, 2023
ff14106
feat: use project on link
manolo-battista Oct 25, 2023
8d82e7e
feat: Add project modal
manolo-battista Oct 25, 2023
3574831
fix: project on client side
manolo-battista Oct 25, 2023
a3857d6
fix: remove unused code
manolo-battista Oct 25, 2023
5793855
fix: tests
manolo-battista Oct 25, 2023
53b2c9c
feat: move user out of project
manolo-battista Oct 25, 2023
e71f91e
feat: add icons on sidebar and clean code
manolo-battista Oct 26, 2023
1fdcea9
fix: add project
manolo-battista Oct 26, 2023
5819e46
fix: route redirect with push
manolo-battista Oct 26, 2023
f03858f
feat: member page
manolo-battista Oct 26, 2023
2b8f309
feat: members page and hooks
manolo-battista Oct 26, 2023
4578893
feat: use tableUtils to clean code and table requests
manolo-battista Oct 26, 2023
864f4b2
feat: FileDropzone with image
manolo-battista Oct 26, 2023
cf64189
feat: login improvement
manolo-battista Oct 26, 2023
6471eec
feat: improvements on unit page and on table empty state
manolo-battista Oct 26, 2023
b9088a6
feat: table config provider and improvements
manolo-battista Oct 26, 2023
e135fb1
feat: improvements on images and units page
manolo-battista Oct 26, 2023
261d3b2
Merge remote-tracking branch 'origin/main' into feat/multiproject
manolo-battista Oct 26, 2023
33286c8
fix: licenses
manolo-battista Oct 26, 2023
e9c3363
fix: app table config and ID on add project
manolo-battista Oct 27, 2023
8ff9d75
fix: add control on app table config provider
manolo-battista Oct 31, 2023
aadea95
fix: member crud
manolo-battista Oct 31, 2023
f2d758f
feat: auth member improvements
manolo-battista Nov 7, 2023
e9650a7
fix: arke members
manolo-battista Nov 8, 2023
3096bf9
feat: remove duplicated permissions page
manolo-battista Nov 8, 2023
e20e9a3
feat: validations on ID field
manolo-battista Nov 10, 2023
7664ad1
feat: add ID on units table and fix id on form
manolo-battista Nov 13, 2023
b8f128a
fix: crud for file
manolo-battista Nov 13, 2023
be3dff1
chore: lint
manolo-battista Nov 14, 2023
812b622
fix: FileDropzone
manolo-battista Nov 15, 2023
5bfd91b
fix: remove id on edit and add field for field
manolo-battista Nov 17, 2023
6ea9933
feat: improvements on member page
manolo-battista Nov 30, 2023
5eba82e
feat: add ApiToast for client reject response
manolo-battista Nov 30, 2023
96f2a86
fix: remove project on authorize
manolo-battista Nov 30, 2023
89ce772
fix: optimize table config and loading (#39)
ilyichv Dec 1, 2023
a098863
feat: add assigned parameter metadata override (#40)
ilyichv Dec 4, 2023
58de742
fix: table config provider
manolo-battista Dec 13, 2023
946090b
chore: use arke-project env variable for login
manolo-battista Dec 19, 2023
b8fcc32
fix: support prod .env.file
manolo-battista Dec 20, 2023
c196917
feat: add NEXT_MULTIPROJECT to enable multiproject
manolo-battista Jan 8, 2024
6fa14b3
chore: add license and types
manolo-battista Jan 8, 2024
e257fe9
chore: add license
manolo-battista Jan 8, 2024
5fc9977
test: add NEXT_MULTIPROJECT on tests
manolo-battista Jan 8, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
NEXT_PUBLIC_ARKE_SERVER_URL=http://0.0.0.0:4000
NEXT_MULTIPROJECT=false
NEXTAUTH_URL=http://localhost:3100/api/auth
NEXTAUTH_SECRET=your_secret
NEXT_PUBLIC_ARKE_PROJECT=""
41 changes: 22 additions & 19 deletions arke/getClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import { Client, HTTPStatusCode, TToken } from "@arkejs/client";
import { Client, TToken } from "@arkejs/client";
import { GetServerSidePropsContext } from "next";
import { getSession } from "next-auth/react";
import { getToken } from "next-auth/jwt";
import { getCookie } from "cookies-next";
import { getCookieName } from "../utils/auth";
import toast from "react-hot-toast";
import { getCookieName } from "@/utils/auth";
import { NextParsedUrlQuery } from "next/dist/server/request-meta";

const getServerUrl = () => {
if (
Expand All @@ -36,17 +36,23 @@ const getServerUrl = () => {
const getProjectId = (context?: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
}) =>
(process.env.NEXT_PUBLIC_ARKE_PROJECT ||
getCookie("arke_project", {
req: context?.req,
res: context?.res,
})?.toString()) ??
"";
query?: any;
}) => {
const project = context?.query?.project ?? "arke_system";
return (
(project ||
getCookie("arke_project", {
req: context?.req,
res: context?.res,
})?.toString()) ??
""
);
};

export const getClient = (context?: {
req: GetServerSidePropsContext["req"];
res: GetServerSidePropsContext["res"];
query?: NextParsedUrlQuery;
}): Client => {
const serverUrl = getServerUrl();
return new Client({
Expand All @@ -68,16 +74,13 @@ export const getClient = (context?: {
return config;
},
(err) => {
if (err.response) {
if (err.response.status === HTTPStatusCode.InternalServerError) {
toast.error(
`${err.message}: ${err.response.data?.errors?.detail}`
);
}
return Promise.reject(err);
} else {
toast.error(`Something went wrong. The Server is unreachable.`);
if (typeof window !== "undefined") {
const event = new CustomEvent("arke_client_reject", {
detail: err,
});
window.dispatchEvent(event);
}
return Promise.reject(err);
}
);
return api;
Expand Down
8 changes: 6 additions & 2 deletions arke/useClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
* limitations under the License.
*/

import { getClient } from '@/arke/getClient';
import { getClient } from "@/arke/getClient";
import { useRouter } from "next/router";

export default function useClient() {
return getClient();
const { query } = useRouter();
// TODO: fix query type
// @ts-ignore
return getClient({ query });
}
2 changes: 1 addition & 1 deletion components/ApiDocs/ApiDocsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function DocsTabContent({ doc }: { doc: Doc }) {
return (
<div className="api__docs__content">
<h3 className="text-xl">{doc.title}</h3>
<p className="pt-2 pb-4">{doc.description}</p>
<p className="pb-4 pt-2">{doc.description}</p>
<Tabs>
{doc.code.map(({ language }, index) => (
<Tabs.Tab key={index}>
Expand Down
36 changes: 36 additions & 0 deletions components/ApiToast/ApiToast.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ReactNode, useEffect } from "react";
manolo-battista marked this conversation as resolved.
Show resolved Hide resolved
import { HTTPStatusCode } from "@arkejs/client";
import toast from "react-hot-toast";

export default function ApiToast({ children }: { children: ReactNode }) {
useEffect(() => {
window.addEventListener("arke_client_reject", onReject, false);
}, []);

function onReject(event: any) {
const err = event.detail;
try {
if (err.response) {
if (err.response.status === HTTPStatusCode.Forbidden) {
toast.error(
`You have not access on resource. Check your permissions`,
{
id: "permission_error",
}
);
}
if (err.response.status === HTTPStatusCode.InternalServerError) {
toast.error(`${err.message}: ${err.response.data?.errors?.detail}`);
}
return Promise.reject(err);
} else {
toast.error(`Something went wrong. The Server is unreachable.`);
return Promise.reject(err);
}
} catch (e) {
return Promise.reject(err);
}
}

return <div>{children}</div>;
}
18 changes: 10 additions & 8 deletions components/AppFormConfigProvider/AppFormConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

import { ReactNode } from "react";
import { ReactNode, useEffect, useState } from "react";
import { FormConfigProvider as FCProvider } from "@arkejs/form";
import { Autocomplete, Checkbox, Input, Json } from "@arkejs/ui";
import AutocompleteLink from "@/components/AppFormConfigProvider/components/AutocompleteLink";
import Dropzone from "@/components/Dropzone/Dropzone";
import FileDropzone from "@/components/AppFormConfigProvider/components/FileDropzone";

export default function AppFormConfigProvider(props: { children: ReactNode }) {
return (
Expand Down Expand Up @@ -96,12 +96,14 @@ export default function AppFormConfigProvider(props: { children: ReactNode }) {
link: ({ field }: any) =>
field?.link_ref?.id === "arke_file" ? (
<>
<Dropzone
{...field}
onChange={(files) => {
field?.onChange(files?.[0] ?? null);
}}
/>
<FileDropzone {...field} />
{!field.value?.path && (
<Input
{...field}
label=""
helperText="If you already known the file ID use this input"
/>
)}
</>
) : (
<AutocompleteLink {...field} onChange={field.onChange} />
Expand Down
63 changes: 63 additions & 0 deletions components/AppFormConfigProvider/components/FileDropzone.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2023 Arkemis S.r.l.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { useEffect, useState } from "react";
import useClient from "@/arke/useClient";
import Dropzone from "@/components/Dropzone/Dropzone";
import { LinkRef } from "@/types/link";
import { TFile } from "@/types/file";

type FileDropzoneProps = {
link_ref: LinkRef;
onChange: (value: any) => void;
value: TFile;
};

const FileDropzone = (props: FileDropzoneProps) => {
const { onChange } = props;
const client = useClient();
const [value, setValue] = useState<TFile | null>(props.value);

useEffect(() => {
if (value) {
client.unit
// @ts-ignore
// TODO: check value that change
.get("arke_file", value)
.then((res) => {
setValue(res.data.content as TFile);
onChange(res.data.content.id);
});
}
}, []);

return (
<Dropzone
{...props}
value={value as TFile}
onChange={(files) => {
if (files?.length > 0) {
onChange(files?.[0]);
} else {
setValue(null);
onChange(null);
}
}}
/>
);
};

export default FileDropzone;
Loading