Skip to content

Commit

Permalink
Small improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
loicknuchel committed Sep 30, 2024
1 parent 278671e commit 16bd9c1
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 40 deletions.
26 changes: 24 additions & 2 deletions demos/ecommerce/source_00_design.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ C##INVENTORY.SUPPLIER_PRICES

C##INVENTORY.SUPPLIER_EMPLOYEES
SUPPLIER_ID BIGINT pk -> C##INVENTORY.SUPPLIERS(ID)
EMPLOYEE_ID BIGINT pk -> C##INVENTORY.Employees(ID)
EMPLOYEE_ID BIGINT pk -> C##INVENTORY.EMPLOYEES(ID)
ROLE supplier_role(delivery, sale)
START TIMESTAMP nullable
END TIMESTAMP nullable
Expand Down Expand Up @@ -807,7 +807,24 @@ analytics.Events
name string index | in form of `$context__$object__$action`
source event_source(website, app, admin, job) | the name of the system which emitted this event
details json nullable | any additional info for the event
ip string nullable
amount number nullable
browser string nullable
entities json nullable | {[kind: string]: {id: string, name: string}[]}
user "Object[]" nullable
id string
name string
email string
cart "Object[]" nullable
id string
name string
items number
invoice "Object[]" nullable
id number
name string
lines number
price number
currency string
createdAt timestamp index

