strapi-plugin-config-sync/admin/src/components/ConfigList/ConfigListRow/index.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-03-27 16:16:14 +01:00
import React from 'react';
import { Tr, Td } from '@strapi/design-system/Table';
2021-11-20 19:06:01 +01:00
import { BaseCheckbox } from '@strapi/design-system/BaseCheckbox';
2021-03-27 16:16:14 +01:00
2021-11-20 19:06:01 +01:00
const CustomRow = ({ row, checked, updateValue }) => {
2021-10-14 17:39:53 +02:00
const { configName, configType, state, onClick } = row;
2021-03-27 16:16:14 +01:00
2021-10-14 17:39:53 +02:00
const stateStyle = (stateStr) => {
2021-10-14 17:13:12 +02:00
const style = {
display: 'inline-flex',
padding: '0 10px',
borderRadius: '12px',
height: '24px',
alignItems: 'center',
fontWeight: '500',
};
2021-10-14 17:39:53 +02:00
if (stateStr === 'Only in DB') {
2021-10-14 17:13:12 +02:00
style.backgroundColor = '#cbf2d7';
style.color = '#1b522b';
}
2021-10-14 17:39:53 +02:00
if (stateStr === 'Only in sync dir') {
2021-10-14 17:13:12 +02:00
style.backgroundColor = '#f0cac7';
style.color = '#3d302f';
}
2021-10-14 17:39:53 +02:00
if (stateStr === 'Different') {
2021-10-14 17:13:12 +02:00
style.backgroundColor = '#e8e6b7';
style.color = '#4a4934';
}
return style;
};
2021-03-27 16:16:14 +01:00
return (
<Tr
2021-11-20 19:06:01 +01:00
onClick={(e) => {
if (e.target.type !== 'checkbox') {
onClick(configType, configName);
}
}}
style={{ cursor: 'pointer' }}
>
2021-11-20 19:06:01 +01:00
<Td>
<BaseCheckbox
aria-label={`Select ${configName}`}
value={checked}
onValueChange={updateValue}
/>
</Td>
<Td>
2021-10-14 17:39:53 +02:00
<p>{configName}</p>
</Td>
<Td>
2021-10-14 17:39:53 +02:00
<p>{configType}</p>
</Td>
<Td>
2021-03-27 16:16:14 +01:00
<p style={stateStyle(state)}>{state}</p>
</Td>
</Tr>
2021-03-27 16:16:14 +01:00
);
};
2021-10-14 17:13:12 +02:00
export default CustomRow;