Skip to content

Commit

Permalink
added isShown to page props
Browse files Browse the repository at this point in the history
  • Loading branch information
acamara2016 committed Sep 23, 2022
1 parent 001a614 commit 94ff387
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 126 deletions.
12 changes: 6 additions & 6 deletions src/frontend/components/actions/action.props.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Dispatch, SetStateAction } from 'react'
import { ActionJSON, RecordJSON, ResourceJSON } from '../../interfaces'
import { ActionJSON, RecordJSON, ResourceJSON, PageJSON } from '../../interfaces'

/**
* Props which are passed to all action components
Expand All @@ -10,23 +10,23 @@ export type ActionProps = {
/**
* Action object describing the action
*/
action: ActionJSON;
action: ActionJSON
/**
* Object of type: {@link ResourceJSON}
*/
resource: ResourceJSON;
resource: ResourceJSON
/**
* Selected record. Passed for actions with "record" actionType
*/
record?: RecordJSON;
record?: RecordJSON

/**
* Selected records. Passed for actions with "bulk" actionType
*/
records?: Array<RecordJSON>;
records?: Array<RecordJSON>

/**
* Sets tag in a header of an action. It is a function taking tag as an argument
*/
setTag?: Dispatch<SetStateAction<string>>;
setTag?: Dispatch<SetStateAction<string>>
}
265 changes: 145 additions & 120 deletions src/frontend/store/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
DROP_NOTICE,
ADD_NOTICE,
ROUTE_CHANGED,
INITIAL_ROUTE } from './actions'
INITIAL_ROUTE,
} from './actions'

import { Assets, BrandingOptions, VersionProps } from '../../adminjs-options.interface'
import { PageJSON, ResourceJSON } from '../interfaces'
Expand All @@ -27,199 +28,223 @@ import { Locale } from '../../locale/config'
import { NoticeMessage } from '../hoc/with-notice'

export type DashboardInState = {
component?: string;
component?: string
}

export type NoticeMessageInState = NoticeMessage & {
message: string;
id: string;
type: NoticeMessage['type'];
progress: number;
message: string
id: string
type: NoticeMessage['type']
progress: number
}

export type Paths = {
rootPath: string;
logoutPath: string;
loginPath: string;
assetsCDN?: string;
rootPath: string
logoutPath: string
loginPath: string
assetsCDN?: string
}

const resourcesReducer = (
state: Array<ResourceJSON> = [],
action: {
type: string;
data: Array<ResourceJSON>;
},
type: string
data: Array<ResourceJSON>
}
) => {
switch (action.type) {
case RESOURCES_INITIALIZE:
return action.data
default: return state
case RESOURCES_INITIALIZE:
return action.data
default:
return state
}
}

const pagesReducer = (
state: Array<PageJSON> = [],
action: {
type: string;
data: Array<PageJSON>;
},
type: string
data: Array<PageJSON>
}
) => {
switch (action.type) {
case PAGES_INITIALIZE:
return action.data
default: return state
case PAGES_INITIALIZE:
return action.data
default:
return state
}
}

const localesReducer = (
state: Locale = { language: 'en', translations: {} } as Locale,
action: {
type: string;
data: Locale;
},
type: string
data: Locale
}
) => {
switch (action.type) {
case LOCALE_INITIALIZE:
return action.data
default: return state
case LOCALE_INITIALIZE:
return action.data
default:
return state
}
}

