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

improve s3 config project injection #901

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
}
Comment on lines +85 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic should ideally be handled by the core. The component shouldn't need to be so aware of the intricacies of S3Config management; its responsibility should be limited to rendering the UI and forwarding the relevant user input.

That said, I understand the desire to avoid introducing another type just to adhere strictly to the doctrine, so I'll approve this impl.

onChange={event => onIsOnyxiaDefaultChange(event.target.checked)}
inputProps={{ "aria-label": "controlled" }}
/>
Expand Down
Loading