Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@okam/directus-next-component
Advanced tools
This library was generated with Nx.
Create a middleware.ts file in the project, in the /src/app
directory of the next application, and add the following code to it.
// middleware.ts
import {
directusRouteMiddleware,
config as directusRouteMiddlewareConfig,
} from '@okam/directus-next-component/src/server'
import type { NextRequest } from 'next/server'
export function middleware(request: NextRequest) {
const { locale } = request.nextUrl
return directusRouteMiddleware(request, [locale])
}
export const config = {
...directusRouteMiddlewareConfig,
}
After, modify the next.config.js
file to add withDirectus
in the plugins.
The role of the directus link hook is to dispatch different props according to the type of the directus link. The configuration for the dispatching is overridable using the propsConfig
prop
The role of the directus link component is to wrap next/link
and dispatch the props to different components according to a configuration. The configuration for dispatching different components is overridable using the componentsConfig
prop.
The directus link component uses the directus link hook, which means it can be passed both componentsConfig
and propsConfig
for both dispatching uses.
By default, the following are included:
collection
: Render a link using a page_settings
relationanchor
: Render a link pointing to an element's id on the page (always starts with #
)external-link
: Render a link with an external URL (e.g.: https://google.com)file
: Render a link for a downloadable fileThe mentionned configuration can be overwritten by passing a componentsConfig
prop to the directus link component
const overrideConfig = {
'external-link': (props) => <CustomExternalLinkComponent {...props} />
}
const BrandLink = (props) => {
return <DirectusLink config={overrideConfig} {...props} />
}
The useNavigationItems
hook allows to build recursively a navigation structure using the DirectusLink
component.
The tokens passed to link
and linkProps
include also include, in order of priority:
onNavigationItem
type
tokenlink
: A rendered react node of the DirectusLink
componentlinkProps
: The props that were passed to the linkchildren
: The navigation items containing link, linkProps, childrenparent
: A single navigation item containing link, linkProps, parentdepth
: The current depth of the recursion. For each level of parent, the depth will go down by one. For each level of children, the depth will go up by one. The depth starts at zero// Any styling could go here
const depthMap: Record<number, object> = {
0: { backgroundColor: 'red' },
1: { backgroundColor: 'blue' },
2: { backgroundColor: 'green' },
}
// Loop recursively through navigation items and assign style based on depth
function renderTree(tree: Nullable<TNavigationItemsTree>): React.ReactNode {
if (!tree) return null
const { children, link, linkProps, depth } = tree
const style = depthMap[depth]
if (!link && !children) return null
if (!children) {
return (
<li style={style} key={link.id}>
{
/*
* Here, `link` represents a rendered version of `DirectusLink` for quick use
* Use `linkProps` for custom rendering needs
*/
}
{link}
</li>
)
}
return (
<ul key={link.id}>
<li style={style}>{link}</li>
{children.map((child) => renderTree(child))}
</ul>
)
}
const NavigationComponent = (props) => {
// Depth and links type cannot be inferred directly, they must be passed
const navigation = useNavigationItems<3, { link?: LinksFragment }>(
props.navigationItems,
// Use `onNavigationItem` to parse the fragments
(item) => {
const { link } = item ?? {}
const collection = getFragment(PageSettingsFragmentDoc, link?.collection)
const file = getFragment(FilesFragmentDoc, link?.file)
return {
...link,
collection,
file,
}
})
return (
<nav>
{navigation.map((item) => renderTree(item))}
</nav>
)
}
FAQs
This library was generated with [Nx](https://nx.dev).
The npm package @okam/directus-next-component receives a total of 123 weekly downloads. As such, @okam/directus-next-component popularity was classified as not popular.
We found that @okam/directus-next-component demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.