-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
tingfuyeh
committed
Dec 2, 2021
1 parent
aa8fe70
commit ef64449
Showing
12 changed files
with
530 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
"jsxSingleQuote": true | ||
} | ||
"semi": true, | ||
"singleQuote": false, | ||
"printWidth": 120, | ||
"trailingComma": "all", | ||
"jsxSingleQuote": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React from "react"; | ||
import { DuckCmpProps, memorize } from "saga-duck"; | ||
import NamespaceDuck from "./PageDuck"; | ||
import getColumns from "./getColumns"; | ||
import insertCSS from "../common/helpers/insertCSS"; | ||
import { Justify, H3, Table, Button, SearchBox, Card } from "tea-component"; | ||
import GridPageGrid from "../common/duckComponents/GridPageGrid"; | ||
import GridPagePagination from "../common/duckComponents/GridPagePagination"; | ||
import BasicLayout from "../common/components/BaseLayout"; | ||
|
||
insertCSS( | ||
"service", | ||
` | ||
.justify-search{ | ||
margin-right:20px | ||
} | ||
.justify-button{ | ||
vertical-align: bottom | ||
} | ||
`, | ||
); | ||
const getHandlers = memorize(({ creators }: NamespaceDuck, dispatch) => ({ | ||
inputKeyword: (keyword) => dispatch(creators.inputKeyword(keyword)), | ||
search: (keyword) => dispatch(creators.search(keyword)), | ||
clearKeyword: () => dispatch(creators.inputKeyword("")), | ||
reload: () => dispatch(creators.reload()), | ||
create: () => dispatch(creators.create()), | ||
})); | ||
export default function ServicePage(props: DuckCmpProps<NamespaceDuck>) { | ||
const { duck, store, dispatch } = props; | ||
const { selectors } = duck; | ||
const columns = React.useMemo(() => getColumns(props), []); | ||
const handlers = getHandlers(props); | ||
return ( | ||
<BasicLayout title={"命名空间"} store={store} selectors={duck.selectors} header={<></>}> | ||
<Table.ActionPanel> | ||
<Justify | ||
left={ | ||
<Button type={"primary"} onClick={handlers.create}> | ||
{"新建"} | ||
</Button> | ||
} | ||
right={ | ||
<> | ||
<SearchBox | ||
value={selectors.pendingKeyword(store)} | ||
placeholder={"请输入命名空间名称"} | ||
onSearch={handlers.search} | ||
onChange={handlers.inputKeyword} | ||
onClear={handlers.clearKeyword} | ||
/> | ||
<Button type={"icon"} icon={"refresh"} onClick={handlers.reload}></Button> | ||
</> | ||
} | ||
/> | ||
</Table.ActionPanel> | ||
<Card> | ||
<GridPageGrid duck={duck} dispatch={dispatch} store={store} columns={columns} /> | ||
<GridPagePagination duck={duck} dispatch={dispatch} store={store} /> | ||
</Card> | ||
</BasicLayout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { createToPayload, reduceFromPayload } from "saga-duck"; | ||
import { takeLatest } from "redux-saga-catch"; | ||
import Create from "./operation/Create"; | ||
import CreateDuck from "./operation/CreateDuck"; | ||
import { put, select } from "redux-saga/effects"; | ||
import GridPageDuck, { Filter as BaseFilter } from "../common/ducks/GridPage"; | ||
import { ComposedId } from "../service/detail/types"; | ||
import { resolvePromise } from "saga-duck/build/helper"; | ||
import { showDialog } from "../common/helpers/showDialog"; | ||
import { Modal, notification } from "tea-component"; | ||
import { Namespace } from "../service/types"; | ||
import { deleteNamespace, describeComplicatedNamespaces } from "./model"; | ||
|
||
export interface NamespaceItem extends Namespace { | ||
id: string; | ||
} | ||
export default class ServicePageDuck extends GridPageDuck { | ||
Filter: BaseFilter; | ||
Item: NamespaceItem; | ||
get baseUrl() { | ||
return ""; | ||
} | ||
get quickTypes() { | ||
enum Types { | ||
EDIT, | ||
REMOVE, | ||
CREATE, | ||
LOAD, | ||
SET_COMPOSE_ID, | ||
} | ||
return { | ||
...super.quickTypes, | ||
...Types, | ||
}; | ||
} | ||
get initialFetch() { | ||
return true; | ||
} | ||
get recordKey() { | ||
return "id"; | ||
} | ||
get watchTypes() { | ||
return [...super.watchTypes, this.types.SEARCH, this.types.SET_COMPOSE_ID]; | ||
} | ||
get params() { | ||
return [...super.params]; | ||
} | ||
get quickDucks() { | ||
return { | ||
...super.quickDucks, | ||
}; | ||
} | ||
get reducers() { | ||
const { types } = this; | ||
return { | ||
...super.reducers, | ||
composedId: reduceFromPayload(types.SET_COMPOSE_ID, {} as ComposedId), | ||
}; | ||
} | ||
get creators() { | ||
const { types } = this; | ||
return { | ||
...super.creators, | ||
edit: createToPayload<NamespaceItem>(types.EDIT), | ||
remove: createToPayload<NamespaceItem>(types.REMOVE), | ||
create: createToPayload<void>(types.CREATE), | ||
load: (composedId, data) => ({ | ||
type: types.LOAD, | ||
payload: { composedId, data }, | ||
}), | ||
}; | ||
} | ||
get rawSelectors() { | ||
type State = this["State"]; | ||
return { | ||
...super.rawSelectors, | ||
filter: (state: State) => ({ | ||
page: state.page, | ||
count: state.count, | ||
keyword: state.keyword, | ||
}), | ||
}; | ||
} | ||
|
||
*saga() { | ||
const { types, creators, selectors } = this; | ||
yield* super.saga(); | ||
yield takeLatest(types.LOAD, function* (action) { | ||
const { composedId } = action.payload; | ||
yield put({ type: types.SET_COMPOSE_ID, payload: composedId }); | ||
}); | ||
yield takeLatest(types.CREATE, function* () { | ||
const res = yield* resolvePromise( | ||
new Promise((resolve) => { | ||
showDialog(Create, CreateDuck, function* (duck: CreateDuck) { | ||
try { | ||
resolve(yield* duck.execute({}, { isModify: false })); | ||
} finally { | ||
resolve(false); | ||
} | ||
}); | ||
}), | ||
); | ||
if (res) { | ||
yield put(creators.reload()); | ||
} | ||
}); | ||
yield takeLatest(types.EDIT, function* (action) { | ||
const data = action.payload; | ||
const res = yield* resolvePromise( | ||
new Promise((resolve) => { | ||
showDialog(Create, CreateDuck, function* (duck: CreateDuck) { | ||
try { | ||
resolve(yield* duck.execute(data, { isModify: true })); | ||
} finally { | ||
resolve(false); | ||
} | ||
}); | ||
}), | ||
); | ||
if (res) { | ||
yield put(creators.reload()); | ||
} | ||
}); | ||
yield takeLatest(types.REMOVE, function* (action) { | ||
const { name } = action.payload; | ||
|
||
const confirm = yield Modal.confirm({ | ||
message: `确认删除命名空间`, | ||
description: "删除后,无法恢复", | ||
okText: "删除", | ||
}); | ||
if (confirm) { | ||
const res = yield deleteNamespace([{ name, token: "polaris@12345678" }]); | ||
if (res) notification.success({ description: "删除成功" }); | ||
yield put(creators.reload()); | ||
} | ||
}); | ||
} | ||
|
||
async getData(filters: this["Filter"]) { | ||
const { page, count, keyword } = filters; | ||
const result = await describeComplicatedNamespaces({ | ||
limit: count, | ||
offset: (page - 1) * count, | ||
name: keyword || undefined, | ||
}); | ||
return { | ||
totalCount: result.amount, | ||
list: | ||
result.namespaces?.map((item) => ({ | ||
...item, | ||
id: item.name, | ||
})) || [], | ||
}; | ||
} | ||
} |
Oops, something went wrong.