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

Add types to constant node #171

Merged
merged 11 commits into from
Nov 16, 2024
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
6 changes: 3 additions & 3 deletions copperc/src/app/u/datasets/_modals/addattribute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useMutation } from "@tanstack/react-query";
import { edgeclient } from "@/lib/api/client";
import { components } from "@/lib/api/openapi";
import { ReactElement, useState } from "react";
import { DataType, dataTypes, getAttrTypeInfo } from "@/lib/attributes";
import { AttrDataType, attrDataTypes, getAttrTypeInfo } from "@/lib/attributes";

export function useAddAttributeModal(params: {
dataset_id: number;
Expand All @@ -20,7 +20,7 @@ export function useAddAttributeModal(params: {
response: string | null;
}>({ type: null, response: null });

const [newAttrType, setNewAttrType] = useState<DataType | null>(null);
const [newAttrType, setNewAttrType] = useState<AttrDataType | null>(null);

// Get input ui for attr-specific parameters
let NewAttrForm:
Expand Down Expand Up @@ -101,7 +101,7 @@ export function useAddAttributeModal(params: {
<Select
required={true}
placeholder={"select attribute type"}
data={dataTypes.map((x) => {
data={attrDataTypes.map((x) => {
const attrdef = getAttrTypeInfo(x);
return {
label: attrdef.pretty_name,
Expand Down
125 changes: 71 additions & 54 deletions copperc/src/app/u/items/_panels/controlpanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ export function ControlPanel(params: {
// outside of this component, or if `selectedClass` doesn't
// initialize as `null`.
selectedClass: components["schemas"]["ClassInfo"] | null;

setSelectedClass: (
new_class: components["schemas"]["ClassInfo"] | null,
) => void;

setSelectedDataset: (
new_dataset: components["schemas"]["DatasetInfo"] | null,
) => void;
}) {
const [selectedDataset, setSelectedDataset] = useState<number | null>(null);

Expand Down Expand Up @@ -95,64 +100,76 @@ export function ControlPanel(params: {
return (
<div className={styles.panel} style={{ width: "20rem" }}>
<TitleBar text="Control panel" />
<div className={styles.panel_content}>
<Select
label="Select dataset"
style={{ width: "100%" }}
disabled={datasets.data === undefined}
placeholder={
datasets.data === undefined ? "Loading..." : "Select a dataset"
}
data={dataset_data}
value={selectedDataset === null ? null : selectedDataset.toString()}
onChange={(value) => {
const int = value === null ? null : parseInt(value);
if (int === selectedDataset) {
return;
}

if (int === null || datasets.data === undefined) {
setSelectedDataset(null);
params.setSelectedClass(null);
return;
}

setSelectedDataset(int);
params.setSelectedClass(null);
}}
/>

<Select
label="Select class"
style={{ width: "100%" }}
disabled={datasets.data === undefined}
placeholder={
datasets.data === undefined ? "Loading..." : "Select a class"
}
data={class_data}
value={
params.selectedClass === null
? null
: params.selectedClass.id.toString()
}
onChange={(value) => {
const int = value === null ? null : parseInt(value);
if (int === params.selectedClass) {
return;
<div
style={{
overflowY: "scroll",
marginTop: "1rem",
}}
>
{/* TODO: clean up, `style` shouldn't be necessary here */}
<div className={styles.panel_content} style={{ padding: 0 }}>
<Select
label="Select dataset"
style={{ width: "100%" }}
disabled={datasets.data === undefined}
placeholder={
datasets.data === undefined ? "Loading..." : "Select a dataset"
}

if (int === null || datasets.data === undefined) {
data={dataset_data}
value={selectedDataset === null ? null : selectedDataset.toString()}
onChange={(value) => {
const int = value === null ? null : parseInt(value);
if (int === selectedDataset) {
return;
}

if (int === null || datasets.data === undefined) {
setSelectedDataset(null);
params.setSelectedClass(null);
params.setSelectedDataset(null);
return;
}

setSelectedDataset(int);
params.setSelectedClass(null);
return;
params.setSelectedDataset(null);
}}
/>

<Select
label="Select class"
style={{ width: "100%" }}
disabled={datasets.data === undefined}
placeholder={
datasets.data === undefined ? "Loading..." : "Select a class"
}

const c = datasets.data
.find((x) => x.id === selectedDataset)!
.classes.find((x) => x.id === int)!;

params.setSelectedClass(c);
}}
/>
data={class_data}
value={
params.selectedClass === null
? null
: params.selectedClass.id.toString()
}
onChange={(value) => {
const int = value === null ? null : parseInt(value);
if (int === params.selectedClass) {
return;
}

if (int === null || datasets.data === undefined) {
params.setSelectedClass(null);
params.setSelectedDataset(null);
return;
}

const d = datasets.data.find((x) => x.id === selectedDataset)!;
const c = d.classes.find((x) => x.id === int)!;

params.setSelectedClass(c);
params.setSelectedDataset(d);
}}
/>
</div>
</div>
</div>
);
Expand Down
37 changes: 27 additions & 10 deletions copperc/src/app/u/items/_panels/edit.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,42 @@
display: flex;
flex-direction: row;
align-items: first baseline;
align-items: stretch;
justify-self: start;
gap: 4rem;
justify-content: space-between;
gap: 2rem;

width: 100%;
height: 100%;
padding-bottom: 2rem;
}

.attr_container {
display: flex;
flex-direction: column;
.attr_container_scroll {
flex-grow: 1;
max-width: 80rem;

max-height: 100%;
overflow: scroll;
overflow-y: scroll;
padding-left: 0.5rem;
padding-right: 1rem;
padding-top: 0.5rem;
padding-bottom: 2rem;
}

.attr_container {
display: flex;
flex-direction: column;

.attr_row {
display: flex;
flex-direction: row;
overflow: hidden;
background-color: var(--mantine-color-dark-9);
min-height: 3rem;
min-height: min-content;
max-height: 10rem;

.row_icon {
width: 2rem;
min-height: 100%;
background-color: var(--mantine-primary-color-8);
display: flex;
align-items: center;
Expand All @@ -41,7 +51,6 @@
justify-content: center;

width: 10rem;
min-height: 100%;
padding: 0.25rem;
background-color: var(--mantine-color-dark-8);
user-select: none;
Expand All @@ -67,7 +76,12 @@
.row_value_new {
display: flex;
flex-direction: column;
justify-content: center;

// hmm, justify-content is weird.
// we have it in value_old but not here
// because this column is usually taller.
//
// That's a hack, though.

padding: 0.25rem;
overflow-x: scroll;
Expand All @@ -84,7 +98,10 @@
vertical-align: top;
flex-direction: column;

width: 30%;
// min-width so that `attr_container` doesn't steal
// width from the panel. Could also set `flex-shrink: 0`.
min-width: 30%;

height: 100%;

border-style: solid;
Expand Down
Loading
Loading