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

[WIP] Configuration Validator Dialog #71

Open
wants to merge 1 commit into
base: import-configuration
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
NODE_ENV=development
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gas-fire",
"version": "3.2.0",
"version": "4.0.0",
"author": "Melle Dijkstra",
"description": "Google App Script utilities to automate the FIRE google sheet",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const meta: Meta<typeof Dialog> = {
title: 'Dialogs/Settings',
component: Dialog,
args: {
dialogSize: DIALOG_SIZES.settings,
dialogTitle: 'Settings Dialog',
dialogSize: DIALOG_SIZES.configValidator,
dialogTitle: 'Config Validator Dialog',
},
};

Expand Down
89 changes: 89 additions & 0 deletions src/client/config-validator-dialog/Dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import {
Alert,
Collapse,
Icon,
List,
ListItemButton,
ListItemIcon,
ListItemText,
} from '@mui/material';
import { Application } from '../Application';
import { useEffect, useState } from 'react';
import { serverFunctions } from '../utils/serverFunctions';
import { ConfigData } from '@/common/types';

const ConfigItem = ({
accountId,
config,
}: {
accountId: string;
config: ConfigData;
}) => {
// const [open, setOpen] = useState(false);

// const toggleOpen = () => {
// setOpen(!open);
// };

return (
<>
<ListItemButton>
<ListItemIcon>
<Icon>account_balance</Icon>
</ListItemIcon>
<ListItemText primary={accountId} />
{/* {open ? <Icon>expand_less</Icon> : <Icon>expand_more</Icon>} */}
</ListItemButton>
{/* <Collapse in={open}>
<List component="div" disablePadding>
<ListItemButton sx={{ pl: 4 }}>
<ListItemText primary="-" />
</ListItemButton>
</List>
</Collapse> */}
</>
);
};

export const Dialog = () => {
const [loading, setLoading] = useState(true);
const [configs, setConfigs] = useState<Record<string, ConfigData>>({});
const [error, setError] = useState<string | null>(null);

useEffect(() => {
setConfigs({});
setError(null);
setLoading(true);
serverFunctions
.getConfiguration()
.then((configs) => {
setConfigs(configs);
setLoading(false);
})
.catch((error: Error) => {
setError(error.message);
});
}, []);

const text = loading
? 'Loading...'
: `${Object.keys(configs).length} configs loaded`;

return (
<Application>
<Alert severity="info">{text}</Alert>
<Alert severity="success">Configuration is valid!</Alert>
{error && <Alert severity="error">{error}</Alert>}

<List sx={{ width: '100%', bgcolor: 'background.paper' }} component="nav">
{Object.keys(configs).map((accountId) => (
<ConfigItem
key={accountId}
accountId={accountId}
config={configs[accountId]}
/>
))}
</List>
</Application>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<head>
<base target="_top" />
<!-- Add any external scripts and stylesheets here -->
<link
rel="stylesheet"
href="https://fonts.googleapis.com/icon?family=Material+Icons"
/>
<script
crossorigin
integrity="sha384-DGyLxAyjq0f9SPpVevD6IgztCFlnMF6oW/XQGmfe+IsZ8TqEiDrcHkMLKI6fiB/Z"
Expand Down
40 changes: 0 additions & 40 deletions src/client/settings-dialog/Dialog.tsx

This file was deleted.

This file was deleted.

66 changes: 0 additions & 66 deletions src/client/settings-dialog/components/FormRule.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/client/settings-dialog/components/ImportRulesForm.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum DialogType {
import,
settings,
configValidator,
about,
}

Expand All @@ -12,7 +12,7 @@ export enum NAMED_RANGES {

export const DIALOG_SIZES: Record<keyof typeof DialogType, [number, number]> = {
import: [900, 600],
settings: [900, 600],
configValidator: [900, 600],
about: [300, 200],
};

Expand All @@ -35,7 +35,7 @@ export const FIRE_COLUMNS = [
'currency',
] as const;

export type FireColumn = (typeof FIRE_COLUMNS)[number];
export const DEFAULT_CACHE_SECOND = 20;

export const SOURCE_SHEET_ID = 1093484485;

Expand Down
15 changes: 15 additions & 0 deletions src/common/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FIRE_COLUMNS } from './constants';

export type Strategies = {
[key: string]: string;
};
Expand Down Expand Up @@ -33,3 +35,16 @@ export type JsonTable = Record<string, string>[];
export type ServerResponse = {
message: string;
};

export type FireColumn = (typeof FIRE_COLUMNS)[number];

export type ColumnMap = {
[key in FireColumn]?: string;
};

export type ConfigData = {
columnMap: ColumnMap;
autoFillColumnIndices: number[];
autoFillEnabled: boolean;
autoCategorizationEnabled: boolean;
};
Loading