mirror of
https://github.com/outline/outline.git
synced 2026-11-24 23:00:18 +03:00
* feat: Multi-select in the users settings table Adds multi-selection to the base settings table — a table opts in by supplying `isRowSelectable` and a `selectionToolbar`, reusing the model selection and toolbar infrastructure built for document lists. User actions are updated to the context based format so the same definitions drive the row menu and the bulk toolbar. * feat: Multi-select in the groups settings table Group deletion now operates on every active group so it can be performed from the bulk selection toolbar as well as the row menu. * feat: Multi-select in the group members settings table Group member removal and permission changes now operate on every active user, so they can be performed from the bulk selection toolbar as well as the row menu. * fix: Table selection styling feedback Lighten the selected row tint and drop the opaque background from the sticky actions cell so the row shows through. The selection checkbox is positioned absolutely so it centers in the row without influencing the cell's inline layout. * fix: Bleed the selected table row highlight past the table edges The highlight is drawn on a pseudo element behind the cells so it can extend 8px either side of the table and be rounded. * fix: Join the highlight of adjacent selected table rows Square off the corners between neighbouring selected rows so a run of them reads as one rounded block. * tweaks * Add new icons, styling tweaks * fix: Make the base key of new count strings singular i18next resolves the base key for count=1, which happens on a partial batch success, so the singular form belongs there and the plural in the _plural value.
83 lines
2.8 KiB
TypeScript
83 lines
2.8 KiB
TypeScript
import { observer } from "mobx-react";
|
|
import * as React from "react";
|
|
import { performAction, resolve } from "~/actions";
|
|
import type { ModelSelection } from "~/components/ModelSelection";
|
|
import { useModelSelection } from "~/components/ModelSelectionContext";
|
|
import type { ModelSelectionAction } from "~/components/ModelSelectionToolbar";
|
|
import ModelSelectionToolbar from "~/components/ModelSelectionToolbar";
|
|
import { ActionContext, ActionContextProvider } from "~/hooks/useActionContext";
|
|
import useStores from "~/hooks/useStores";
|
|
import type Model from "~/models/base/Model";
|
|
import type { Action } from "~/types";
|
|
|
|
type Props = {
|
|
/** The models the actions should operate on, usually the current selection. */
|
|
models: Model[];
|
|
/** The action definitions offered for the selection. */
|
|
actions: Action[];
|
|
};
|
|
|
|
/**
|
|
* Renders the bulk selection toolbar for the given action definitions, feeding
|
|
* the selected models in as the active models so that the same definitions used
|
|
* by menus operate on the whole selection.
|
|
*
|
|
* @param props The component props.
|
|
* @returns the toolbar element, or null when no list selection is in scope.
|
|
*/
|
|
export function ModelSelectionActionToolbar({ models, actions }: Props) {
|
|
const selection = useModelSelection();
|
|
|
|
if (!selection) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<ActionContextProvider value={{ activeModels: models, isButton: true }}>
|
|
<Toolbar selection={selection} actions={actions} />
|
|
</ActionContextProvider>
|
|
);
|
|
}
|
|
|
|
const Toolbar = observer(function Toolbar_({
|
|
selection,
|
|
actions,
|
|
}: {
|
|
selection: ModelSelection;
|
|
actions: Action[];
|
|
}) {
|
|
const { dialogs } = useStores();
|
|
const context = React.useContext(ActionContext);
|
|
if (!context) {
|
|
return null;
|
|
}
|
|
|
|
const toolbarActions: ModelSelectionAction[] = actions.map((action) => ({
|
|
key: action.id,
|
|
label: resolve<string>(action.name, context),
|
|
icon: resolve<React.ReactNode>(action.icon, context),
|
|
dangerous: action.dangerous,
|
|
visible: action.visible ? resolve<boolean>(action.visible, context) : true,
|
|
perform: async () => {
|
|
const openModals = dialogs.modalStack.size;
|
|
await performAction(action, context);
|
|
|
|
// `openModal` adds to the stack on a macrotask, so wait one before
|
|
// checking (its timer, scheduled first, runs before ours). If the action
|
|
// opened a dialog, leave the selection alone — cancelling keeps it and it
|
|
// clears once the models leave the list on confirm; otherwise the action
|
|
// completed inline, so clear it.
|
|
await new Promise<void>((resolve) => {
|
|
setTimeout(resolve, 0);
|
|
});
|
|
if (dialogs.modalStack.size <= openModals) {
|
|
selection.clear();
|
|
}
|
|
},
|
|
}));
|
|
|
|
return (
|
|
<ModelSelectionToolbar selection={selection} actions={toolbarActions} />
|
|
);
|
|
});
|