Skip to content

Commit

Permalink
Fix s3 releated features always shown when user not logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
garronej committed Dec 2, 2024
1 parent 5e82938 commit deb1880
Show file tree
Hide file tree
Showing 14 changed files with 143 additions and 2 deletions.
6 changes: 5 additions & 1 deletion web/src/core/usecases/fileExplorer/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { type State, name } from "./state";
import { createSelector } from "clean-architecture";
import * as userConfigs from "core/usecases/userConfigs";
import * as s3ConfigManagement from "core/usecases/s3ConfigManagement";
import * as deploymentRegionManagement from "core/usecases/deploymentRegionManagement";
import { assert } from "tsafe/assert";
import * as userAuthentication from "core/usecases/userAuthentication";
import { id } from "tsafe/id";
Expand Down Expand Up @@ -338,7 +339,10 @@ const isFileExplorerEnabled = (rootState: RootState) => {
userAuthentication.selectors.authenticationState(rootState);

if (!isUserLoggedIn) {
return true;
const { s3Configs } =
deploymentRegionManagement.selectors.currentDeploymentRegion(rootState);

return s3Configs.some(s3Config => s3Config.sts.url !== undefined);
} else {
return (
s3ConfigManagement.selectors
Expand Down
7 changes: 7 additions & 0 deletions web/src/ui/i18n/resources/de.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ export const translations: Translations<"de"> = {
</>
)
},
MyFilesDisabledDialog: {
"dialog title": "Kein S3-Server konfiguriert",
"dialog body":
"Für diese Instanz ist kein S3-Server konfiguriert. Sie können jedoch manuell einen hinzufügen, um den S3-Dateiexplorer zu aktivieren.",
cancel: "Abbrechen",
"go to settings": "Zu den Einstellungen gehen"
},
ShareDialog: {
title: "Ihre Daten teilen",
close: "Schließen",
Expand Down
7 changes: 7 additions & 0 deletions web/src/ui/i18n/resources/en.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,13 @@ export const translations: Translations<"en"> = {
</>
)
},
MyFilesDisabledDialog: {
"dialog title": "No S3 server configured",
"dialog body":
"There's no S3 server configured for this instance. But you can add one manually for enabling the S3 file explorer.",
cancel: "Cancel",
"go to settings": "Go to settings"
},
ShareDialog: {
title: "Share your data",
close: "Close",
Expand Down
7 changes: 7 additions & 0 deletions web/src/ui/i18n/resources/es.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ export const translations: Translations<"en"> = {
</>
)
},
MyFilesDisabledDialog: {
"dialog title": "No hay servidor S3 configurado",
"dialog body":
"No hay ningún servidor S3 configurado para esta instancia. Pero puedes agregar uno manualmente para habilitar el explorador de archivos S3.",
cancel: "Cancelar",
"go to settings": "Ir a configuración"
},
ShareDialog: {
title: "Compartir tus datos",
close: "Cerrar",
Expand Down
7 changes: 7 additions & 0 deletions web/src/ui/i18n/resources/fi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,13 @@ export const translations: Translations<"fi"> = {
</>
)
},
MyFilesDisabledDialog: {
"dialog title": "S3-palvelinta ei ole määritetty",
"dialog body":
"Tälle instanssille ei ole määritetty S3-palvelinta. Voit kuitenkin lisätä sellaisen manuaalisesti ottaaksesi käyttöön S3-tiedostonhallinnan.",
cancel: "Peruuta",
"go to settings": "Siirry asetuksiin"
},
ShareDialog: {
title: "Jaa tietosi",
close: "Sulje",
Expand Down
7 changes: 7 additions & 0 deletions web/src/ui/i18n/resources/fr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ export const translations: Translations<"fr"> = {
</>
)
},
MyFilesDisabledDialog: {
"dialog title": "Aucun serveur S3 configuré",
"dialog body":
"Il n'y a aucun serveur S3 configuré pour cette instance. Mais vous pouvez en ajouter un manuellement pour activer l'explorateur de fichiers S3.",
cancel: "Annuler",
"go to settings": "Aller aux paramètres"
},
ShareDialog: {
title: "Partager vos données",
close: "Fermer",
Expand Down
7 changes: 7 additions & 0 deletions web/src/ui/i18n/resources/it.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ export const translations: Translations<"it"> = {
</>
)
},
MyFilesDisabledDialog: {
"dialog title": "Nessun server S3 configurato",
"dialog body":
"Non è stato configurato nessun server S3 per questa istanza. Tuttavia, è possibile aggiungerne uno manualmente per abilitare l'esploratore file S3.",
cancel: "Annulla",
"go to settings": "Vai alle impostazioni"
},
ShareDialog: {
title: "Condividi i tuoi dati",
close: "Chiudi",
Expand Down
7 changes: 7 additions & 0 deletions web/src/ui/i18n/resources/nl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ export const translations: Translations<"nl"> = {
</>
)
},
MyFilesDisabledDialog: {
"dialog title": "Geen S3-server geconfigureerd",
"dialog body":
"Er is geen S3-server geconfigureerd voor deze instantie. Je kunt er echter handmatig een toevoegen om de S3-bestandsverkenner in te schakelen.",
cancel: "Annuleren",
"go to settings": "Ga naar instellingen"
},
ShareDialog: {
title: "Deel je gegevens",
close: "Sluiten",
Expand Down
7 changes: 7 additions & 0 deletions web/src/ui/i18n/resources/no.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,13 @@ export const translations: Translations<"no"> = {
</>
)
},
MyFilesDisabledDialog: {
"dialog title": "Ingen S3-server konfigurert",
"dialog body":
"Det er ingen S3-server konfigurert for denne instansen. Men du kan legge til en manuelt for å aktivere S3-filutforskeren.",
cancel: "Avbryt",
"go to settings": "Gå til innstillinger"
},
ShareDialog: {
title: "Del dataene dine",
close: "Lukk",
Expand Down
6 changes: 6 additions & 0 deletions web/src/ui/i18n/resources/zh-CN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ export const translations: Translations<"zh-CN"> = {
</>
)
},
MyFilesDisabledDialog: {
"dialog title": "未配置S3服务器",
"dialog body": "此实例未配置S3服务器。但您可以手动添加一个,以启用S3文件浏览器。",
cancel: "取消",
"go to settings": "前往设置"
},
ShareDialog: {
title: "分享您的数据",
close: "关闭",
Expand Down
1 change: 1 addition & 0 deletions web/src/ui/i18n/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type ComponentKey =
| import("ui/pages/mySecrets/SecretsExplorer/SecretsExplorerItems/SecretsExplorerItem").I18n
| import("ui/pages/mySecrets/MySecretsEditor/MySecretsEditorRow").I18n
| import("ui/pages/myFiles/MyFiles").I18n
| import("ui/pages/myFiles/MyFilesDisabledDialog").I18n
| import("ui/pages/myFiles/Explorer/Explorer").I18n
| import("ui/pages/myFiles/Explorer/ExplorerButtonBar").I18n
| import("ui/pages/myFiles/Explorer/ExplorerItems").I18n
Expand Down
11 changes: 10 additions & 1 deletion web/src/ui/pages/myFiles/MyFiles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ import type { PageRoute } from "./route";
import { assert } from "tsafe/assert";
import { env } from "env";
import { getIconUrlByName, customIcons } from "lazy-icons";
import { MyFilesDisabledDialog } from "./MyFilesDisabledDialog";

export type Props = {
route: PageRoute;
className?: string;
};

export default function MyFiles(props: Props) {
export default function MyFilesMaybeDisabled(props: Props) {
const isFileExplorerEnabled = useCoreState("fileExplorer", "isFileExplorerEnabled");
if (!isFileExplorerEnabled) {
return <MyFilesDisabledDialog />;
}
return <MyFiles {...props} />;
}

function MyFiles(props: Props) {
const { className, route } = props;

const { t } = useTranslation({ MyFiles });
Expand Down
15 changes: 15 additions & 0 deletions web/src/ui/pages/myFiles/MyFilesDisabledDialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Meta, StoryObj } from "@storybook/react";
import { MyFilesDisabledDialog } from "./MyFilesDisabledDialog";

const meta = {
title: "Pages/MyFiles/MyFilesDisabledDialog",
component: MyFilesDisabledDialog
} satisfies Meta<typeof MyFilesDisabledDialog>;

export default meta;

type Story = StoryObj<typeof meta>;

export const Default: Story = {
args: {}
};
50 changes: 50 additions & 0 deletions web/src/ui/pages/myFiles/MyFilesDisabledDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { memo } from "react";
import { Dialog } from "onyxia-ui/Dialog";
import { Button } from "onyxia-ui/Button";
import { routes } from "ui/routes";
import { declareComponentKeys, useTranslation } from "ui/i18n";

export const MyFilesDisabledDialog = memo(() => {
const onClose = () => routes.home().push();
const { t } = useTranslation({ MyFilesDisabledDialog });

return (
<Dialog
title={t("dialog title")}
isOpen={true}
onClose={onClose}
body={t("dialog body")}
buttons={
<>
<Button variant="secondary" onClick={onClose}>
{t("cancel")}
</Button>
<Button
autoFocus
doOpenNewTabIfHref={false}
{...(() => {
const link = routes.projectSettings({
tabId: "s3-configs"
}).link;
return {
...link,
onClick: e => {
onClose();
return link.onClick(e);
}
};
})()}
>
{t("go to settings")}
</Button>
</>
}
/>
);
});

const { i18n } = declareComponentKeys<
"dialog title" | "dialog body" | "cancel" | "go to settings"
>()({ MyFilesDisabledDialog });

export type I18n = typeof i18n;

0 comments on commit deb1880

Please sign in to comment.