Skip to content

Commit

Permalink
Rename configuration to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
pavsaund committed Sep 7, 2023
1 parent 5ade6ec commit 24213e6
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import React, { } from 'react';
import { SetupContainer } from './setup/SetupContainer';
import { ConfigurationContainer } from './configuration/ConfigurationContainer';
import { SettingsContainer } from './settings/SettingsContainer';
import { DataSyncConfigurationContainer } from './realtimeUpdates/DataSyncConfigurationContainer';

export const ConfigurationView = () => {
Expand All @@ -12,7 +12,7 @@ export const ConfigurationView = () => {
<>
<SetupContainer />
{/* TODO: Only show configuration section after the deployment type is set ? */}
<ConfigurationContainer />
<SettingsContainer />
<DataSyncConfigurationContainer />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ import { useSnackbar } from 'notistack';
import { ContentContainer, ContentHeader } from '@dolittle/design-system/';
import { useConnectionsIdGet } from '../../../../../apis/integrations/connectionsApi.hooks';
import { useConnectionIdFromRoute } from '../../../../routes.hooks';
import { ExporterConfigurationSection } from './ExporterConfigurationSection';
import { ConnectorConfigurationForm, ConnectorConfigurationFormRef, ConnectorConfigurationFormSaveState } from './ConnectorConfigurationForm';
import { SettingsFormContent } from './SettingsFormContent';
import { SettingsForm, SettingsFormRef, SettingsFormSaveState } from './SettingsForm';
import { ActionToolbar } from './ActionToolbar';

export const ConfigurationContainer = () => {
export const SettingsContainer = () => {
const [canEdit, setEditMode] = useState(false);
const [lastSaveState, setLastSaveState] = useState<ConnectorConfigurationFormSaveState>();
const [lastSaveState, setLastSaveState] = useState<SettingsFormSaveState>();

const { enqueueSnackbar } = useSnackbar();
const connectionId = useConnectionIdFromRoute();
const query = useConnectionsIdGet({ id: connectionId });

const formRef = useRef<ConnectorConfigurationFormRef>(null);
const formRef = useRef<SettingsFormRef>(null);

const connection = query.data?.value;
const links = query.data?.links || [];

const handleSaveState = (saveState: ConnectorConfigurationFormSaveState) => {
const handleSaveState = (saveState: SettingsFormSaveState) => {
setLastSaveState(saveState);
saveState.forEach((state) => {
if (state.status === 'success') {
Expand All @@ -35,7 +35,7 @@ export const ConfigurationContainer = () => {
});
};

const handleOnSaved = (saveState: ConnectorConfigurationFormSaveState): void => {
const handleOnSaved = (saveState: SettingsFormSaveState): void => {
if (saveState.every((state) => state.status === 'success')) {
setEditMode(false);
}
Expand All @@ -52,7 +52,7 @@ export const ConfigurationContainer = () => {

return (
<ContentContainer>
<ConnectorConfigurationForm
<SettingsForm
connectionId={connectionId}
connection={connection}
onSaved={handleOnSaved}
Expand All @@ -68,8 +68,8 @@ export const ConfigurationContainer = () => {
/>
}
/>
<ExporterConfigurationSection canEdit={canEdit} />
</ConnectorConfigurationForm>
<SettingsFormContent canEdit={canEdit} />
</SettingsForm>
</ContentContainer>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useConnectionsIdConfigurationExporterStrictCertificateValidationPost }


//TODO: Can this be replaced with using `watch` from react-hook-form?
const useForceSubscribeToIsDirtyStateChanges = (currentForm: FormRef<ConnectorConfigurationFormParameters> | undefined) => {
const useForceSubscribeToIsDirtyStateChanges = (currentForm: FormRef<SettingsFormParameters> | undefined) => {
useEffect(() => {
if (currentForm) {
const { isDirty } = currentForm.getFieldState('strictCertificateValidation', currentForm.formState);
Expand All @@ -29,33 +29,33 @@ export type ConfigurationSaveActionState =

export type ConfigurationFormSaveAction = { name: ConfigurationSaveActionName } & ConfigurationSaveActionState;

export type ConnectorConfigurationFormSaveState = ConfigurationFormSaveAction[];
export type SettingsFormSaveState = ConfigurationFormSaveAction[];

export type ConnectorConfigurationFormRef = {
export type SettingsFormRef = {
reset: (keepDefault: boolean) => void;
};

export type ConnectorConfigurationFormParameters = {
export type SettingsFormParameters = {
strictCertificateValidation: boolean;
};

export type ConnectorConfigurationFormProps = {
export type SettingsFormProps = {
connectionId: string;
connection: ConnectionModel
onSaved?: (saveState: ConnectorConfigurationFormSaveState) => void;
onSaved?: (saveState: SettingsFormSaveState) => void;
children?: React.ReactNode;
};

export const ConnectorConfigurationForm = React.forwardRef<ConnectorConfigurationFormRef, ConnectorConfigurationFormProps>(({
export const SettingsForm = React.forwardRef<SettingsFormRef, SettingsFormProps>(({
connectionId,
connection,
onSaved,
children
}: ConnectorConfigurationFormProps,
ref: React.Ref<ConnectorConfigurationFormRef>
}: SettingsFormProps,
ref: React.Ref<SettingsFormRef>
) => {
const [currentForm, setCurrentForm] = useState<FormRef<ConnectorConfigurationFormParameters>>();
const [lastSaveState, setLastSaveState] = useState<ConnectorConfigurationFormSaveState>();
const [currentForm, setCurrentForm] = useState<FormRef<SettingsFormParameters>>();
const [lastSaveState, setLastSaveState] = useState<SettingsFormSaveState>();
const formRef = useCallback((ref) => {
if (ref) {
setCurrentForm(ref);
Expand All @@ -80,7 +80,7 @@ export const ConnectorConfigurationForm = React.forwardRef<ConnectorConfiguratio

const strictCertificateValidationMutation = useConnectionsIdConfigurationExporterStrictCertificateValidationPost();

const defaultValues: ConnectorConfigurationFormParameters = useMemo(() => (
const defaultValues: SettingsFormParameters = useMemo(() => (
{
strictCertificateValidation: connection.strictCertificateValidation || false,
}
Expand All @@ -99,7 +99,7 @@ export const ConnectorConfigurationForm = React.forwardRef<ConnectorConfiguratio

}, [defaultValues, currentForm]);

const handleSave: SubmitHandler<ConnectorConfigurationFormParameters> = useCallback((data) => {
const handleSave: SubmitHandler<SettingsFormParameters> = useCallback((data) => {
if (!connectionId || !currentForm) {
return;
}
Expand Down Expand Up @@ -143,7 +143,7 @@ export const ConnectorConfigurationForm = React.forwardRef<ConnectorConfiguratio
]);

return (
<Form<ConnectorConfigurationFormParameters>
<Form<SettingsFormParameters>
initialValues={defaultValues}
onSubmit={(data, event) => handleSave(data, event)}
fRef={formRef}
Expand All @@ -153,4 +153,4 @@ export const ConnectorConfigurationForm = React.forwardRef<ConnectorConfiguratio
);
});

ConnectorConfigurationForm.displayName = 'ConnectorConfigurationForm';
SettingsForm.displayName = 'SettingsForm';
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

import React from 'react';
import { ContentParagraph, ContentSection, Input, Link, Switch } from '@dolittle/design-system';
import { ContentParagraph, ContentSection, Switch } from '@dolittle/design-system';

export type ExporterConfigurationSectionProps = {
export type SettingsFormContentProps = {
canEdit: boolean;
};

export const ExporterConfigurationSection = ({ canEdit }: ExporterConfigurationSectionProps) => {
export const SettingsFormContent = ({ canEdit }: SettingsFormContentProps) => {

return (
<>
Expand Down

0 comments on commit 24213e6

Please sign in to comment.