Possible fix: normalize folder names

folders
Rick Carlino 2019-11-25 10:08:51 -06:00
parent 91c9c6d2f7
commit c88abc010e
3 changed files with 80 additions and 99 deletions

View File

@ -0,0 +1,74 @@
import { Color } from "farmbot/dist/corpus";
interface SFile { uuid: string; }
interface FolderNode {
name: string;
content: SFile[];
color?: Color;
open?: boolean;
}
/** A top-level directory */
interface FolderNodeInitial extends FolderNode {
kind: "initial";
children: (FolderNodeMedial | FolderNodeTerminal)[];
}
/** A mid-level directory. */
interface FolderNodeMedial extends FolderNode {
kind: "medial";
children: FolderNodeTerminal;
}
/** A leaf node on the directory tree.
* Never has a child */
interface FolderNodeTerminal extends FolderNode {
kind: "terminal";
children?: never[];
}
export interface RootFolderNode {
folders: FolderNodeInitial[];
}
/** === THIS WILL LIVE ON THE API === */
interface FlatNode {
id: number;
name_id: number;
color: Color;
sequence_ids: number[];
}
/** === THIS WILL LIVE ON THE API === */
interface FlatNodeName {
id: number;
value: string;
parent_id: undefined | number;
}
export const MOCKUP_SEQUENCES: Record<number, string> = {
1: "Another sequence",
2: "Some random sequence",
3: "Planting seeds",
4: "Purple rain",
5: "Make it rain",
};
export const MOCKUP_NODE_NAMES: FlatNodeName[] = [
{ id: 1, value: "Water stuff", parent_id: undefined },
{ id: 2, value: "Folder for growing things", parent_id: undefined },
{ id: 3, value: "subfolder", parent_id: 2 },
{ id: 4, value: "tests", parent_id: undefined }
];
export const MOCKUP_FLAT_NODES: FlatNode[] = [
{ id: 1, name_id: 1, color: "red", sequence_ids: [] },
{ id: 1, name_id: 2, color: "red", sequence_ids: [] },
{ id: 1, name_id: 3, color: "red", sequence_ids: [5, 4] },
{ id: 1, name_id: 4, color: "red", sequence_ids: [] },
];
export const MOCKUP_TREE: RootFolderNode = {
folders: []
};

View File

@ -0,0 +1,4 @@
export function ingest(_folders: FlatNode[], _names: FlatNodeName[]): RootFolderNode {
return { folders: [] };
}

View File

@ -1,69 +1,5 @@
import React from "react";
interface SFile {
uuid: string;
}
interface SFolder {
name: string;
content: SFile[];
color?: "red" | "blue"; // Stub for now.
open?: boolean;
}
/** A top-level directory */
interface SFolderInitial extends SFolder {
kind: "initial";
children: (SFolderMedial | SFolderTerminal)[];
}
/** A mid-level directory. */
interface SFolderMedial extends SFolder {
kind: "medial";
children: SFolderTerminal;
}
/** A leaf node on the directory tree.
* Never has a child */
interface SFolderTerminal extends SFolder {
kind: "terminal";
children?: never[];
}
export interface SFolderGroup { folders: SFolderInitial[]; }
export const JUST_LIKE_RORYS_MOCKUP: SFolderGroup = {
folders: [
{
kind: "initial",
name: "water schtuff",
content: [],
open: false,
children: [{ kind: "terminal", name: "bar", content: [] }]
},
{
kind: "initial",
name: "Folder for Growing Things",
content: [],
open: false,
children: [
{
kind: "terminal",
name: "bar",
content: []
}
]
},
{
kind: "initial",
name: "Planting Seeds",
content: [],
open: false,
children: [{ kind: "terminal", name: "bar", content: [] }]
},
]
};
export const createFolder = () => Promise.resolve({});
export const deleteFolder = () => Promise.resolve({});
export const saveFolder = () => Promise.resolve({});
@ -74,41 +10,6 @@ export const moveFolder = () => Promise.resolve({});
export const toggleFolder = () => Promise.resolve({});
export const searchByNameOrFolder = () => Promise.resolve({});
// QUESTIONS:
// * How will we handle local (unsaved) updates?
// * How will this affect auto-sync?
// PROBLEMS:
// * We can't just add a "sort_order"
// * 1 drag/drop operation === 40 auto_sync messages
// * Can't put unsaved sequences into folders.
// SOLUTIONS:
// * JSON map:
// {
// lock_id: 12345,
// names: {
// "baz.foo.bar": 1,
// "baz": 2,
// },
// meta: {
// 1: { color: "red", sequence_ids: [4, 5] },
// 2: { color: "blue", sequence_ids: [9] }
// }
// };
// * "Materialized path" on sequence resource as attribute.
// Eg: "directory_path: 'foo.bar.baz.0'"
// *
// Search function should also search folder names
// Folders without any matching items should not be shown in search results
// When searching, folders should be opened to display the matching items
// Folder open/closed state should be reset upon page reload, but maintained during an app session
// Folders can be nested up to... 3 levels deep?
// Folders can only be deleted if empty
// All items in the list have a user-customizable ordering
// New folders and new sequences are added to the bottom of the list
export class ScratchPad extends React.Component<{}, {}> {
render() {
@ -116,6 +17,8 @@ export class ScratchPad extends React.Component<{}, {}> {
<br />
<br />
<br />
<input placeholder="Search..." />
<button>Create Folder</button>
Hey!
</div>;
}