Skip to content
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
5 changes: 3 additions & 2 deletions admin/src/components/ActionButtons/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ const ActionButtons = () => {
const dispatch = useDispatch();
const { toggleNotification } = useNotification();
const partialDiff = useSelector((state) => state.getIn(['config', 'partialDiff'], Map({}))).toJS();
const isLoading = useSelector((state) => state.getIn(['config', 'isLoading'], false));
const { formatMessage } = useIntl();

return (
<ActionButtonsStyling>
<ConfirmModal
type="import"
trigger={(
<Button disabled={isEmpty(partialDiff)}>
<Button disabled={isLoading || isEmpty(partialDiff)}>
{formatMessage({ id: 'config-sync.Buttons.Import' })}
</Button>
)}
Expand All @@ -31,7 +32,7 @@ const ActionButtons = () => {
<ConfirmModal
type="export"
trigger={(
<Button disabled={isEmpty(partialDiff)}>
<Button disabled={isLoading || isEmpty(partialDiff)}>
{formatMessage({ id: 'config-sync.Buttons.Export' })}
</Button>
)}
Expand Down
54 changes: 44 additions & 10 deletions admin/src/components/ConfigDiff/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { useDispatch } from 'react-redux';
import RDV, { DiffMethod } from 'react-diff-viewer-continued';
import { useIntl } from 'react-intl';
import { getFetchClient, useNotification } from '@strapi/strapi/admin';

/**
* An issue with the diff-viewer library causes a difference in the way the library is exported.
Expand All @@ -19,19 +21,21 @@ if (typeof RDV.default !== 'undefined') {
}

import {
Button,
Modal,
Grid,
Typography,
} from '@strapi/design-system';
import ConfirmModal from '../ConfirmModal';
import { exportAllConfig, importAllConfig } from '../../state/actions/Config';

const ConfigDiff = ({ oldValue, newValue, configName, trigger }) => {
const ConfigDiff = ({ oldValue, newValue, configName, open, onOpenChange }) => {
const { formatMessage } = useIntl();

const dispatch = useDispatch();
const { toggleNotification } = useNotification();
const { post, get } = getFetchClient();
return (
<Modal.Root>
<Modal.Trigger>
{trigger}
</Modal.Trigger>
<Modal.Root open={open} onOpenChange={onOpenChange}>
<Modal.Content>
<Modal.Header>
<Typography variant="omega" fontWeight="bold" textColor="neutral800">
Expand All @@ -41,21 +45,51 @@ const ConfigDiff = ({ oldValue, newValue, configName, trigger }) => {
<Modal.Body>
<Grid.Root paddingBottom={4} style={{ textAlign: 'center' }}>
<Grid.Item col={6}>
<Typography variant="delta" style={{ width: '100%' }}>{formatMessage({ id: 'config-sync.ConfigDiff.SyncDirectory' })}</Typography>
<Typography variant="delta" style={{ width: '100%' }}>
{formatMessage({ id: 'config-sync.ConfigDiff.SyncDirectory' })}
</Typography>
</Grid.Item>
<Grid.Item col={6}>
<Typography variant="delta" style={{ width: '100%' }}>{formatMessage({ id: 'config-sync.ConfigDiff.Database' })}</Typography>
<Typography variant="delta" style={{ width: '100%' }}>
{formatMessage({ id: 'config-sync.ConfigDiff.Database' })}
</Typography>
</Grid.Item>
</Grid.Root>
<Typography variant="pi">
<ReactDiffViewer
oldValue={JSON.stringify(oldValue, null, 2)}
newValue={JSON.stringify(newValue, null, 2)}
oldValue={JSON.stringify(oldValue, null, 2) ?? ''}
newValue={JSON.stringify(newValue, null, 2) ?? ''}
splitView
compareMethod={DiffMethod.WORDS}
/>
</Typography>
</Modal.Body>
<Modal.Footer justifyContent="flex-end" gap={2}>
<ConfirmModal
type="import"
trigger={(
<Button title={formatMessage({ id: 'config-sync.ConfigDiff.ImportTitle' })}>
{formatMessage({ id: 'config-sync.Buttons.Import' })}
</Button>
)}
onSubmit={async (force) => {
const succeeded = await dispatch(importAllConfig([configName], force, toggleNotification, formatMessage, post, get));
if (succeeded) onOpenChange(false, configName);
}}
/>
<ConfirmModal
type="export"
trigger={(
<Button title={formatMessage({ id: 'config-sync.ConfigDiff.ExportTitle' })}>
{formatMessage({ id: 'config-sync.Buttons.Export' })}
</Button>
)}
onSubmit={async () => {
const succeeded = await dispatch(exportAllConfig([configName], toggleNotification, formatMessage, post, get));
if (succeeded) onOpenChange(false, configName);
}}
/>
</Modal.Footer>
</Modal.Content>
</Modal.Root>
);
Expand Down
14 changes: 5 additions & 9 deletions admin/src/components/ConfigList/ConfigListRow/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,23 @@ const CustomRow = ({ row, checked, updateValue, ...props }) => {
return (
<Tr
{...props}
onClick={(e) => {
if (e.target.type !== 'checkbox') {
onClick(configType, configName);
}
}}
onClick={() => onClick(configType, configName)}
style={{ cursor: 'pointer' }}
>
<Td>
<Td onClick={(e) => e.stopPropagation()}>
<Checkbox
aria-label={`Select ${configName}`}
checked={checked}
onCheckedChange={updateValue}
/>
</Td>
<Td onClick={(e) => props.onClick(e)}>
<Td>
<Typography variant="omega">{configName}</Typography>
</Td>
<Td onClick={(e) => props.onClick(e)}>
<Td>
<Typography variant="omega">{configType}</Typography>
</Td>
<Td onClick={(e) => props.onClick(e)}>
<Td>
<Typography variant="omega" style={stateStyle(state)}>{state}</Typography>
</Td>
</Tr>
Expand Down
74 changes: 40 additions & 34 deletions admin/src/components/ConfigList/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import { setConfigPartialDiffInState } from '../../state/actions/Config';


const ConfigList = ({ diff, isLoading }) => {
const [originalConfig, setOriginalConfig] = useState({});
const [newConfig, setNewConfig] = useState({});
const [cName, setCname] = useState('');
const [rows, setRows] = useState([]);
const [checkedItems, setCheckedItems] = useState([]);
Expand Down Expand Up @@ -68,8 +66,6 @@ const ConfigList = ({ diff, isLoading }) => {
configType: type,
state: getConfigState(name),
onClick: (configType, configName) => {
setOriginalConfig(diff.fileConfig[`${configType}.${configName}`]);
setNewConfig(diff.databaseConfig[`${configType}.${configName}`]);
setCname(`${configType}.${configName}`);
},
});
Expand All @@ -87,24 +83,25 @@ const ConfigList = ({ diff, isLoading }) => {
dispatch(setConfigPartialDiffInState(newPartialDiff));
}, [checkedItems]);

if (isLoading) {
return (
<div style={{ textAlign: 'center', marginTop: 40 }}>
<Loader>{formatMessage({ id: 'config-sync.ConfigList.Loading' })}</Loader>
</div>
);
}
const renderList = () => {
if (isLoading) {
return (
<div style={{ textAlign: 'center', marginTop: 40 }}>
<Loader>{formatMessage({ id: 'config-sync.ConfigList.Loading' })}</Loader>
</div>
);
}

if (!isLoading && !isEmpty(diff.message)) {
return <FirstExport />;
}
if (!isEmpty(diff.message)) {
return <FirstExport />;
}

if (!isLoading && isEmpty(diff.diff)) {
return <NoChanges />;
}
if (isEmpty(diff.diff)) {
return <NoChanges />;
}

const allChecked = checkedItems && checkedItems.every(Boolean);
const isIndeterminate = checkedItems.some(Boolean) && !allChecked;
const allChecked = checkedItems && checkedItems.every(Boolean);
const isIndeterminate = checkedItems.some(Boolean) && !allChecked;

return (
<div>
Expand All @@ -131,26 +128,35 @@ const ConfigList = ({ diff, isLoading }) => {
</Thead>
<Tbody>
{rows.map((row, index) => (
<ConfigDiff
key={row.configName}
oldValue={originalConfig}
newValue={newConfig}
configName={cName}
trigger={(
<ConfigListRow
row={row}
checked={checkedItems[index]}
updateValue={() => {
checkedItems[index] = !checkedItems[index];
setCheckedItems([...checkedItems]);
}}
/>
)}
<ConfigListRow
key={`${row.configType}.${row.configName}`}
row={row}
checked={checkedItems[index]}
updateValue={() => {
checkedItems[index] = !checkedItems[index];
setCheckedItems([...checkedItems]);
}}
/>
))}
</Tbody>
</Table>
</div>
);
};

return (
<>
{renderList()}
<ConfigDiff
oldValue={diff.fileConfig?.[cName]}
newValue={diff.databaseConfig?.[cName]}
configName={cName}
open={Boolean(cName)}
onOpenChange={(open, syncedName) => {
if (!open) setCname((current) => (!syncedName || current === syncedName ? '' : current));
}}
/>
</>
);
};

Expand Down
Loading
Loading