Code Monkey home page Code Monkey logo

cosmo-cloud's Introduction

Completed Tasks (According to guidelines)

  1. Schema design
  2. Add field
  3. Edit field name
  4. Edit field type
  5. Nested fields for type object.
  6. Update is required flag

Some assumptions that i made :

  1. No limit for nesting. Currently we can create infinite amount of nested objects
  2. If a field's type is changed from "object" to something else, it looses all its nested object.

Third party libraries used:

  1. Chakra-UI for components

Schema

Schema for this component is an array of objects. (kinda like a n-ary tree). Single object looks something like this :

{ id: uuid, name: string, type: string, isRequired: boolean children?: IField }

Eg. Schema :

[
    {
      id: uuidv4(),
      name: "id",
      type: "number",
      isRequired: false
    },
    {
      id: uuidv4(),
      name: "person",
      type: "object",
      isRequired: false,
      children: [
        {
          id: uuidv4(),
          name: "name",
          type: "string",
          isRequired: false
        },
        {
          id: uuidv4(),
          name: "location",
          type: "object",
          isRequired: false,
          children: [
            {
              id: uuidv4(),
              name: "state",
              type: "string",
              isRequired: false
            }
          ]
        }
      ]
    }

Component Structure

  • FieldTree
    • FieldGroup
      • Field
        • FieldInfo
      • Field
        • FieldInfo
      • Field
        • FieldInfo
        • FieldGroup (for nested groups)

Component Architectures

  1. FieldTree
  • fields: IField[]
  • updateFields: (fields: IField[]) => void
  1. Field
  • updateFieldName: (id) => void
  • updateFieldType: (id, newType) => void
  • removeField: (id) => void
  • toggleIsRequired: (id) => void
  • addNewField: (id) => void
  • field: IField
  • depth?: number
  1. FieldGroup
  • updateFieldName: (id) => void
  • updateFieldType: (id, newType) => void
  • removeField: (id) => void
  • toggleIsRequired: (id) => void
  • addNewField: (id) => void
  • fields: IField[]
  1. FieldInfo
  • updateFieldName: (id) => void
  • updateFieldType: (id, newType) => void
  • removeField: (id) => void
  • toggleIsRequired: (id) => void
  • addNewField: (id) => void
  • fields: IField

Where,

IField: { id: number, name: string, type: enum, children?: IField[] }

Thought process behing architecture: I really don't want the users to write their own CRUD operations, that is going to involve recursive traversing through the state. That lead to the idea of hiding these functions from users, and only allowing them to pass in the intital field value and the field updater function to the FieldTree component (root component). Thereby taking away a lot of pain for reusing the component.

How to see the configuration behind the UI?

I have added a <pre> tag in the index.jsx (in FieldTree folder). It will render the configuration as you make changes in the UI. I didn't implement the save button. (one less click!)

Things that I feel is bad

  1. UI looks are okay-ish. (Since I had to spent some time for the actual logic for CRUD operations)

Thank you for considering my application, Have a nice day :)

cosmo-cloud's People

Contributors

adwaithks avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.