Replace lerna with turborepo (#2073)

This change allows our ui libraries to be built separately. It is therefore to utilize different build tools for individual projects, as well as using build caches for the local build.

Co-authored-by: Sebastian Sdorra <sebastian.sdorra@cloudogu.com>
Co-authored-by: Matthias Thieroff <matthias.thieroff@cloudogu.com>
This commit is contained in:
Konstantin Schaper
2022-06-22 11:49:26 +02:00
committed by GitHub
parent 77ab43c93b
commit 84f220e5b2
43 changed files with 1216 additions and 2969 deletions

View File

@@ -227,7 +227,7 @@ describe("Test base api hooks", () => {
_links: {}
});
const { result } = renderHook(() => useIndexJsonResource<{}>("spaceships"), {
const { result } = renderHook(() => useIndexJsonResource<Record<string, unknown>>("spaceships"), {
wrapper: createWrapper(undefined, queryClient)
});

View File

@@ -74,6 +74,8 @@ export const useConfigLink = <C extends HalRepresentation>(link: string) => {
});
}
},
// eslint means we should add C to the dependency array, but C is only a type
// eslint-disable-next-line react-hooks/exhaustive-deps
[mutate, data, isReadOnly]
);

View File

@@ -24,14 +24,8 @@
import { apiClient } from "./apiclient";
import { useQuery } from "react-query";
import { ApiResultWithFetching } from "./base";
export type ContentType = {
type: string;
language?: string;
aceMode?: string;
codemirrorMode?: string;
prismMode?: string;
};
import type { ContentType } from "@scm-manager/ui-types";
export type { ContentType } from "@scm-manager/ui-types";
function getContentType(url: string): Promise<ContentType> {
return apiClient.head(url).then((response) => {

View File

@@ -0,0 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import modalEn from "./modal.en";
import modalDe from "./modal.de";
export default {
de: modalDe,
en: modalEn,
} as const;

View File

@@ -0,0 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
import syntaxEn from "./syntax.en";
import syntaxDe from "./syntax.de";
export default {
de: syntaxDe,
en: syntaxEn,
} as const;

View File

@@ -83,9 +83,6 @@ export const useLogin = () => {
);
const login = (username: string, password: string) => {
// grant_type is specified by the oauth standard with the underscore
// so we stick with it, even if eslint does not like it.
// eslint-disable-next-line @typescript-eslint/camelcase
mutate({ cookie: true, grant_type: "password", username, password });
};

View File

@@ -28,6 +28,8 @@ import { apiClient } from "./apiclient";
import { createQueryString } from "./utils";
import { useQueries, useQuery } from "react-query";
import { useEffect, useState } from "react";
import SYNTAX from "./help/search/syntax";
import MODAL from "./help/search/modal";
export type SearchOptions = {
type: string;
@@ -118,36 +120,45 @@ export const useSearch = (query: string, optionParam = defaultSearchOptions): Ap
);
};
const useObserveAsync = <D extends any[], R, E = Error>(fn: (...args: D) => Promise<R>, deps: D) => {
const useObserveAsync = <D extends unknown[], R, E = Error>(fn: (...args: D) => Promise<R>, deps: D) => {
const [data, setData] = useState<R>();
const [isLoading, setLoading] = useState(false);
const [error, setError] = useState<E>();
useEffect(() => {
setLoading(true);
fn(...deps)
.then(setData)
.catch(setError)
.finally(() => setLoading(false));
}, deps);
useEffect(
() => {
setLoading(true);
fn(...deps)
.then(setData)
.catch(setError)
.finally(() => setLoading(false));
},
// eslint-disable-next-line react-hooks/exhaustive-deps
deps
);
return { data, isLoading, error };
};
const supportedLanguages = ["de", "en"];
const getTypedKeys = <K extends string>(input: { readonly [_ in K]: unknown }) => Object.keys(input) as K[];
const pickLang = (language: string) => {
if (!supportedLanguages.includes(language)) {
return "en";
}
return language;
};
const isSupportedLanguage = <T>(input: unknown, supportedLanguages: T[]): input is T =>
supportedLanguages.includes(input as T);
const pickLang = <T>(language: unknown, supportedLanguages: T[], fallback: T): T =>
isSupportedLanguage(language, supportedLanguages) ? language : fallback;
const SUPPORTED_MODAL_LANGUAGES = getTypedKeys(MODAL);
const SUPPORTED_SYNTAX_LANGUAGES = getTypedKeys(SYNTAX);
const FALLBACK_LANGUAGE = "en";
export const useSearchHelpContent = (language: string) =>
useObserveAsync(
(lang) => import(`./help/search/modal.${pickLang(lang)}`).then((module) => module.default),
(lang) => Promise.resolve(MODAL[pickLang(lang, SUPPORTED_MODAL_LANGUAGES, FALLBACK_LANGUAGE)]),
[language]
);
export const useSearchSyntaxContent = (language: string) =>
useObserveAsync(
(lang) => import(`./help/search/syntax.${pickLang(lang)}`).then((module) => module.default),
(lang) => Promise.resolve(SYNTAX[pickLang(lang, SUPPORTED_SYNTAX_LANGUAGES, FALLBACK_LANGUAGE)]),
[language]
);

View File

@@ -73,7 +73,7 @@ export const useSources = (repository: Repository, opts: UseSourcesOptions = Use
}
}, options.refetchPartialInterval);
return () => clearInterval(intervalId);
}, [options.refetchPartialInterval, file]);
}, [options.refetchPartialInterval, file, refetch]);
return {
isLoading,