Skip to content

Commit

Permalink
Merge pull request #57 from pitzzahh/feat/changing-of-parent
Browse files Browse the repository at this point in the history
Feat/ load auto increment
  • Loading branch information
pitzzahh authored Dec 14, 2024
2 parents 7d045e6 + e4d6f7d commit 96b135c
Show file tree
Hide file tree
Showing 52 changed files with 755 additions and 385 deletions.
Binary file modified bun.lockb
Binary file not shown.
17 changes: 17 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://"0.0.9"keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.17] - 2024-12-13

## Update

- Update dependencies to fix security vulnerabilities.

## [0.1.16] - 2024-12-13

## Add

- Changing of load supply from to any load or highest unit.
- More bugs

## Fix

- Horsepower rating dropdown options.

## [0.1.15] - 2024-12-12

## Add
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "heda",
"version": "0.1.15",
"version": "0.1.17",
"type": "module",
"private": true,
"author": {
Expand All @@ -16,13 +16,14 @@
"lint": "prettier --check . && eslint .",
"tauri": "tauri",
"db:gen": "drizzle-kit generate",
"db:push": "drizzle-kit push"
"db:push": "drizzle-kit push",
"site:td": "bun run build && bun run preview"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.3.1",
"@sveltejs/adapter-static": "^3.0.6",
"@sveltejs/kit": "^2.10.1",
"@sveltejs/vite-plugin-svelte": "^5.0.1",
"@sveltejs/kit": "^2.11.1",
"@sveltejs/vite-plugin-svelte": "^5.0.2",
"@tailwindcss/typography": "^0.5.15",
"@tauri-apps/cli": "^2.1.0",
"@types/eslint": "^9.6.1",
Expand All @@ -37,7 +38,7 @@
"prettier": "^3.4.2",
"prettier-plugin-svelte": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.9",
"svelte": "^5.11.2",
"svelte": "^5.12.0",
"svelte-check": "^4.1.1",
"svelte-radix": "^2.0.1",
"svelte-sonner": "^0.3.28",
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "../node_modules/@tauri-apps/cli/config.schema.json",
"productName": "Hierarchical Electrical Design Analyzer",
"version": "0.1.15",
"version": "0.1.17",
"identifier": "me.araopj.heda",
"build": {
"frontendDist": "../build",
Expand Down
32 changes: 32 additions & 0 deletions src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,38 @@
body {
@apply bg-background text-foreground;
}
button:active {
@apply scale-98 transition-all;
}

::-webkit-scrollbar {
@apply h-full w-3 border-l border-l-transparent p-px;
}

::-webkit-scrollbar-track {
@apply !bg-transparent pr-4;
}
::-webkit-scrollbar-thumb {
@apply relative rounded-sm !bg-border;
}

::-webkit-scrollbar-corner {
background: rgba(0, 0, 0, 0);
}

@media (prefers-reduced-motion: no-preference) {
:root::view-transition-old(root) {
animation:
90ms cubic-bezier(0.4, 0, 1, 1) both fade-out,
300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-to-left;
}

:root::view-transition-new(root) {
animation:
210ms cubic-bezier(0, 0, 0.2, 1) 90ms both fade-in,
300ms cubic-bezier(0.4, 0, 0.2, 1) both slide-from-right;
}
}
}

/* @font-face {
Expand Down
8 changes: 3 additions & 5 deletions src/lib/components/custom/highest-unit-form.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<script lang="ts" generics="T extends SuperValidated<HighestUnitSchema>">
<script lang="ts" generics="T extends SuperValidated<NonNullable<Node['highest_unit_form']>>">
import { goto, invalidate } from '$app/navigation';
import { superForm, type SuperValidated } from 'sveltekit-superforms';
import { zodClient } from 'sveltekit-superforms/adapters';
import { toast } from 'svelte-sonner';
import { Input } from '@/components/ui/input/index.js';
import * as RadioGroup from '@/components/ui/radio-group/index.js';
import * as Form from '@/components/ui/form/index.js';
import { tick, untrack } from 'svelte';
import { useId } from 'bits-ui';
import { cn } from '@/utils';
import { buttonVariants } from '@/components/ui/button';
import { type HighestUnitSchema, highest_unit_schema } from '@/schema';
import { highest_unit_schema } from '@/schema';
import { DEFAULT_PHASES_OPTIONS } from '@/constants';
import { createProject } from '@/db/mutations/index';
import type { Project } from '@/types/project';
import type { Project, Node } from '@/db/schema';
interface Props {
highest_unit_form: T;
Expand Down
63 changes: 41 additions & 22 deletions src/lib/components/custom/load/generic-phase-main-load-form.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,29 @@
import { checkNodeExists } from '@/db/queries';
import { invalidateAll } from '$app/navigation';
import { convertToNormalText } from '@/utils/text';
import type { Node } from '@/types/project';
import type { Node } from '@/db/schema';
import type { LoadType, TerminalTemperature, VariesLabel } from '@/types/load';
import { dev } from '$app/environment';
interface Props {
phase_main_load_form: T;
saved_path?: string;
closeDialog: () => void;
load_to_edit?: Node;
selected_parent_id?: string;
node_to_edit?: Node;
action: 'add' | 'edit';
latest_circuit_node?: Node;
}
type FormLoadTypeOption = 'DEFAULT' | 'CUSTOM';
let { phase_main_load_form, closeDialog, load_to_edit, action }: Props = $props();
let {
phase_main_load_form,
closeDialog,
node_to_edit,
action,
selected_parent_id,
latest_circuit_node
}: Props = $props();
const form = superForm(phase_main_load_form, {
SPA: true,
Expand Down Expand Up @@ -82,9 +91,11 @@
if (panel_id) {
is_circuit_number_taken_state.is_circuit_number_taken = await checkNodeExists({
circuit_number: form.data.circuit_number,
parent_id: panel_id,
node_id: load_to_edit?.id
//we want to check if the circuit number is alrdy existing in the parent we want to move in
parent_id: selected_parent_id || panel_id,
node_id: node_to_edit?.id
});
if (is_circuit_number_taken_state.is_circuit_number_taken) {
cancel();
toast.warning('Circuit number already exists');
Expand All @@ -94,24 +105,25 @@
if (load_type) {
const load_description = `${form.data.quantity} - ${form.data.load_description}`;
const loadData = {
const load_data = {
...form.data,
load_description,
config_preference: load_type
};
switch (action) {
case 'add':
await addNode({
load_data: loadData,
load_data,
parent_id: panel_id
});
toast.success(`${load_description} added successfully`);
break;
case 'edit':
if (load_to_edit) {
if (node_to_edit && selected_parent_id) {
await updateNode({
load_data: loadData,
id: load_to_edit.id
load_data,
id: node_to_edit.id,
parent_id: selected_parent_id
});
toast.success('Load updated successfully');
}
Expand Down Expand Up @@ -145,7 +157,7 @@
const load_description_trigger_id = useId();
const horsepower_rating_trigger_id = useId();
let load_type = $state<FormLoadTypeOption | undefined>(
load_to_edit?.load_data?.config_preference as FormLoadTypeOption | undefined
node_to_edit?.load_data?.config_preference as FormLoadTypeOption | undefined
);
// We want to refocus the trigger button when the user selects
Expand All @@ -162,9 +174,12 @@
}
$effect(() => {
if (action !== 'edit') return;
if (action !== 'edit') {
$formData.circuit_number = (latest_circuit_node?.circuit_number ?? 0) + 1;
return;
}
if (!load_to_edit || !load_to_edit.load_data) {
if (!node_to_edit || !node_to_edit.load_data) {
// TODO: Log system error
toast.warning('Failed to identify the load to edit', {
description: 'This is a system error and should not be here, the error has been logged.'
Expand All @@ -175,7 +190,7 @@
const {
circuit_number,
load_data: { load_description, terminal_temperature, load_type, quantity, varies, continuous }
} = load_to_edit;
} = node_to_edit;
$formData.circuit_number = circuit_number as number;
$formData.load_description = load_description.split(' - ')[1];
Expand All @@ -196,16 +211,20 @@
>
</Alert.Root>
{/if}
<div class="grid grid-cols-2 place-items-start justify-between gap-2">
<div class="mt-2 grid grid-cols-2 place-items-start justify-between gap-2">
<Form.Field {form} name="circuit_number">
<Form.Control>
{#snippet children({ props })}
<Form.Label>Circuit number</Form.Label>
<Form.Label
class={cn({ 'text-red': is_circuit_number_taken_state.is_circuit_number_taken })}
>Circuit number</Form.Label
>
<Input
{...props}
type="number"
inputmode="numeric"
min={1}
class={cn({ 'border-red': is_circuit_number_taken_state.is_circuit_number_taken })}
bind:value={$formData.circuit_number}
placeholder="Enter the circuit number"
/>
Expand Down Expand Up @@ -247,19 +266,19 @@
<Command.Input autofocus placeholder="Search a terminal temp..." class="h-9" />
<Command.Empty>No terminal temp found.</Command.Empty>
<Command.Group>
{#each DEFAULT_TERMINAL_TEMPERATURE_OPTIONS as ambient_temp}
{#each DEFAULT_TERMINAL_TEMPERATURE_OPTIONS as terminal_temp}
<Command.Item
value={ambient_temp}
value={terminal_temp}
onSelect={() => {
$formData.terminal_temperature = ambient_temp;
$formData.terminal_temperature = terminal_temp;
closeAndFocusTrigger(terminal_temp_trigger_id);
}}
>
{convertToNormalText(ambient_temp)}
{convertToNormalText(terminal_temp)}
<Check
class={cn(
'ml-auto size-4',
ambient_temp !== $formData.terminal_temperature && 'text-transparent'
terminal_temp !== $formData.terminal_temperature && 'text-transparent'
)}
/>
</Command.Item>
Expand Down
15 changes: 3 additions & 12 deletions src/lib/components/custom/new-file-form.svelte
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
<script module>
import { z } from 'zod';
export const newFileSchema = z.object({
id: z.string().optional(),
file_name: z.string().refine((v) => v, { message: 'An file_name is required.' })
});
export type NewFileSchema = z.infer<typeof newFileSchema>;
</script>

<script lang="ts" generics="T extends SuperValidated<NewFileSchema>">
import { goto } from '$app/navigation';
import { superForm, type SuperValidated } from 'sveltekit-superforms';
Expand All @@ -18,7 +8,8 @@
import { ScrollArea } from '@/components/ui/scroll-area/index.js';
import { Separator } from '@/components/ui/separator/index.js';
import * as Form from '@/components/ui/form/index.js';
import { new_file_schema, type NewFileSchema } from '@/schema';
interface Props {
new_file_form: T;
saved_path?: string;
Expand All @@ -29,7 +20,7 @@
const form = superForm(new_file_form, {
SPA: true,
validators: zodClient(newFileSchema),
validators: zodClient(new_file_schema),
onUpdate: ({ form }) => {
// toast the values
if (form.valid) {
Expand Down
Loading

0 comments on commit 96b135c

Please sign in to comment.