Skip to content

Commit

Permalink
feat: support /rollouts/:namespace?q=... and /rollout/:namespace/:name (
Browse files Browse the repository at this point in the history
#1902)

Signed-off-by: Simon Ninon <[email protected]>
  • Loading branch information
Cylix authored Jun 30, 2022
1 parent 935a825 commit 03b7f5e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
1 change: 1 addition & 0 deletions USERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Organizations below are **officially** using Argo Rollouts. Please send a PR wit
1. [New Relic](https://newrelic.com/)
1. [Nitro](https://www.gonitro.com)
1. [Nozzle](https://nozzle.io)
1. [PagerDuty](https://www.pagerduty.com/)
1. [PayPal](https://www.paypal.com/)
1. [PayPay](https://paypay.ne.jp/)
1. [Quipper](https://www.quipper.com/)
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const App = () => {
<Switch>
<Page
exact
path='/'
path='/:namespace?'
component={<RolloutsList />}
shortcuts={[
{key: '/', description: 'Search'},
Expand All @@ -102,7 +102,7 @@ const App = () => {
]}
changeNamespace={changeNamespace}
/>
<Page path='/rollout/:name' component={<Rollout />} changeNamespace={changeNamespace} />
<Page path='/rollout/:namespace?/:name' component={<Rollout />} changeNamespace={changeNamespace} />
</Switch>
</Router>
</KeybindingProvider>
Expand All @@ -112,4 +112,4 @@ const App = () => {
);
};

export default App;
export default App;
14 changes: 11 additions & 3 deletions ui/src/app/components/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const Header = (props: {pageHasShortcuts: boolean; changeNamespace: (val:
const history = useHistory();
const namespaceInfo = React.useContext(NamespaceContext);
const {name} = useParams<{name: string}>();
const {namespace} = useParams<{namespace: string}>();
const api = React.useContext(RolloutAPIContext);
const [version, setVersion] = React.useState('v?');
const [nsInput, setNsInput] = React.useState(namespaceInfo.namespace);
Expand All @@ -23,6 +24,12 @@ export const Header = (props: {pageHasShortcuts: boolean; changeNamespace: (val:
};
getVersion();
}, []);
React.useEffect(() => {
if (namespace && namespace != namespaceInfo.namespace) {
props.changeNamespace(namespace);
setNsInput(namespace);
}
}, []);
return (
<GenericHeader>
<Link to='/'>
Expand Down Expand Up @@ -54,8 +61,9 @@ export const Header = (props: {pageHasShortcuts: boolean; changeNamespace: (val:
placeholder='Namespace'
onChange={(el) => setNsInput(el.target.value)}
onItemClick={(val) => {
props.changeNamespace(val ? val : nsInput);
history.push(`/`);
const selectedNamespace = val ? val : nsInput;
props.changeNamespace(selectedNamespace);
history.push(`/${selectedNamespace}`);
}}
value={nsInput}
/>
Expand All @@ -65,4 +73,4 @@ export const Header = (props: {pageHasShortcuts: boolean; changeNamespace: (val:
</div>
</GenericHeader>
);
};
};
13 changes: 11 additions & 2 deletions ui/src/app/components/rollouts-list/rollouts-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export const RolloutsList = () => {
const [filteredRollouts, setFilteredRollouts] = React.useState(rollouts);
const [pos, nav, reset] = useNav(filteredRollouts.length);
const [searchString, setSearchString, searchInput] = useAutocomplete('');
const searchParam = new URLSearchParams(window.location.search).get('q');
React.useEffect(() => {
if (searchParam && searchParam != searchString) {
setSearchString(searchParam);
}
}, []);

const {useKeybinding, keybindingState} = React.useContext(KeybindingContext);

Expand Down Expand Up @@ -81,6 +87,9 @@ export const RolloutsList = () => {
if ((filtered || []).length > 0) {
setFilteredRollouts(filtered);
}
if (searchString) {
history.replace(`/${namespaceCtx.namespace}?q=${searchString}`);
}
}, [searchString, rollouts]);

const namespaceCtx = React.useContext(NamespaceContext);
Expand All @@ -97,7 +106,7 @@ export const RolloutsList = () => {
className='rollouts-list__search'
placeholder='Search...'
style={{marginBottom: '1.5em'}}
onItemClick={(item) => history.push(`/rollout/${item}`)}
onItemClick={(item) => history.push(`/rollout/${namespaceCtx.namespace}/${item}`)}
icon='fa-search'
{...searchInput}
/>
Expand Down Expand Up @@ -176,7 +185,7 @@ export const RolloutWidget = (props: {rollout: RolloutInfo; deselect: () => void

return (
<EffectDiv className={`rollouts-list__widget ${props.selected ? 'rollouts-list__widget--selected' : ''}`} innerref={ref}>
<Link to={`/rollout/${rollout.objectMeta?.name}`} className='rollouts-list__widget__container'>
<Link to={`/rollout/${rollout.objectMeta?.namespace}/${rollout.objectMeta?.name}`} className='rollouts-list__widget__container'>
<WidgetHeader
rollout={rollout}
refresh={() => {
Expand Down

0 comments on commit 03b7f5e

Please sign in to comment.