Skip to content

Commit

Permalink
Merge pull request #901 from InseeFrLab/s3-config-project
Browse files Browse the repository at this point in the history
improve s3 config project injection
  • Loading branch information
garronej authored Dec 18, 2024
2 parents f208ea4 + b0c1651 commit 645dd34
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
9 changes: 7 additions & 2 deletions web/src/core/usecases/launcher/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ const chartVersion = createSelector(readyState, state => {
const s3ConfigSelect = createSelector(
s3ConfigManagement.selectors.s3Configs,
isReady,
projectManagement.selectors.canInjectPersonalInfos,
createSelector(readyState, state => {
if (state === null) {
return null;
}
return state.s3Config;
}),
(s3Configs, isReady, s3Config) => {
(s3Configs, isReady, canInjectPersonalInfos, s3Config) => {
if (!isReady) {
return null;
}
Expand All @@ -137,13 +138,17 @@ const s3ConfigSelect = createSelector(
return undefined;
}

const availableConfigs = s3Configs.filter(
config => canInjectPersonalInfos || config.origin !== "deploymentRegion"
);

// We don't display the s3 config selector if there is no config or only one
if (s3Configs.length <= 1) {
return undefined;
}

return {
options: s3Configs.map(s3Config => ({
options: availableConfigs.map(s3Config => ({
optionValue: s3Config.id,
label: {
dataSource: s3Config.dataSource,
Expand Down
13 changes: 2 additions & 11 deletions web/src/core/usecases/launcher/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,8 @@ export const thunks = {
return;
}

const { doInjectPersonalInfos } = (() => {
const project =
projectManagement.protectedSelectors.currentProject(getState());

const doInjectPersonalInfos =
project.group === undefined ||
!rootContext.paramsOfBootstrapCore
.disablePersonalInfosInjectionInGroup;

return { doInjectPersonalInfos };
})();
const doInjectPersonalInfos =
projectManagement.selectors.canInjectPersonalInfos(getState());

const { s3ConfigId, s3ConfigId_default } = (() => {
const s3Configs = s3ConfigManagement.selectors
Expand Down
9 changes: 7 additions & 2 deletions web/src/core/usecases/projectManagement/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { State as RootState } from "core/bootstrap";
import type { Project } from "core/ports/OnyxiaApi";
import { name } from "./state";
import { createSelector } from "clean-architecture";
import { assert } from "tsafe/assert";
Expand All @@ -9,7 +8,7 @@ const state = (rootState: RootState) => rootState[name];
const projectConfig = createSelector(state, state => state.currentProjectConfigs);

export const protectedSelectors = {
currentProject: createSelector(state, (state): Project => {
currentProject: createSelector(state, state => {
const { projects, selectedProjectId } = state;

const project = projects.find(({ id }) => id === selectedProjectId);
Expand Down Expand Up @@ -46,5 +45,11 @@ export const selectors = {
doesUserBelongToSomeGroupProject: createSelector(
state,
state => state.projects.length !== 1
),
canInjectPersonalInfos: createSelector(
protectedSelectors.currentProject,
currentProject => {
return currentProject.doInjectPersonalInfos;
}
)
};
2 changes: 1 addition & 1 deletion web/src/core/usecases/projectManagement/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import type { ProjectConfigs } from "./decoupledLogic/ProjectConfigs";

type State = {
projects: Project[];
projects: (Project & { doInjectPersonalInfos: boolean })[];
selectedProjectId: string;
currentProjectConfigs: ProjectConfigs;
};
Expand Down
15 changes: 13 additions & 2 deletions web/src/core/usecases/projectManagement/thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ export const thunks = {
changeProject:
(params: { projectId: string }) =>
async (...args) => {
const [dispatch, getState, { onyxiaApi, secretsManager }] = args;
const [
dispatch,
getState,
{ onyxiaApi, secretsManager, paramsOfBootstrapCore }
] = args;

const { projectId } = params;

Expand Down Expand Up @@ -167,9 +171,16 @@ export const thunks = {
}
}

const projectWithInjectedPersonalInfos = projects.map(project => ({
...project,
doInjectPersonalInfos:
project.group === undefined ||
!paramsOfBootstrapCore.disablePersonalInfosInjectionInGroup
}));

dispatch(
actions.projectChanged({
projects,
projects: projectWithInjectedPersonalInfos,
selectedProjectId: projectId,
currentProjectConfigs: projectConfigs
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export const ProjectSettingsS3ConfigTab = memo((props: Props) => {
}));

const s3Configs = useCoreState("s3ConfigManagement", "s3Configs");

const canInjectPersonalInfos = useCoreState(
"projectManagement",
"canInjectPersonalInfos"
);
const { s3ConfigManagement } = useCore().functions;

const { classes, css, theme } = useStyles();
Expand Down Expand Up @@ -101,6 +104,7 @@ export const ProjectSettingsS3ConfigTab = memo((props: Props) => {
projectS3ConfigId: s3Config.id
});
})()}
canInjectPersonalInfos={canInjectPersonalInfos}
/>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Props = {
onIsOnyxiaDefaultChange: (value: boolean) => void;
onEdit: (() => void) | undefined;
onTestConnection: (() => void) | undefined;
canInjectPersonalInfos: boolean;
};

export function S3ConfigCard(props: Props) {
Expand All @@ -28,7 +29,8 @@ export function S3ConfigCard(props: Props) {
onIsExplorerConfigChange,
onIsOnyxiaDefaultChange,
onEdit,
onTestConnection
onTestConnection,
canInjectPersonalInfos
} = props;

const { classes, cx, css, theme } = useStyles();
Expand Down Expand Up @@ -80,7 +82,16 @@ export function S3ConfigCard(props: Props) {
</Tooltip>
&nbsp;
<Switch
checked={s3Config.isXOnyxiaDefault}
disabled={
canInjectPersonalInfos
? false
: s3Config.origin === "deploymentRegion"
}
checked={
canInjectPersonalInfos || s3Config.origin !== "deploymentRegion"
? s3Config.isXOnyxiaDefault
: false
}
onChange={event => onIsOnyxiaDefaultChange(event.target.checked)}
inputProps={{ "aria-label": "controlled" }}
/>
Expand Down

0 comments on commit 645dd34

Please sign in to comment.