Squashed commit of the following: (#5785)

commit 5e8ea099068475fd257d8c172348dc6f3edf9bcf
Author: Matthias Mair <code@mjmair.com>
Date:   Tue Oct 24 09:22:38 2023 +0200

    Update ui_plattform.spec.ts

commit 49da3312beff7fd6837ea741e621df221c445d19
Author: Matthias Mair <code@mjmair.com>
Date:   Tue Oct 24 07:56:25 2023 +0200

    more logging

commit 5337be4c3990051b805a6fce2e79ca4030b4afe5
Author: Matthias Mair <code@mjmair.com>
Date:   Tue Oct 24 07:56:11 2023 +0200

    added filter method for undefined settings that overwrite defaults

commit 5df8a0b3e77cd5dcf04c39ad7638ac845df75e4c
Author: Matthias Mair <code@mjmair.com>
Date:   Tue Oct 24 03:05:06 2023 +0200

    you do not need to string a string

commit 0650d3b3a0132889c2a76de38db38224e974d205
Author: Matthias Mair <code@mjmair.com>
Date:   Tue Oct 24 03:04:34 2023 +0200

    fix things that were borken for no good reason

commit a40dbfd1364cf01465037350184f59d2a2a8afab
Author: Matthias Mair <code@mjmair.com>
Date:   Tue Oct 24 02:39:34 2023 +0200

    reduce unneeded blocking timeouts

commit bf9046a5361ae919e70662e717d6156434b6fe43
Author: Matthias Mair <code@mjmair.com>
Date:   Tue Oct 24 02:34:10 2023 +0200

    catch server fetching errors

commit aa01e67e8c8e789fdf755ac4481e730fe5ea4183
Author: Matthias Mair <code@mjmair.com>
Date:   Tue Oct 24 02:33:29 2023 +0200

    move init as things are now plugged together different

commit 290c33bd3125d50779497d6fc5981d5813b58f5d
Author: Matthias Mair <code@mjmair.com>
Date:   Tue Oct 24 01:49:32 2023 +0200

    do not log a failed automatic login try - why would you?
This commit is contained in:
Matthias Mair 2023-10-25 22:55:52 +02:00 committed by GitHub
parent e13b57669c
commit 02d55b9c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 22 deletions

View File

@ -20,8 +20,8 @@ export const doClassicLogin = async (username: string, password: string) => {
const token = await axios
.get(apiUrl(ApiPaths.user_token), {
auth: { username, password },
baseURL: host.toString(),
timeout: 5000,
baseURL: host,
timeout: 2000,
params: {
name: 'inventree-web-app'
}
@ -120,7 +120,7 @@ export function handleReset(navigate: any, values: { email: string }) {
export function checkLoginState(navigate: any, redirect?: string) {
api
.get(apiUrl(ApiPaths.user_token), {
timeout: 5000,
timeout: 2000,
params: {
name: 'inventree-web-app'
}
@ -140,8 +140,7 @@ export function checkLoginState(navigate: any, redirect?: string) {
navigate('/login');
}
})
.catch((error) => {
console.error('Error fetching login information:', error);
.catch(() => {
navigate('/login');
});
}

View File

@ -25,26 +25,37 @@ export const IS_DEV = import.meta.env.DEV;
export const IS_DEMO = import.meta.env.VITE_DEMO === 'true';
export const IS_DEV_OR_DEMO = IS_DEV || IS_DEMO;
// Filter out any settings that are not defined
let loaded_vals = (window.INVENTREE_SETTINGS || {}) as any;
Object.keys(loaded_vals).forEach((key) => {
if (loaded_vals[key] === undefined) {
delete loaded_vals[key];
// check for empty server list
} else if (key === 'server_list' && loaded_vals[key].length === 0) {
delete loaded_vals[key];
}
});
window.INVENTREE_SETTINGS = {
server_list: {
localhost: {
'mantine-cqj63coxn': {
host: `${window.location.origin}/`,
name: 'Current Server'
},
...(IS_DEV_OR_DEMO
? {
demo: {
'mantine-u56l5jt85': {
host: 'https://demo.inventree.org/',
name: 'InvenTree Demo'
}
}
: {})
},
default_server: IS_DEMO ? 'demo' : 'localhost',
default_server: IS_DEMO ? 'mantine-u56l5jt85' : 'mantine-cqj63coxn',
show_server_selector: IS_DEV_OR_DEMO,
// merge in settings that are already set via django's spa_view or for development
...((window.INVENTREE_SETTINGS || {}) as any)
...loaded_vals
};
if (window.INVENTREE_SETTINGS.sentry_dsn) {

View File

@ -15,9 +15,12 @@ export const useServerApiState = create<ServerApiStateProps>((set, get) => ({
setServer: (newServer: ServerAPIProps) => set({ server: newServer }),
fetchServerApiState: async () => {
// Fetch server data
await api.get(apiUrl(ApiPaths.api_server_info)).then((response) => {
await api
.get(apiUrl(ApiPaths.api_server_info))
.then((response) => {
set({ server: response.data });
});
})
.catch(() => {});
}
}));

View File

@ -32,7 +32,7 @@ export const useUserState = create<UserStateProps>((set, get) => ({
// Fetch user data
await api
.get(apiUrl(ApiPaths.user_me), {
timeout: 5000
timeout: 2000
})
.then((response) => {
const user: UserProps = {

View File

@ -27,10 +27,6 @@ export default function DesktopAppView() {
]);
// Local state initialization
if (Object.keys(hostList).length === 0) {
console.log('Loading default host list');
useLocalState.setState({ hostList: defaultHostList });
}
setApiDefaults();
// Server Session
@ -38,6 +34,11 @@ export default function DesktopAppView() {
const sessionState = useSessionState.getState();
const [token] = sessionState.token ? [sessionState.token] : [null];
useEffect(() => {
if (Object.keys(hostList).length === 0) {
console.log('Loading default host list', defaultHostList);
useLocalState.setState({ hostList: defaultHostList });
}
if (token && !fetchedServerSession) {
setFetchedServerSession(true);
fetchUserState();

View File

@ -11,9 +11,4 @@ test('Basic Platform UI test', async ({ page }) => {
await page.goto('./platform/');
await expect(page).toHaveTitle('InvenTree Demo Server');
await expect(
page.getByRole('heading', {
name: 'Welcome to your Dashboard, Ally Access'
})
).toBeVisible();
});