Skip to content

Syntax Lookup: Put deprecated constructs to the end of a section and … #834

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

Merged
merged 1 commit into from
Mar 29, 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
1 change: 1 addition & 0 deletions misc_docs/syntax/decorator_obj.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ keywords: ["obj", "decorator"]
name: "@obj"
summary: "This is the `@obj` decorator."
category: "decorators"
status: "deprecated"
---


Expand Down
1 change: 1 addition & 0 deletions misc_docs/syntax/operators_triangle_pipe.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ keywords: [pipe", "triangle", "operator", "function", "argument"]
name: "|>"
summary: "This is the `triangle pipe` operator."
category: "operators"
status: "deprecated"
---

The `|>` operator passes a value to a function as its last argument.
Expand Down
75 changes: 57 additions & 18 deletions src/SyntaxLookup.res
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,43 @@ module Category = {
}
}

// The data representing a syntax construct
// handled in the widget
type item = {
id: string,
keywords: array<string>,
name: string,
summary: string,
category: Category.t,
children: React.element,
module Status = {
type t =
| Active
| Deprecated

let fromString = (s: string): t =>
switch s {
| "deprecated" => Deprecated
| "active" | _ => Active
}

let compare = (a, b) =>
switch (a, b) {
| (Deprecated, Deprecated) | (Active, Active) => 0
| (Active, Deprecated) => -1
| (Deprecated, Active) => 1
}
}

module Item = {
// The data representing a syntax construct
// handled in the widget
type t = {
id: string,
keywords: array<string>,
name: string,
summary: string,
category: Category.t,
children: React.element,
status: Status.t,
}

let compare = (a, b) =>
switch Status.compare(a.status, b.status) {
| 0 => String.compare(a.name, b.name)
| x => x
}
}

type itemInfo = {
Expand All @@ -59,6 +87,7 @@ type itemInfo = {
name: string,
summary: string,
category: Category.t,
status: Status.t,
}

let getAnchor = path => {
Expand All @@ -70,8 +99,13 @@ let getAnchor = path => {

module Tag = {
@react.component
let make = (~text: string) => {
<span className="hover:bg-fire hover:text-white bg-fire-5 py-1 px-3 rounded text-fire text-16">
let make = (~deprecated: bool, ~text: string) => {
<span
className={`
py-1 px-3 rounded text-16
${deprecated
? "hover:bg-gray-30 bg-gray-50 text-gray-80 line-through"
: "hover:bg-fire hover:text-white bg-fire-5 text-fire"}`}>
{React.string(text)}
</span>
}
Expand Down Expand Up @@ -104,8 +138,8 @@ module DetailBox = {

type state =
| ShowAll
| ShowFiltered(string, array<item>) // (search, filteredItems)
| ShowDetails(item)
| ShowFiltered(string, array<Item.t>) // (search, filteredItems)
| ShowDetails(Item.t)

@val @scope("window")
external scrollTo: (int, int) => unit = "scrollTo"
Expand All @@ -122,21 +156,26 @@ let decode = (json: Js.Json.t) => {
let name = json->(field("name", string, _))
let summary = json->(field("summary", string, _))
let category = json->field("category", string, _)->Category.fromString
let status =
json
->optional(field("status", string, _), _)
->Belt.Option.mapWithDefault(Status.Active, Status.fromString)

{
id,
keywords,
name,
summary,
category,
status,
}
}

let default = (props: props) => {
let {mdxSources} = props

let allItems = mdxSources->Js.Array2.map(mdxSource => {
let {id, keywords, category, summary, name} = decode(mdxSource.frontmatter)
let {id, keywords, category, summary, name, status} = decode(mdxSource.frontmatter)

let children =
<MdxRemote
Expand All @@ -146,7 +185,7 @@ let default = (props: props) => {
components={MarkdownComponents.default}
/>

{id, keywords, category, summary, name, children}
{Item.id, keywords, category, summary, name, status, children}
})

let fuseOpts = Fuse.Options.t(
Expand All @@ -160,7 +199,7 @@ let default = (props: props) => {
(),
)

let fuse: Fuse.t<item> = Fuse.make(allItems, fuseOpts)
let fuse: Fuse.t<Item.t> = Fuse.make(allItems, fuseOpts)

let router = Next.Router.useRouter()
let (state, setState) = React.useState(_ => ShowAll)
Expand Down Expand Up @@ -267,14 +306,14 @@ let default = (props: props) => {
} else {
let children =
items
->Belt.SortArray.stableSortBy((v1, v2) => String.compare(v1.name, v2.name))
->Belt.SortArray.stableSortBy(Item.compare)
->Belt.Array.map(item => {
let onMouseDown = evt => {
ReactEvent.Mouse.preventDefault(evt)
onSearchValueChange(item.name)
}
<span className="mr-2 mb-2 cursor-pointer" onMouseDown key=item.name>
<Tag text={item.name} />
<Tag text={item.name} deprecated={item.status == Deprecated} />
</span>
})
let el =
Expand Down
Loading