const brandingReducer = (state = {}, action: {
type: string;
data: BrandingOptions;
}) => {
const brandingReducer = (
state = {},
action: {
type: string
data: BrandingOptions
}
) => {
switch (action.type) {
case BRANDING_INITIALIZE:
return action.data
default: return state
case BRANDING_INITIALIZE:
return action.data
default:
return state
}
}

const assetsReducer = (state = {}, action: {
type: string;
data: Assets;
}) => {
const assetsReducer = (
state = {},
action: {
type: string
data: Assets
}
) => {
switch (action.type) {
case ASSETS_INITIALIZE:
return action.data
default: return state
case ASSETS_INITIALIZE:
return action.data
default:
return state
}
}

const pathsReducer = (
state: Paths = DEFAULT_PATHS,
action: {type: string; data: Paths},
): Paths => {
const pathsReducer = (state: Paths = DEFAULT_PATHS, action: { type: string; data: Paths }): Paths => {
switch (action.type) {
case PATHS_INITIALIZE:
return action.data
default: return state
case PATHS_INITIALIZE:
return action.data
default:
return state
}
}

const dashboardReducer = (state = {}, action: {
type: string;
data: DashboardInState;
}): DashboardInState => {
const dashboardReducer = (
state = {},
action: {
type: string
data: DashboardInState
}
): DashboardInState => {
switch (action.type) {
case DASHBOARD_INITIALIZE:
return action.data
default: return state
case DASHBOARD_INITIALIZE:
return action.data
default:
return state
}
}

const sessionReducer = (
state: CurrentAdmin | null = null,
action: {
type: string;
data: CurrentAdmin | null;
},
type: string
data: CurrentAdmin | null
}
) => {
switch (action.type) {
case SESSION_INITIALIZE:
return action.data
default: return state
case SESSION_INITIALIZE:
return action.data
default:
return state
}
}

const versionsReducer = (state = {}, action: {
type: string;
data: VersionProps;
}) => {
const versionsReducer = (
state = {},
action: {
type: string
data: VersionProps
}
) => {
switch (action.type) {
case VERSIONS_INITIALIZE:
return {
admin: action.data.admin,
app: action.data.app,
}
default: return state
case VERSIONS_INITIALIZE:
return {
admin: action.data.admin,
app: action.data.app,
}
default:
return state
}
}

export type RouterProps = {
from: Partial<ReturnType<typeof useLocation>>;
to: Partial<ReturnType<typeof useLocation>>;
from: Partial<ReturnType<typeof useLocation>>
to: Partial<ReturnType<typeof useLocation>>
}

const routerReducer = (state: RouterProps = { from: {}, to: {} }, action: {
type: string;
data: any;
}) => {
const routerReducer = (
state: RouterProps = { from: {}, to: {} },
action: {
type: string
data: any
}
) => {
switch (action.type) {
case INITIAL_ROUTE:
return {
...state,
from: { ...action.data },
}
case ROUTE_CHANGED:
return {
from: { ...state.to },
to: { ...action.data },
}
default: return state
case INITIAL_ROUTE:
return {
...state,
from: { ...action.data },
}
case ROUTE_CHANGED:
return {
from: { ...state.to },
to: { ...action.data },
}
default:
return state
}
}

type NoticeArgs = { noticeId: string; progress: number }

const noticesReducer = (state: Array<NoticeMessageInState> = [], action: {
type: string;
data: NoticeMessageInState | NoticeArgs;
}): Array<NoticeMessageInState> => {
switch (action.type) {
case ADD_NOTICE: {
const notices = [action.data as NoticeMessageInState]
return notices
}
case DROP_NOTICE: {
return state.filter((notice) => notice.id !== (action.data as NoticeArgs).noticeId)
}
case SET_NOTICE_PROGRESS: {
return state.map((notice) => ({
...notice,
progress: notice.id === (action.data as NoticeArgs).noticeId
? action.data.progress
: notice.progress,
}))
const noticesReducer = (
state: Array<NoticeMessageInState> = [],
action: {
type: string
data: NoticeMessageInState | NoticeArgs
}
default: return state
): Array<NoticeMessageInState> => {
switch (action.type) {
case ADD_NOTICE: {
const notices = [action.data as NoticeMessageInState]
return notices
}
case DROP_NOTICE: {
return state.filter((notice) => notice.id !== (action.data as NoticeArgs).noticeId)
}
case SET_NOTICE_PROGRESS: {
return state.map((notice) => ({
...notice,
progress: notice.id === (action.data as NoticeArgs).noticeId ? action.data.progress : notice.progress,
}))
}
default:
return state
}
}

export type ReduxState = {
resources: Array<ResourceJSON>;
branding: BrandingOptions;
assets: Assets;
paths: Paths;
session: CurrentAdmin | null;
dashboard: DashboardInState;
notices: Array<NoticeMessageInState>;
versions: VersionProps;
pages: Array<PageJSON>;
locale: Locale;
router: RouterProps;
resources: Array<ResourceJSON>
branding: BrandingOptions
assets: Assets
paths: Paths
session: CurrentAdmin | null
dashboard: DashboardInState
notices: Array<NoticeMessageInState>
versions: VersionProps
pages: Array<PageJSON>
locale: Locale
router: RouterProps
}

const reducer = combineReducers<ReduxState>({
Expand Down

0 comments on commit 94ff387

Please sign in to comment.