|
| 1 | +# Workspace Template (DS 2.0) |
| 2 | + |
| 3 | +A template for building Alberta government **workspace applications** using the GoA Design System 2.0. This template provides a starting point for internal staff-facing applications with common patterns and components already implemented. |
| 4 | + |
| 5 | +## Tech Stack |
| 6 | + |
| 7 | +- **React** 18.2 with TypeScript 5.3 |
| 8 | +- **Vite** 5.1 for fast development and builds |
| 9 | +- **React Router** 6.22 for routing |
| 10 | +- **GoA Design System 2.0** (`@abgov/react-components`, `@abgov/web-components`) |
| 11 | +- **Vitest** for testing |
| 12 | + |
| 13 | +## Features |
| 14 | + |
| 15 | +- **Work Side Menu** - Responsive sidebar navigation with primary, secondary, and account sections |
| 16 | +- **Dynamic page headers** - Sticky headers with title and action buttons |
| 17 | +- **Data tables** - Sorting, filtering, keyboard navigation, and horizontal scroll shadows |
| 18 | +- **Notification system** - Popover notifications with localStorage persistence |
| 19 | +- **Loading states** - Progress indicators for async operations |
| 20 | +- **Error boundary** - Graceful error handling with fallback UI |
| 21 | +- **Mock API utilities** - Simulate network requests for development |
| 22 | + |
| 23 | +## Project Structure |
| 24 | + |
| 25 | +``` |
| 26 | +src/ |
| 27 | +├── components/ # Reusable UI components |
| 28 | +│ ├── ErrorBoundary.tsx |
| 29 | +│ ├── PageHeader.tsx |
| 30 | +│ └── ScrollContainer.tsx |
| 31 | +├── constants/ # Shared constants |
| 32 | +│ └── breakpoints.ts |
| 33 | +├── contexts/ # React Context providers |
| 34 | +│ ├── MenuContext.tsx |
| 35 | +│ ├── NotificationContext.tsx |
| 36 | +│ └── PageHeaderContext.tsx |
| 37 | +├── data/ # Mock data |
| 38 | +│ ├── mockClients.json |
| 39 | +│ ├── mockNotifications.ts |
| 40 | +│ └── mockSearchResults.json |
| 41 | +├── routes/ # Page components |
| 42 | +│ ├── ClientsPage.tsx |
| 43 | +│ ├── SearchPage.tsx |
| 44 | +│ └── ... |
| 45 | +├── types/ # TypeScript interfaces |
| 46 | +│ ├── Client.ts |
| 47 | +│ ├── Notification.ts |
| 48 | +│ └── SearchResult.ts |
| 49 | +├── utils/ # Helper functions |
| 50 | +│ ├── badgeUtils.ts |
| 51 | +│ ├── dateUtils.ts |
| 52 | +│ ├── mockApi.ts |
| 53 | +│ └── searchUtils.ts |
| 54 | +├── App.tsx # Root layout |
| 55 | +├── App.css # Global styles |
| 56 | +└── index.tsx # Entry point |
| 57 | +``` |
| 58 | + |
| 59 | +## Getting Started |
| 60 | + |
| 61 | +### Prerequisites |
| 62 | + |
| 63 | +- Node.js 18+ |
| 64 | +- npm 9+ |
| 65 | + |
| 66 | +### Installation |
| 67 | + |
| 68 | +1. Click the green **Use this template** button |
| 69 | +2. Select **Create a new repository** |
| 70 | +3. Select an owner and give the repo a suitable name |
| 71 | +4. Clone the repo onto your machine |
| 72 | +5. Install dependencies: |
| 73 | + |
| 74 | +```bash |
| 75 | +npm install |
| 76 | +``` |
| 77 | + |
| 78 | +### Development |
| 79 | + |
| 80 | +Start the development server: |
| 81 | + |
| 82 | +```bash |
| 83 | +npm run dev |
| 84 | +``` |
| 85 | + |
| 86 | +Open [http://localhost:5173](http://localhost:5173) in your browser. |
| 87 | + |
| 88 | +### Available Scripts |
| 89 | + |
| 90 | +| Script | Description | |
| 91 | +|--------|-------------| |
| 92 | +| `npm run dev` | Start development server | |
| 93 | +| `npm run build` | Build for production | |
| 94 | +| `npm run build:check` | Type-check and build | |
| 95 | +| `npm run preview` | Preview production build | |
| 96 | +| `npm run test` | Run tests | |
| 97 | +| `npm run coverage` | Run tests with coverage | |
| 98 | + |
| 99 | +## Key Patterns |
| 100 | + |
| 101 | +### Loading States |
| 102 | + |
| 103 | +Use the `mockFetch` utility to simulate API calls with loading states: |
| 104 | + |
| 105 | +```tsx |
| 106 | +import { mockFetch } from "../utils/mockApi"; |
| 107 | + |
| 108 | +const [data, setData] = useState([]); |
| 109 | +const [isLoading, setIsLoading] = useState(true); |
| 110 | + |
| 111 | +useEffect(() => { |
| 112 | + const fetchData = async () => { |
| 113 | + setIsLoading(true); |
| 114 | + const result = await mockFetch(mockData); |
| 115 | + setData(result); |
| 116 | + setIsLoading(false); |
| 117 | + }; |
| 118 | + fetchData(); |
| 119 | +}, []); |
| 120 | + |
| 121 | +// In JSX: |
| 122 | +<GoabCircularProgress visible={isLoading} variant="fullscreen" message="Loading..." /> |
| 123 | +``` |
| 124 | + |
| 125 | +### Page Headers |
| 126 | + |
| 127 | +Use the `usePageHeader` hook to set dynamic page titles and actions: |
| 128 | + |
| 129 | +```tsx |
| 130 | +import { usePageHeader } from "../contexts/PageHeaderContext"; |
| 131 | + |
| 132 | +usePageHeader("Page Title", <GoabButton>Action</GoabButton>); |
| 133 | +``` |
| 134 | + |
| 135 | +### Error Handling |
| 136 | + |
| 137 | +The app is wrapped in an `ErrorBoundary` component that catches errors and displays a fallback UI. |
| 138 | + |
| 139 | +## Customization |
| 140 | + |
| 141 | +### Styling |
| 142 | + |
| 143 | +- Global styles are in `src/App.css` |
| 144 | +- GoA Design System tokens are imported via `@abgov/web-components/index.css` |
| 145 | +- Mobile breakpoint is set at 624px (defined in `src/constants/breakpoints.ts`) |
| 146 | + |
| 147 | +### Adding New Pages |
| 148 | + |
| 149 | +1. Create a new component in `src/routes/` |
| 150 | +2. Add the route in `src/index.tsx` |
| 151 | +3. Add a menu item in `src/App.tsx` |
| 152 | + |
| 153 | +## Resources |
| 154 | + |
| 155 | +- [GoA Design System 2.0](https://design.alberta.ca) |
| 156 | +- [UI Components Documentation](https://design.alberta.ca) |
| 157 | + |
| 158 | +## License |
| 159 | + |
| 160 | +This template is provided by the Government of Alberta for use by Alberta government teams building internal workspace applications. |
0 commit comments