Skip to content

Commit

Permalink
refactor: tweak generators with new naming convention
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Jan 7, 2024
1 parent 645d371 commit bb3ad2f
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 48 deletions.
6 changes: 3 additions & 3 deletions libs/tools/src/lib/web/create-mock-web-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function createMockWebApp(tree: Tree, app: string) {
})
// Create the shell data access lib
await libraryGenerator(tree, {
directory: `libs/${app}/shell/data-access`,
directory: `libs/${app}/core/data-access`,
linter: Linter.EsLint,
name: `${app}-shell-data-access`,
projectNameAndRootFormat: 'as-provided',
Expand All @@ -38,8 +38,8 @@ export async function createMockWebApp(tree: Tree, app: string) {
await createMockComponent(tree, `${app}-shell-feature`, `${app}-shell-feature`)

// Create the shell routes libs
await createMockComponent(tree, `${app}-shell-feature`, `${app}-shell.routes`)
await createMockComponent(tree, `${app}-shell-feature`, `${app}-admin.routes`)
await createMockComponent(tree, `${app}-shell-feature`, `shell-routes`)
await createMockComponent(tree, `${app}-shell-feature`, `shell-admin-routes`)
}

function createMockComponent(tree: Tree, project: string, name: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AdminCreate<%= modelClassName %>Input, AdminFindMany<%= modelClassName %>Input } from '@<%= npmScope %>/sdk'
import { useWebSdk } from '@<%= npmScope %>/<%= app %>-shell-data-access'
import { useSdk } from '@<%= npmScope %>/<%= app %>-core-data-access'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useQuery } from '@tanstack/react-query'
import { useState } from 'react'

export function useAdminFindMany<%= modelClassName %>(props?: Partial<AdminFindMany<%= modelClassName %>Input>) {
const sdk = useWebSdk()
const sdk = useSdk()
const [limit, setLimit] = useState(props?.limit ?? 10)
const [page, setPage] = useState(props?.page ?? 1)
const [search, setSearch] = useState<string>(props?.search ?? '')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { AdminUpdate<%= modelClassName %>Input } from '@<%= npmScope %>/sdk'
import { useWebSdk } from '@<%= npmScope %>/<%= app %>-shell-data-access'
import { useSdk } from '@<%= npmScope %>/<%= app %>-core-data-access'
import { toastError, toastSuccess } from '@pubkey-ui/core'
import { useQuery } from '@tanstack/react-query'

export function useAdminFindOne<%= modelClassName %>({ <%= modelPropertyName %>Id }:{ <%= modelPropertyName %>Id: string }) {
const sdk = useWebSdk()
const sdk = useSdk()
const query = useQuery({
queryKey: ['admin', 'find-one-<%= modelFileName %>', <%= modelPropertyName %>Id],
queryFn: () => sdk.adminFindOne<%= modelClassName %>({ <%= modelPropertyName %>Id }).then((res) => res.data),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Button, Group } from '@mantine/core'
import { AdminCreate<%= modelClassName %>Input } from '@<%= npmScope %>/sdk'
import { useAdminFindMany<%= modelClassName %> } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-data-access'
import { AdminUiCreate<%= modelClassName %>Form } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-ui'
import { Admin<%= modelClassName %>UiCreateForm } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-ui'
import { toastError, UiBack, UiCard, UiPage } from '@pubkey-ui/core'
import { useNavigate } from 'react-router-dom'

export function WebAdmin<%= modelClassName %>CreateFeature() {
export function Admin<%= modelClassName %>CreateFeature() {
const navigate = useNavigate()
const { create<%= modelClassName %> } = useAdminFindMany<%= modelClassName %>()

Expand All @@ -26,11 +26,11 @@ export function WebAdmin<%= modelClassName %>CreateFeature() {
return (
<UiPage leftAction={<UiBack />} title="Create <%= modelClassName %>">
<UiCard>
<AdminUiCreate<%= modelClassName %>Form submit={submit}>
<Admin<%= modelClassName %>UiCreateForm submit={submit}>
<Group justify="right">
<Button type="submit">Create</Button>
</Group>
</AdminUiCreate<%= modelClassName %>Form>
</Admin<%= modelClassName %>UiCreateForm>
</UiCard>
</UiPage>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useAdminFindOne<%= modelClassName %> } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-data-access'
import { UiCard, UiDebug, UiError, UiLoader } from '@pubkey-ui/core'

export function WebAdmin<%= modelClassName %>DetailOverviewTab({ <%= modelPropertyName %>Id }: { <%= modelPropertyName %>Id: string }) {
export function Admin<%= modelClassName %>DetailOverviewTab({ <%= modelPropertyName %>Id }: { <%= modelPropertyName %>Id: string }) {
const { item, query } = useAdminFindOne<%= modelClassName %>({ <%= modelPropertyName %>Id })

if (query.isLoading) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useAdminFindOne<%= modelClassName %> } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-data-access'
import { AdminUiUpdate<%= modelClassName %>Form } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-ui'
import { Admin<%= modelClassName %>UiUpdateForm } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-ui'
import { UiCard, UiError, UiLoader } from '@pubkey-ui/core'

export function WebAdmin<%= modelClassName %>DetailSettingsTab({ <%= modelPropertyName %>Id }: { <%= modelPropertyName %>Id: string }) {
export function Admin<%= modelClassName %>DetailSettingsTab({ <%= modelPropertyName %>Id }: { <%= modelPropertyName %>Id: string }) {
const { item, query, update<%= modelClassName %> } = useAdminFindOne<%= modelClassName %>({ <%= modelPropertyName %>Id })

if (query.isLoading) {
Expand All @@ -14,7 +14,7 @@ export function WebAdmin<%= modelClassName %>DetailSettingsTab({ <%= modelProper

return (
<UiCard>
<AdminUiUpdate<%= modelClassName %>Form <%= modelPropertyName %>={item} submit={update<%= modelClassName %>} />
<Admin<%= modelClassName %>UiUpdateForm <%= modelPropertyName %>={item} submit={update<%= modelClassName %>} />
</UiCard>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Group } from '@mantine/core'
import { UiBack, UiDebugModal, UiError, UiLoader, UiPage, UiTabRoutes } from '@pubkey-ui/core'
import { useAdminFindOne<%= modelClassName %> } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-data-access'
import { useParams } from 'react-router-dom'
import { WebAdmin<%= modelClassName %>DetailOverviewTab } from './web-admin-<%= modelFileName %>-detail-overview.tab'
import { WebAdmin<%= modelClassName %>DetailSettingsTab } from './web-admin-<%= modelFileName %>-detail-settings.tab'
import { Admin<%= modelClassName %>DetailOverviewTab } from './admin-<%= modelFileName %>-detail-overview.tab'
import { Admin<%= modelClassName %>DetailSettingsTab } from './admin-<%= modelFileName %>-detail-settings.tab'

export function WebAdmin<%= modelClassName %>DetailFeature() {
export function Admin<%= modelClassName %>DetailFeature() {
const { <%= modelPropertyName %>Id } = useParams<{ <%= modelPropertyName %>Id: string }>() as { <%= modelPropertyName %>Id: string }
const { item, query } = useAdminFindOne<%= modelClassName %>({ <%= modelPropertyName %>Id })

Expand All @@ -31,12 +31,12 @@ export function WebAdmin<%= modelClassName %>DetailFeature() {
{
value: 'overview',
label: 'Overview',
component: <WebAdmin<%= modelClassName %>DetailOverviewTab <%= modelPropertyName %>Id={<%= modelPropertyName %>Id} />,
component: <Admin<%= modelClassName %>DetailOverviewTab <%= modelPropertyName %>Id={<%= modelPropertyName %>Id} />,
},
{
value: 'settings',
label: 'Settings',
component: <WebAdmin<%= modelClassName %>DetailSettingsTab <%= modelPropertyName %>Id={<%= modelPropertyName %>Id} />,
component: <Admin<%= modelClassName %>DetailSettingsTab <%= modelPropertyName %>Id={<%= modelPropertyName %>Id} />,
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useRoutes } from 'react-router-dom'
import { Admin<%= modelClassName %>DetailFeature } from './admin-<%= modelFileName %>-detail.feature'
import { Admin<%= modelClassName %>CreateFeature } from './admin-<%= modelFileName %>-create.feature'
import { Admin<%= modelClassName %>ListFeature } from './admin-<%= modelFileName %>-list.feature'

export default function Admin<%= modelClassName %>Routes() {
return useRoutes([
{ path: '', element: <Admin<%= modelClassName %>ListFeature /> },
{
path: 'create',
element: <Admin<%= modelClassName %>CreateFeature />,
},
{ path: ':<%= modelPropertyName %>Id/*', element: <Admin<%= modelClassName %>DetailFeature /> },
])
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Button, Group } from '@mantine/core'
import { UiPageLimit, UiSearchField } from '@<%= npmScope %>/<%= app %>-ui-core'
import { useAdminFindMany<%= modelClassName %> } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-data-access'
import { AdminUi<%= modelClassName %>Table } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-ui'
import { Admin<%= modelClassName %>UiTable } from '@<%= npmScope %>/<%= app %>-<%= modelFileName %>-ui'
import { UiBack, UiDebugModal, UiInfo, UiLoader, UiPage } from '@pubkey-ui/core'
import { Link } from 'react-router-dom'

export function WebAdmin<%= modelClassName %>ListFeature() {
export function Admin<%= modelClassName %>ListFeature() {
const { delete<%= modelClassName %>, items, pagination, query, setSearch } = useAdminFindMany<%= modelClassName %>()

return (
Expand All @@ -29,7 +29,7 @@ export function WebAdmin<%= modelClassName %>ListFeature() {
{query.isLoading ? (
<UiLoader />
) : items?.length ? (
<AdminUi<%= modelClassName %>Table
<Admin<%= modelClassName %>UiTable
delete<%= modelClassName %>={(<%= modelPropertyName %>) => {
if (!window.confirm('Are you sure?')) return
return delete<%= modelClassName %>(<%= modelPropertyName %>.id)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AdminCreate<%= modelClassName %>Input } from '@<%= npmScope %>/sdk'
import { formFieldText, UiForm, UiFormField } from '@pubkey-ui/core'
import { ReactNode } from 'react'

export function AdminUiCreate<%= modelClassName %>Form({
export function Admin<%= modelClassName %>UiCreateForm({
children,
submit,
}: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IconPencil, IconTrash } from '@tabler/icons-react'
import { DataTable, DataTableProps } from 'mantine-datatable'
import { Link } from 'react-router-dom'

export function AdminUi<%= modelClassName %>Table({
export function Admin<%= modelClassName %>UiTable({
delete<%= modelClassName %>,
<%= modelPropertyNamePlural %> = [],
onPageChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button, Group } from '@mantine/core'
import { AdminUpdate<%= modelClassName %>Input, <%= modelClassName %> } from '@<%= npmScope %>/sdk'
import { formFieldText, UiForm, UiFormField } from '@pubkey-ui/core'

export function AdminUiUpdate<%= modelClassName %>Form({
export function Admin<%= modelClassName %>UiUpdateForm({
submit,
<%= modelPropertyName %>
}: {
Expand Down
8 changes: 4 additions & 4 deletions libs/tools/src/lib/web/generate-web-lib-feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function generateWebLibFeature(tree: Tree, options: NormalizedWebFe
barrel,
`import { lazy } from 'react'
export const WebAdmin${className}Routes = lazy(() => import('./lib/web-admin-${fileName}.routes'))
export const Admin${className}Feature = lazy(() => import('./lib/admin-${fileName}-feature'))
`,
)

Expand All @@ -36,7 +36,7 @@ export const WebAdmin${className}Routes = lazy(() => import('./lib/web-admin-${f
throw new Error(`Could not find shell project for ${options.app}`)
}

const adminRoutes = `${shellProject.sourceRoot}/lib/web-admin.routes.tsx`
const adminRoutes = `${shellProject.sourceRoot}/lib/shell-admin-routes.tsx`

updateSourceFile(tree, adminRoutes, (source) => {
addArrayItem(source, {
Expand All @@ -45,13 +45,13 @@ export const WebAdmin${className}Routes = lazy(() => import('./lib/web-admin-${f
})
addArrayItem(source, {
name: 'routes',
content: `{ path: '${fileNamePlural}/*', element: <WebAdmin${className}Routes /> },`,
content: `{ path: '${fileNamePlural}/*', element: <Admin${className}Feature /> },`,
})
return source
})

updateSourceFile(tree, adminRoutes, (source) => {
addNamedImport(source, `@${npmScope}/${options.app}-${options.name}-feature`, `WebAdmin${className}Routes`)
addNamedImport(source, `@${npmScope}/${options.app}-${options.name}-feature`, `Admin${className}Feature`)
return source
})
}
Expand Down
6 changes: 3 additions & 3 deletions libs/tools/src/lib/web/generate-web-lib-ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export async function generateWebLibUi(tree: Tree, options: NormalizedWebFeature
})
addExports(tree, barrel, [
// Export the admin hooks
`./lib/admin-ui-${options.name}-create-form`,
`./lib/admin-ui-${options.name}-table`,
`./lib/admin-ui-${options.name}-update-form`,
`./lib/admin-${options.name}-ui-create-form`,
`./lib/admin-${options.name}-ui-table`,
`./lib/admin-${options.name}-ui-update-form`,
])
}
}

0 comments on commit bb3ad2f

Please sign in to comment.