Skip to content

Commit

Permalink
Ability to read branch information from URL (#2867)
Browse files Browse the repository at this point in the history
  • Loading branch information
riverar committed Feb 22, 2024
1 parent 3396244 commit 352bd45
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 5 deletions.
39 changes: 39 additions & 0 deletions web/features/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"gh-pages": "^6.1.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.22.1",
"react-scripts": "^5.0.1",
"typescript": "^4.9.5"
},
Expand Down
15 changes: 11 additions & 4 deletions web/features/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import Path from './components/path';
import FeatureList from './components/featurelist';
import { IWorkerMessage, IInitializeMessage, IInitializeResultMessage, ISearchMessage, ISearchResultMessage } from './worker/worker';
import { useNavigate, useParams } from 'react-router-dom';

const useStyles = makeStyles({
root: {
Expand Down Expand Up @@ -57,7 +58,9 @@ const useStyles = makeStyles({
},
searchContainer: {
display: 'flex',
width: '100%'
flexWrap: 'wrap',
width: '100%',
...shorthands.gap('1em')
},
searchInput: {
flexGrow: 5
Expand Down Expand Up @@ -121,8 +124,9 @@ function App() {
const [worker, setWorker] = React.useState<Worker | null>(null);
const [query, setQuery] = React.useState('');

const params = useParams();
const branches = process.env.REACT_APP_BRANCHES!.split(',');
const defaultBranch = branches[0];
const defaultBranch = branches.includes(params.branch!) ? params.branch : branches[0];
const [branch, setBranch] = React.useState(defaultBranch);

const styles = useStyles();
Expand Down Expand Up @@ -189,11 +193,14 @@ function App() {
setResultsTruncated(false);
};

const navigate = useNavigate();
const onBranchSelected = (
ev: SelectionEvents,
data: OptionOnSelectData
) => {
setBranch(data.optionValue ?? defaultBranch);
const branch = data.optionValue ?? defaultBranch;
setBranch(branch);
navigate(`/${branch}`, { replace: true });
};

return (
Expand Down Expand Up @@ -233,7 +240,7 @@ function App() {
)
}
/>
<Dropdown className={styles.searchBranch} value={branch} onOptionSelect={onBranchSelected}>
<Dropdown size='large' className={styles.searchBranch} value={branch} onOptionSelect={onBranchSelected}>
{
branches.map((branch) => (
<Option key={branch}>
Expand Down
9 changes: 8 additions & 1 deletion web/features/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as ReactDOM from 'react-dom/client';
import { RouterProvider, createHashRouter } from 'react-router-dom';
import { FluentProvider, createLightTheme } from '@fluentui/react-components';
import '@fontsource/fira-sans';
import App from './app';
Expand Down Expand Up @@ -32,14 +33,20 @@ const lightTheme = {
...coreTheme,
};

const router = createHashRouter([
{
path: '/:branch?',
element: <App />
}
]);
const root = ReactDOM.createRoot(
document.getElementById('root') as HTMLElement
);
root.render(
// https://github.com/microsoft/fluentui/issues/30450
//<StrictMode>
<FluentProvider theme={lightTheme}>
<App />
<RouterProvider router={router} />
</FluentProvider>
//</StrictMode>
);

0 comments on commit 352bd45

Please sign in to comment.