rel analytics.Events(entities.user.id) -> identity.Users(id)
Expand All @@ -818,7 +835,12 @@ analytics.Entities
kind string unique="pk"
id string unique="pk"
name string index
properties json
properties json nullable
email string nullable
items number nullable
lines number nullable
price number nullable
currency string nullable
createdAt timestamp
updatedAt timestamp

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Components/Slices/DataExplorer.elm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import PagesComponents.Organization_.Project_.Updates.Extra as Extra exposing (E
import Ports
import Services.Lenses exposing (mapDetailsT, mapFilters, mapResultsT, mapVisualEditor, setOperation, setOperator, setValue)
import Services.Toasts as Toasts
import Services.Urls as Urls
import Track


Expand Down Expand Up @@ -376,7 +377,7 @@ viewSources wrap htmlId sources selectedSource =
, p [] [ text "To add one, open settings (top right cog), click on 'add source' and provide your database url." ]
, p []
[ text "Local databases are accessible with "
, extLink "https://www.npmjs.com/package/azimutt" [ class "link" ] [ text "Azimutt CLI" ]
, extLink Urls.cliNpm [ class "link" ] [ text "Azimutt CLI" ]
, text " ("
, Badge.basic Tw.blue [] [ text "npx azimutt@latest gateway" ] |> Tooltip.t "Starts the Azimutt Gateway on your computer to access local databases."
, text ")."
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/Components/Slices/PlanDialog.elm
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Conf
import ElmBook
import ElmBook.Actions as Actions
import ElmBook.Chapter as Chapter exposing (Chapter)
import Html exposing (Html, a, blockquote, br, button, div, h3, input, label, p, span, text)
import Html exposing (Html, blockquote, br, button, div, h3, input, label, p, span, text)
import Html.Attributes exposing (class, for, href, id, name, placeholder, rel, style, target, title, type_, value)
import Html.Events exposing (onBlur, onClick, onInput)
import Libs.Html exposing (bText, extLink, sendTweet)
Expand All @@ -28,6 +28,7 @@ import Models.ProjectRef as ProjectRef exposing (ProjectRef)
import PagesComponents.Organization_.Project_.Updates.Extra as Extra exposing (Extra)
import Services.Backend as Backend exposing (TableColorTweet)
import Services.Lenses exposing (setColors, setResult)
import Services.Urls as Urls


projectsNoSaveAlert : Organization -> Html msg
Expand All @@ -38,7 +39,7 @@ projectsNoSaveAlert organization =
in
Alert.withDescription { color = color, icon = Icon.Exclamation, title = "Can't save project" }
[ text ("You " ++ organization.plan.name ++ " plan can't save projects (see ")
, extLink Backend.pricingUrl [ class "link" ] [ text "pricing" ]
, extLink Urls.pricing [ class "link" ] [ text "pricing" ]
, text "). "
, br [] []
, text "Please "
Expand Down Expand Up @@ -70,7 +71,7 @@ amlDisabledAlert project =
in
warning color
("Database design not available in " ++ planName project)
[ p [] [ text "Azimutt allows database design with a ", extLink Backend.amlUrl [ class "link" ] [ text "very simple DSL" ], text " called AML, here is how it looks:" ]
[ p [] [ text "Azimutt allows database design with a ", extLink Urls.amlHome [ class "link" ] [ text "very simple DSL" ], text " called AML, here is how it looks:" ]
, p [ class ("whitespace-pre font-mono " ++ Tw.bg_200 color ++ " p-2 my-3 rounded shadow") ]
[ text "users\n id uuid pk\n name varchar\n email varchar unique\n created_at timestamp index\n\n"
, text "posts\n id uuid pk\n title varchar index\n status post_status(draft, published)\n content text nullable\n created_at timestamp index\n created_by uuid fk users.id"
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/PagesComponents/New/Views.elm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import Services.ProjectSource as ProjectSource
import Services.SampleSource as SampleSource
import Services.SqlSource as SqlSource
import Services.Toasts as Toasts
import Services.Urls as Urls
import Shared
import Time
import Url exposing (Url)
Expand Down Expand Up @@ -149,7 +150,7 @@ viewTabContent htmlId zone projects urlOrganization model =
viewDatabaseSourceTab : HtmlId -> HtmlId -> Maybe OrganizationId -> List ProjectInfo -> DatabaseSource.Model Msg -> Html Msg
viewDatabaseSourceTab htmlId openedCollapse urlOrganization projects model =
div []
[ viewHeading "Extract your database schema" [ text "Browsers can't connect to databases, schema extraction is done through a proxy, Azimutt Gateway or ", extLink "https://www.npmjs.com/package/azimutt" [ class "link" ] [ text "CLI" ], text ". Nothing is stored." ]
[ viewHeading "Extract your database schema" [ text "Browsers can't connect to databases, schema extraction is done through a proxy, Azimutt Gateway or ", extLink Urls.cliNpm [ class "link" ] [ text "CLI" ], text ". Nothing is stored." ]
, div [ class "mt-6" ] [ DatabaseSource.viewInput DatabaseSourceMsg htmlId model ]
, div [ class "mt-3" ] [ viewDataPrivacyCollapse htmlId openedCollapse ]
, DatabaseSource.viewParsing DatabaseSourceMsg model
Expand Down Expand Up @@ -194,7 +195,7 @@ viewJsonSourceTab htmlId openedCollapse urlOrganization projects model =
viewEmptyProjectTab : Html Msg
viewEmptyProjectTab =
div []
[ viewHeading "Create a new project" [ text "When you don't want to import a schema, just create it in Azimutt using ", extLink "https://github.com/azimuttapp/azimutt/blob/main/libs/aml/docs/README.md" [ class "link" ] [ text "AML" ], text "." ]
[ viewHeading "Create a new project" [ text "When you don't want to import a schema, just create it in Azimutt using ", extLink Urls.amlDocs [ class "link" ] [ text "AML" ], text "." ]
, div [ css [ "mt-20" ] ]
[ div [ css [ "flex justify-center" ] ]
[ Button.primary5 Tw.primary [ onClick (CreateEmptyProject Conf.constants.newProjectName), id "create-project-btn", css [ "ml-3" ] ] [ text "Create new project!" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ import PagesComponents.Organization_.Project_.Updates.Extra as Extra exposing (E
import PagesComponents.Organization_.Project_.Updates.Table exposing (hideTable, showColumns, showTable)
import PagesComponents.Organization_.Project_.Updates.Utils exposing (setDirty, setDirtyM)
import Ports
import Services.Backend as Backend
import Services.Lenses exposing (mapAmlSidebarM, mapAmlSidebarMTM, mapErdM, mapErdMT, mapSelectedMT, setAmlSidebar, setContent, setErrors, setSelected, setUpdatedAt)
import Services.Urls as Urls
import Set exposing (Set)
import Time
import Track
Expand Down Expand Up @@ -257,7 +257,7 @@ viewHeading =
]
, p [ class "mt-1 text-sm text-gray-500" ]
[ text "In Azimutt your schema is the union of all active sources. Create or update one with "
, extLink "https://github.com/azimuttapp/azimutt/blob/main/libs/aml/docs/README.md" [ class "link" ] [ text "AML syntax" ]
, extLink Urls.amlDocs [ class "link" ] [ text "AML syntax" ]
, text " to extend it."
]
]
Expand Down Expand Up @@ -326,7 +326,22 @@ fk credentials.role -> roles.slug""" 30 (List.nonEmpty errors)
viewErrors : List String -> Html msg
viewErrors errors =
div []
(errors |> List.map (\err -> p [ class "mt-2 text-sm text-red-600" ] [ text err ]))
((if errors |> List.nonEmpty then
div [ class "mt-2 text-sm text-gray-500" ]
[ text "Issues with AML? Try our "
, extLink Urls.amlEditor [ class "link" ] [ text "online editor" ]
, text " or check the "
, extLink Urls.amlDocs [ class "link" ] [ text "documentation" ]
, text "."
, br [] []
, text "(We are working to bring the editor here but have issues with Elm, Web Components & Monaco Editor, contact us if you can help 😉)"
]

else
div [] []
)
:: (errors |> List.map (\err -> p [ class "mt-2 text-sm text-red-600" ] [ text err ]))
)


viewWarnings : List String -> Html msg
Expand All @@ -337,7 +352,7 @@ viewWarnings warnings =
[ text "Oh! It seems you are using the legacy AML syntax 😅"
, br [] []
, text "Fix it easily with "
, extLink Backend.amlv1ConverterUrl [ class "link" ] [ text "our converter tool" ]
, extLink Urls.amlV1Converter [ class "link" ] [ text "our converter tool" ]
, text " 🪄"
]

Expand All @@ -352,6 +367,6 @@ viewHelp : Html msg
viewHelp =
p [ class "mt-2 text-sm text-gray-500" ]
[ text "Write your schema using "
, extLink "https://github.com/azimuttapp/azimutt/blob/main/libs/aml/docs/README.md" [ class "link" ] [ text "AML syntax" ]
, extLink Urls.amlDocs [ class "link" ] [ text "AML syntax" ]
, text "."
]
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import PagesComponents.Organization_.Project_.Views.Erd.Table as Table exposing
import PagesComponents.Organization_.Project_.Views.Erd.TableRow as TableRow exposing (viewTableRow)
import PagesComponents.Organization_.Project_.Views.Modals.ErdContextMenu as ErdContextMenu
import PagesComponents.Organization_.Project_.Views.Modals.GroupContextMenu as GroupContextMenu
import Services.Urls as Urls
import Set exposing (Set)
import Time

Expand Down Expand Up @@ -415,7 +416,7 @@ viewEmptyState defaultSchema tables =
, if tables |> Dict.isEmpty then
p [ class "mt-3 text-sm text-gray-500" ]
[ text "Azimutt allows you to create and explore your database schema. Start writing your schema using "
, extLink "https://github.com/azimuttapp/azimutt/blob/main/libs/aml/docs/README.md" [ class "link" ] [ text "AML syntax" ]
, extLink Urls.amlDocs [ class "link" ] [ text "AML syntax" ]
, text " or import and explore your schema. Add any source (database url, SQL or JSON) in project settings (top right "
, Icon.outline Icon.Cog "h-5 w-5 inline"
, text ")."
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Services/AmlSource.elm
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Models.Project.SourceId as SourceId exposing (SourceId)
import Models.ProjectInfo exposing (ProjectInfo)
import PagesComponents.Organization_.Project_.Updates.Extra as Extra exposing (Extra)
import Random
import Services.Urls as Urls
import Time
import Track

Expand Down Expand Up @@ -78,7 +79,7 @@ viewInput wrap htmlId model =
div []
[ p [ class "mt-1 text-sm text-gray-500" ]
[ text "AML means "
, extLink "https://github.com/azimuttapp/azimutt/blob/main/libs/aml/docs/README.md" [ class "link" ] [ text "Azimutt Markup Language" ]
, extLink Urls.amlDocs [ class "link" ] [ text "Azimutt Markup Language" ]
, text ", it's our very simple language allowing you to define your own schema in Azimutt."
]
, label [ for fieldId, class "mt-1 block text-sm font-medium text-gray-700" ] [ text "Source name" ]
Expand Down
17 changes: 1 addition & 16 deletions frontend/src/Services/Backend.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Services.Backend exposing (Error, Sample, SampleSchema, TableColorTweet, amlUrl, amlv1ConverterUrl, blogArticleUrl, blogUrl, createProjectToken, embedUrl, errorStatus, errorToString, getCurrentUser, getOrganizationsAndProjects, getProjectTokens, getSamples, getTableColorTweet, homeUrl, internal, loginUrl, logoutUrl, organizationBillingUrl, organizationUrl, pricingUrl, resourceUrl, revokeProjectToken)
module Services.Backend exposing (Error, Sample, SampleSchema, TableColorTweet, blogArticleUrl, blogUrl, createProjectToken, embedUrl, errorStatus, errorToString, getCurrentUser, getOrganizationsAndProjects, getProjectTokens, getSamples, getTableColorTweet, homeUrl, internal, loginUrl, logoutUrl, organizationBillingUrl, organizationUrl, resourceUrl, revokeProjectToken)

import Components.Atoms.Icon as Icon exposing (Icon)
import Either exposing (Either(..))
Expand Down Expand Up @@ -74,21 +74,6 @@ dashboardUrl =
"/home"


pricingUrl : String
pricingUrl =
"/pricing"


amlUrl : String
amlUrl =
"/aml"


amlv1ConverterUrl : String
amlv1ConverterUrl =
"/converters/amlv1/to/aml"


organizationUrl : Maybe OrganizationId -> String
organizationUrl organization =
organization |> Maybe.filter (\id -> id /= OrganizationId.zero) |> Maybe.mapOrElse (\id -> "/organizations/" ++ id) dashboardUrl
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/Services/DatabaseSource.elm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Random
import Services.Backend as Backend
import Services.Lenses exposing (mapShow)
import Services.SourceLogs as SourceLogs
import Services.Urls as Urls
import Time
import Track

Expand Down Expand Up @@ -226,7 +227,7 @@ viewInput wrap htmlId model =
[ Alert.simple Tw.blue
Icon.QuestionMarkCircle
[ text "Access databases from your computer using "
, extLink "https://www.npmjs.com/package/azimutt" [ class "link" ] [ text "Azimutt CLI" ]
, extLink Urls.cliNpm [ class "link" ] [ text "Azimutt CLI" ]
, text " (install "
, extLink "https://docs.npmjs.com/downloading-and-installing-node-js-and-npm" [ class "link" ] [ text "npm" ]
, text " & run "
Expand Down
31 changes: 31 additions & 0 deletions frontend/src/Services/Urls.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Services.Urls exposing (amlDocs, amlEditor, amlHome, amlV1Converter, cliNpm, pricing)


amlHome : String
amlHome =
"/aml"


amlDocs : String
amlDocs =
"https://github.com/azimuttapp/azimutt/blob/main/libs/aml/docs/README.md"


amlEditor : String
amlEditor =
"/converters/aml/to/json"


amlV1Converter : String
amlV1Converter =
"/converters/amlv1/to/aml"


cliNpm : String
cliNpm =
"https://www.npmjs.com/package/azimutt"


pricing : String
pricing =
"/pricing"
5 changes: 4 additions & 1 deletion libs/aml/src/amlParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,10 @@ class AmlParser extends EmbeddedActionsParser {
const extra = $.SUBRULE($.extraRule)
$.CONSUME(NewLine)
const attrs: AttributeAstFlat[] = []
$.MANY(() => attrs.push($.SUBRULE($.attributeRule)))
$.MANY(() => {
const attr = $.SUBRULE($.attributeRule)
if (attr.name?.value) attrs.push(attr) // name can be '' on invalid input :/
})
return removeEmpty({statement: 'Entity' as const, name: entity, view: view ? tokenInfo(view) : undefined, ...namespace, alias, ...extra, attrs: nestAttributes(attrs)})
})

Expand Down
13 changes: 6 additions & 7 deletions libs/models/src/legacy/legacyDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export type LegacyColumnDbStats = z.infer<typeof LegacyColumnDbStats>
export type LegacyColumn = {
name: LegacyColumnName
type: LegacyColumnType
nullable?: boolean | null
default?: LegacyColumnValue | null
comment?: string | null
values?: string[] | null
columns?: LegacyColumn[] | null
stats?: LegacyColumnDbStats | null
nullable?: boolean | null | undefined
default?: LegacyColumnValue | null | undefined
comment?: string | null | undefined
values?: string[] | null | undefined
columns?: LegacyColumn[] | null | undefined
stats?: LegacyColumnDbStats | null | undefined
}
export const LegacyColumn: z.ZodType<LegacyColumn> = z.object({
name: LegacyColumnName,
Expand Down Expand Up @@ -443,7 +443,6 @@ function typeToLegacy(t: Type): LegacyType {
}
}


export function legacyDatabaseJsonFormat(database: LegacyDatabase): string {
return stringify(database, (path: (string | number)[], value: any) => {
const last = path[path.length - 1]
Expand Down

0 comments on commit 16bd9c1

Please sign in to comment.