Fakultas Ilmu Komputer UI

Commit 2dc0e3f8 authored by Sean Zeliq Urian's avatar Sean Zeliq Urian
Browse files

[REFACTOR] fix code style

parent e6616171
...@@ -9,7 +9,6 @@ import Button from 'components/Button'; ...@@ -9,7 +9,6 @@ import Button from 'components/Button';
import Loading from 'components/Loading'; import Loading from 'components/Loading';
import Icon from 'components/Icon'; import Icon from 'components/Icon';
type ValueType = string | number; type ValueType = string | number;
interface TableProps { interface TableProps {
...@@ -17,10 +16,13 @@ interface TableProps { ...@@ -17,10 +16,13 @@ interface TableProps {
header: Array<string>; header: Array<string>;
data?: Array<Array<ValueType>>; data?: Array<Array<ValueType>>;
setData?: any; setData?: any;
onChange?: (value: string, pageNumber: number) => Promise<Array<Array<ValueType>>>; onChange?: (
value: string,
pageNumber: number
) => Promise<Array<Array<ValueType>>>;
searchPlaceholder?: string; searchPlaceholder?: string;
maximumData?: number; maximumData?: number;
rowOnClick?: (row: Array<ValueType>) => void rowOnClick?: (row: Array<ValueType>) => void;
} }
const Click = styled.div` const Click = styled.div`
...@@ -68,7 +70,7 @@ const TableHeader = styled.th` ...@@ -68,7 +70,7 @@ const TableHeader = styled.th`
const LoadingContainer = styled.tr` const LoadingContainer = styled.tr`
height: 400px; height: 400px;
` `;
const DEFAULT_THEME = { const DEFAULT_THEME = {
colors: { colors: {
...@@ -124,7 +126,9 @@ export default function Table({ ...@@ -124,7 +126,9 @@ export default function Table({
if (newData.length === 0 || newData[0].length === 0) return; if (newData.length === 0 || newData[0].length === 0) return;
setPageNumber(newPageNumber); setPageNumber(newPageNumber);
setPreviousDataTotal(previousDataTotal + (sign === 1? data.length: -newData.length)); setPreviousDataTotal(
previousDataTotal + (sign === 1 ? data.length : -newData.length)
);
setData([...newData]); setData([...newData]);
}; };
...@@ -149,7 +153,7 @@ export default function Table({ ...@@ -149,7 +153,7 @@ export default function Table({
initializeData(); initializeData();
}, []); }, []);
if (data[0] && (header.length > data[0].length)) { if (data[0] && header.length > data[0].length) {
throw new Error('The shape of Header and data are not consistent'); throw new Error('The shape of Header and data are not consistent');
} }
...@@ -218,7 +222,7 @@ export default function Table({ ...@@ -218,7 +222,7 @@ export default function Table({
})} })}
</tr> </tr>
</thead> </thead>
{isLoading? ( {isLoading ? (
<tbody> <tbody>
<LoadingContainer> <LoadingContainer>
<Loading isLoading={isLoading} shouldSetBlackTheme={true} /> <Loading isLoading={isLoading} shouldSetBlackTheme={true} />
...@@ -235,7 +239,9 @@ export default function Table({ ...@@ -235,7 +239,9 @@ export default function Table({
index % 2 === 0 ? 'transparent' : colors.almostWhite index % 2 === 0 ? 'transparent' : colors.almostWhite
} }
> >
{row.filter((_, index) => index < header.length).map((value: ValueType, index: number) => { {row
.filter((_, index) => index < header.length)
.map((value: ValueType, index: number) => {
return ( return (
<td key={index}> <td key={index}>
<Text <Text
...@@ -248,7 +254,7 @@ export default function Table({ ...@@ -248,7 +254,7 @@ export default function Table({
</td> </td>
); );
})} })}
{rowOnClick? ( {rowOnClick ? (
<td> <td>
<Box <Box
height="100%" height="100%"
...@@ -269,34 +275,33 @@ export default function Table({ ...@@ -269,34 +275,33 @@ export default function Table({
crossAxis="center" crossAxis="center"
background={colors.green} background={colors.green}
> >
<Icon src="/assets/icons/zoom.svg" height="50%" cursor="pointer" /> <Icon
src="/assets/icons/zoom.svg"
height="50%"
cursor="pointer"
/>
</Box> </Box>
</Click> </Click>
</Box> </Box>
</td> </td>
) : <></>} ) : (
<></>
)}
</Row> </Row>
); );
})} })}
</tbody> </tbody>
)} )}
</StyledTable> </StyledTable>
{!isLoading && data.length === 0 {!isLoading && data.length === 0 ? (
? ( <Box width="100%" height="300px" mainAxis="center" crossAxis="center">
<Box <Text type={Text.StyleType.Medium} color={colors.mediumGray}>
width="100%"
height="300px"
mainAxis='center'
crossAxis='center'
>
<Text
type={Text.StyleType.Medium}
color={colors.mediumGray}
>
Tidak ada data Tidak ada data
</Text> </Text>
</Box> </Box>
) : <></>} ) : (
<></>
)}
<Gap gap={20} axis={Gap.Axis.Vertical} /> <Gap gap={20} axis={Gap.Axis.Vertical} />
<Box width="100%" mainAxis="flex-end"> <Box width="100%" mainAxis="flex-end">
<Box crossAxis="center"> <Box crossAxis="center">
...@@ -318,7 +323,10 @@ export default function Table({ ...@@ -318,7 +323,10 @@ export default function Table({
transform="rotateZ(180deg)" transform="rotateZ(180deg)"
/> />
<Gap gap={12} axis={Gap.Axis.Horizontal} /> <Gap gap={12} axis={Gap.Axis.Horizontal} />
<Text id='page-number' type={Text.StyleType.Small}>{`${pageNumber}`}</Text> <Text
id="page-number"
type={Text.StyleType.Small}
>{`${pageNumber}`}</Text>
<Gap gap={12} axis={Gap.Axis.Horizontal} /> <Gap gap={12} axis={Gap.Axis.Horizontal} />
<Icon <Icon
data-test-id="next-button" data-test-id="next-button"
......
import { LogDetail } from 'scenes/ActivityLog/types/types' import { LogDetail } from 'scenes/ActivityLog/types/types';
const generateLogMessage = async (log: any, services: any) => { const generateLogMessage = async (log: any, services: any) => {
let message = ''; let message = '';
...@@ -10,9 +10,7 @@ const generateLogMessage = async (log: any, services: any) => { ...@@ -10,9 +10,7 @@ const generateLogMessage = async (log: any, services: any) => {
case 'Create': { case 'Create': {
if (accountResponse.status === 200) { if (accountResponse.status === 200) {
let username = accountResponse.data.username; let username = accountResponse.data.username;
let accountType = accountResponse.data.is_admin let accountType = accountResponse.data.is_admin ? 'admin' : 'kader';
? 'admin'
: 'kader';
message = message =
'Menambahkan akun ' + 'Menambahkan akun ' +
accountType + accountType +
...@@ -26,9 +24,7 @@ const generateLogMessage = async (log: any, services: any) => { ...@@ -26,9 +24,7 @@ const generateLogMessage = async (log: any, services: any) => {
case 'Edit': { case 'Edit': {
if (accountResponse.status === 200) { if (accountResponse.status === 200) {
let username = accountResponse.data.username; let username = accountResponse.data.username;
let accountType = accountResponse.data.is_admin let accountType = accountResponse.data.is_admin ? 'admin' : 'kader';
? 'admin'
: 'kader';
message = message =
'Memperbarui akun ' + 'Memperbarui akun ' +
accountType + accountType +
...@@ -77,7 +73,10 @@ const generateLogMessage = async (log: any, services: any) => { ...@@ -77,7 +73,10 @@ const generateLogMessage = async (log: any, services: any) => {
return message; return message;
}; };
const generateLogDetail = async (log: any, services: any): Promise<LogDetail> => { const generateLogDetail = async (
log: any,
services: any
): Promise<LogDetail> => {
let logDetail: LogDetail = { let logDetail: LogDetail = {
activity: log.model_name, activity: log.model_name,
authorRole: log.author.is_admin ? 'admin' : 'kader', authorRole: log.author.is_admin ? 'admin' : 'kader',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment