-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from galadrimteam/folders
Folders
- Loading branch information
Showing
20 changed files
with
557 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
interface ApiViewBase { | ||
label: string | ||
isHidden: boolean | ||
fullPath: string | ||
visibilityCheckPassed: boolean | ||
name: string | ||
/** | ||
* Icon name, by default this uses Tabler icons | ||
* | ||
* You can browse the list of available icons at: | ||
* https://tabler.io/icons | ||
*/ | ||
icon?: string | ||
} | ||
|
||
export interface ApiModelView extends ApiViewBase { | ||
type: 'model' | ||
labelPluralized: string | ||
} | ||
|
||
export interface ApiStatView extends ApiViewBase { | ||
type: 'stats' | ||
} | ||
|
||
export interface ApiFolderView extends ApiViewBase { | ||
type: 'folder' | ||
views: ApiAdominView[] | ||
} | ||
|
||
export type ApiAdominView = ApiModelView | ApiStatView | ApiFolderView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { AdominViewConfig } from './adomin_config.types.js' | ||
import type { AdominRightsCheckFunction } from './routes/adomin_routes_overrides_and_rights.js' | ||
|
||
export interface FolderViewConfig { | ||
type: 'folder' | ||
/** | ||
* Title of the folder, displayed in the sidebar | ||
*/ | ||
label: string | ||
/** | ||
* Used to determine the path in the frontend | ||
* | ||
* e.g. if name = 'test', full path on the frontend will be /adomin/folders/test | ||
*/ | ||
name: string | ||
/** | ||
* Each object in the array represents a view in the folder (which can be a model, a folder or a stats view) | ||
*/ | ||
views: AdominViewConfig[] | ||
/** Check if logged in user can see this folder */ | ||
visibilityCheck?: AdominRightsCheckFunction | ||
/** | ||
* If true, the view will be hidden on the frontend (but still accessible if you know the path) | ||
* | ||
* if you want to restrict access to a view, use the `visibilityCheck` property | ||
*/ | ||
isHidden?: boolean | ||
/** | ||
* Icon name, by default this uses Tabler icons | ||
* | ||
* You can browse the list of available icons at: | ||
* https://tabler.io/icons | ||
*/ | ||
icon?: string | ||
} | ||
|
||
export type FolderViewConfigStaticOptions = Omit<FolderViewConfig, 'type'> | ||
|
||
export const createFolderViewConfig = ( | ||
options: FolderViewConfigStaticOptions | ||
): FolderViewConfig => { | ||
const { name, label, visibilityCheck, views, isHidden, icon } = options | ||
|
||
return { | ||
type: 'folder', | ||
name, | ||
label, | ||
visibilityCheck, | ||
views, | ||
isHidden, | ||
icon, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import type { AdominViewConfig } from './adomin_config.types.js' | ||
import { ADOMIN_CONFIG } from './config/adomin_config.js' | ||
|
||
export const flattenViews = (views: AdominViewConfig[]): AdominViewConfig[] => { | ||
const flatViews = views.flatMap((view) => { | ||
if (view.type === 'folder') return flattenViews(view.views) | ||
|
||
return view | ||
}) | ||
|
||
return flatViews | ||
} | ||
|
||
export const getFlatViews = () => { | ||
return flattenViews(ADOMIN_CONFIG.views) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.