Improve labels
This commit is contained in:
parent
42b55e860b
commit
649f35e0d1
6 changed files with 33 additions and 9 deletions
|
@ -22,8 +22,12 @@ const useStyles = makeStyles(
|
||||||
color: theme.palette.text.secondary,
|
color: theme.palette.text.secondary,
|
||||||
fontWeight: 400
|
fontWeight: 400
|
||||||
},
|
},
|
||||||
|
display: "flex",
|
||||||
margin: theme.spacing(1, 0)
|
margin: theme.spacing(1, 0)
|
||||||
},
|
},
|
||||||
|
itemLabel: {
|
||||||
|
display: "inline-block"
|
||||||
|
},
|
||||||
label: {
|
label: {
|
||||||
paddingLeft: theme.spacing(2),
|
paddingLeft: theme.spacing(2),
|
||||||
textTransform: "uppercase"
|
textTransform: "uppercase"
|
||||||
|
@ -34,6 +38,9 @@ const useStyles = makeStyles(
|
||||||
},
|
},
|
||||||
margin: theme.spacing(2, 0),
|
margin: theme.spacing(2, 0),
|
||||||
padding: theme.spacing(0, 1)
|
padding: theme.spacing(0, 1)
|
||||||
|
},
|
||||||
|
spacer: {
|
||||||
|
flex: 1
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
|
@ -70,7 +77,14 @@ const NavigatorSection: React.FC<NavigatorSectionProps> = props => {
|
||||||
selected={highlightedIndex === index}
|
selected={highlightedIndex === index}
|
||||||
key={[item.label, item.type].join(":")}
|
key={[item.label, item.type].join(":")}
|
||||||
>
|
>
|
||||||
{item.label}
|
<span className={classes.itemLabel}>
|
||||||
|
<span>{item.label}</span>
|
||||||
|
{item.caption && (
|
||||||
|
<Typography variant="caption">{item.caption}</Typography>
|
||||||
|
)}
|
||||||
|
</span>
|
||||||
|
<span className={classes.spacer} />
|
||||||
|
{item.extraInfo}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { UseNavigatorResult } from "@saleor/hooks/useNavigator";
|
||||||
import { OrderDraftCreate } from "@saleor/orders/types/OrderDraftCreate";
|
import { OrderDraftCreate } from "@saleor/orders/types/OrderDraftCreate";
|
||||||
import { productAddUrl } from "@saleor/products/urls";
|
import { productAddUrl } from "@saleor/products/urls";
|
||||||
import { MutationFunction } from "react-apollo";
|
import { MutationFunction } from "react-apollo";
|
||||||
import { QuickSearchAction } from "../../types";
|
import { QuickSearchActionInput } from "../../types";
|
||||||
import messages from "../messages";
|
import messages from "../messages";
|
||||||
|
|
||||||
const threshold = 0.05;
|
const threshold = 0.05;
|
||||||
|
@ -24,7 +24,7 @@ export function searchInCommands(
|
||||||
intl: IntlShape,
|
intl: IntlShape,
|
||||||
navigate: UseNavigatorResult,
|
navigate: UseNavigatorResult,
|
||||||
createOrder: MutationFunction<OrderDraftCreate, {}>
|
createOrder: MutationFunction<OrderDraftCreate, {}>
|
||||||
): QuickSearchAction[] {
|
): QuickSearchActionInput[] {
|
||||||
const actions: Command[] = [
|
const actions: Command[] = [
|
||||||
{
|
{
|
||||||
label: intl.formatMessage(messages.addCategory),
|
label: intl.formatMessage(messages.addCategory),
|
||||||
|
@ -56,6 +56,7 @@ export function searchInCommands(
|
||||||
label: action.label,
|
label: action.label,
|
||||||
onClick: action.onClick,
|
onClick: action.onClick,
|
||||||
score: score(action.label, search),
|
score: score(action.label, search),
|
||||||
|
text: action.label,
|
||||||
type: "action"
|
type: "action"
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -65,7 +66,7 @@ function getCommandModeActions(
|
||||||
intl: IntlShape,
|
intl: IntlShape,
|
||||||
navigate: UseNavigatorResult,
|
navigate: UseNavigatorResult,
|
||||||
createOrder: MutationFunction<OrderDraftCreate, {}>
|
createOrder: MutationFunction<OrderDraftCreate, {}>
|
||||||
): QuickSearchAction[] {
|
): QuickSearchActionInput[] {
|
||||||
return [...searchInCommands(query, intl, navigate, createOrder)]
|
return [...searchInCommands(query, intl, navigate, createOrder)]
|
||||||
.filter(action => action.score >= threshold)
|
.filter(action => action.score >= threshold)
|
||||||
.sort((a, b) => (a.score <= b.score ? 1 : -1))
|
.sort((a, b) => (a.score <= b.score ? 1 : -1))
|
||||||
|
|
|
@ -12,6 +12,7 @@ export function searchInCustomers(
|
||||||
customers: SearchCustomers_search_edges_node[]
|
customers: SearchCustomers_search_edges_node[]
|
||||||
): QuickSearchAction[] {
|
): QuickSearchAction[] {
|
||||||
return customers.map(customer => ({
|
return customers.map(customer => ({
|
||||||
|
caption: customer.email,
|
||||||
label:
|
label:
|
||||||
customer.firstName && customer.lastName
|
customer.firstName && customer.lastName
|
||||||
? intl.formatMessage(messages.customerWithName, {
|
? intl.formatMessage(messages.customerWithName, {
|
||||||
|
|
|
@ -21,7 +21,7 @@ import { staffListUrl } from "@saleor/staff/urls";
|
||||||
import { countryListUrl } from "@saleor/taxes/urls";
|
import { countryListUrl } from "@saleor/taxes/urls";
|
||||||
import { languageListUrl } from "@saleor/translations/urls";
|
import { languageListUrl } from "@saleor/translations/urls";
|
||||||
import { webhooksListUrl } from "@saleor/webhooks/urls";
|
import { webhooksListUrl } from "@saleor/webhooks/urls";
|
||||||
import { QuickSearchAction } from "../../types";
|
import { QuickSearchActionInput } from "../../types";
|
||||||
|
|
||||||
interface View {
|
interface View {
|
||||||
label: string;
|
label: string;
|
||||||
|
@ -31,7 +31,7 @@ function searchInViews(
|
||||||
search: string,
|
search: string,
|
||||||
intl: IntlShape,
|
intl: IntlShape,
|
||||||
navigate: UseNavigatorResult
|
navigate: UseNavigatorResult
|
||||||
): QuickSearchAction[] {
|
): QuickSearchActionInput[] {
|
||||||
const views: View[] = [
|
const views: View[] = [
|
||||||
{
|
{
|
||||||
label: intl.formatMessage(sectionNames.attributes),
|
label: intl.formatMessage(sectionNames.attributes),
|
||||||
|
@ -123,6 +123,7 @@ function searchInViews(
|
||||||
label: view.label,
|
label: view.label,
|
||||||
onClick: () => navigate(view.url),
|
onClick: () => navigate(view.url),
|
||||||
score: score(view.label, search),
|
score: score(view.label, search),
|
||||||
|
text: view.label,
|
||||||
type: "view"
|
type: "view"
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { IntlShape } from "react-intl";
|
import { IntlShape } from "react-intl";
|
||||||
|
|
||||||
import { UseNavigatorResult } from "@saleor/hooks/useNavigator";
|
import { UseNavigatorResult } from "@saleor/hooks/useNavigator";
|
||||||
import { maybe } from "@saleor/misc";
|
import { maybe, transformOrderStatus } from "@saleor/misc";
|
||||||
import { orderUrl } from "@saleor/orders/urls";
|
import { orderUrl } from "@saleor/orders/urls";
|
||||||
import { CheckIfOrderExists_order } from "../queries/types/CheckIfOrderExists";
|
import { CheckIfOrderExists_order } from "../queries/types/CheckIfOrderExists";
|
||||||
import { QuickSearchAction } from "../types";
|
import { QuickSearchAction } from "../types";
|
||||||
|
@ -26,11 +26,11 @@ function getOrdersModeActions(
|
||||||
if (isQueryValidOrderNumber(query) && maybe(() => order.id === gqlId)) {
|
if (isQueryValidOrderNumber(query) && maybe(() => order.id === gqlId)) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
extraInfo: transformOrderStatus(order.status, intl).localized,
|
||||||
label: intl.formatMessage(messages.goToOrder, {
|
label: intl.formatMessage(messages.goToOrder, {
|
||||||
orderNumber: query
|
orderNumber: query
|
||||||
}),
|
}),
|
||||||
onClick: () => navigate(orderUrl(gqlId)),
|
onClick: () => navigate(orderUrl(gqlId)),
|
||||||
score: 1,
|
|
||||||
type: "action"
|
type: "action"
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
export type QuickSearchActionType = "action" | "customer" | "view";
|
export type QuickSearchActionType = "action" | "customer" | "view";
|
||||||
|
|
||||||
export interface QuickSearchAction {
|
export interface QuickSearchAction {
|
||||||
|
caption?: string;
|
||||||
|
extraInfo?: string;
|
||||||
label: string;
|
label: string;
|
||||||
score: number;
|
price?: number;
|
||||||
type: QuickSearchActionType;
|
type: QuickSearchActionType;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface QuickSearchActionInput extends QuickSearchAction {
|
||||||
|
score: number;
|
||||||
|
text: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type QuickSearchMode = "default" | "commands" | "orders" | "customers";
|
export type QuickSearchMode = "default" | "commands" | "orders" | "customers";
|
||||||
|
|
Loading…
Reference in a new issue