Skip to content

Commit

Permalink
feat(dashboard) modal search autofocus (medusajs#9038)
Browse files Browse the repository at this point in the history
**What**
- autofocus search input on route modal that have tables

---

CLOSES CC-132
  • Loading branch information
fPolic authored Sep 11, 2024
1 parent d398009 commit 28dc8d4
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DataTableOrderBy } from "../data-table-order-by"
import { DataTableSearch } from "../data-table-search"

export interface DataTableQueryProps {
search?: boolean
search?: boolean | "autofocus"
orderBy?: (string | number)[]
filters?: Filter[]
prefix?: string
Expand All @@ -25,7 +25,12 @@ export const DataTableQuery = ({
)}
</div>
<div className="flex shrink-0 items-center gap-x-2">
{search && <DataTableSearch prefix={prefix} />}
{search && (
<DataTableSearch
prefix={prefix}
autofocus={search === "autofocus"}
/>
)}
{orderBy && <DataTableOrderBy keys={orderBy} prefix={prefix} />}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { useSelectedParams } from "../hooks"
type DataTableSearchProps = {
placeholder?: string
prefix?: string
autofocus?: boolean
}

export const DataTableSearch = ({
placeholder,
prefix,
autofocus,
}: DataTableSearchProps) => {
const { t } = useTranslation()
const placeholderText = placeholder || t("general.search")
Expand Down Expand Up @@ -50,6 +52,7 @@ export const DataTableSearch = ({
name="q"
type="search"
size="small"
autoFocus={autofocus}
defaultValue={query?.[0] || undefined}
onChange={debouncedOnChange}
placeholder={placeholderText}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const DataTable = <TData,>({
<TableSkeleton
layout={layout}
rowCount={pageSize}
search={search}
search={!!search}
filters={!!filters?.length}
orderBy={!!orderBy?.length}
pagination={!!pagination}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const ApiKeySalesChannelsForm = ({
count={count}
pageSize={PAGE_SIZE}
pagination
search
search="autofocus"
isLoading={isLoading}
queryObject={raw}
orderBy={["name", "created_at", "updated_at"]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const AddCampaignPromotionsForm = ({
queryObject={raw}
layout="fill"
pagination
search
search="autofocus"
noRecords={{
message: t("campaigns.promotions.add.list.noRecordsMessage"),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const EditCategoryProductsForm = ({
isLoading={isPending}
layout="fill"
pagination
search
search="autofocus"
/>
</RouteFocusModal.Body>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const AddProductsToCollectionForm = ({
isLoading={isLoading}
layout="fill"
pagination
search
search="autofocus"
/>
</RouteFocusModal.Body>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export const AddCustomersForm = ({
]}
isLoading={isLoading}
layout="fill"
search
search="autofocus"
queryObject={raw}
noRecords={{
message: t("customerGroups.customers.add.list.noRecordsMessage"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const AddCustomerGroupsForm = ({
orderBy={["name", "created_at", "updated_at"]}
isLoading={isLoading}
layout="fill"
search
search="autofocus"
queryObject={raw}
noRecords={{
message: t("customers.groups.add.list.noRecordsMessage"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export const LocationEditFulfillmentProvidersForm = ({
isLoading={isLoading}
count={count}
filters={filters}
search
search="autofocus"
pagination
orderBy={["id", "created_at", "updated_at"]}
queryObject={raw}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const LocationEditSalesChannelsForm = ({
isLoading={isLoading}
count={count}
filters={filters}
search
search="autofocus"
pagination
orderBy={["name", "created_at", "updated_at"]}
queryObject={raw}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export const EditSalesChannelsForm = ({
isLoading={isLoading}
count={count}
filters={filters}
search
search="autofocus"
pagination
orderBy={["name", "created_at", "updated_at"]}
queryObject={raw}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export const AddCountriesForm = ({ region }: AddCountriesFormProps) => {
columns={columns}
pageSize={PAGE_SIZE}
count={count}
search
search="autofocus"
pagination
layout="fill"
orderBy={["name", "code"]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ export const CreateRegionForm = ({
pageSize={PAGE_SIZE}
orderBy={["name", "code"]}
pagination
search
search="autofocus"
layout="fill"
queryObject={raw}
prefix={PREFIX}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export const AddProductsToSalesChannelForm = ({
queryObject={raw}
layout="fill"
pagination
search
search="autofocus"
noRecords={{
message: t("salesChannels.products.add.list.noRecordsMessage"),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export const AddCurrenciesForm = ({
columns={columns}
layout="fill"
pagination
search
search="autofocus"
prefix={PREFIX}
orderBy={["code", "name"]}
isLoading={isLoading}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const InviteUserSchema = zod.object({

const PAGE_SIZE = 10
const PREFIX = "usr_invite"
const INVITE_URL = `${window.location.origin}${__BASE__ === "/" ? "" : __BASE__}/invite?token=`

const INVITE_URL = `${window.location.origin}${
__BASE__ === "/" ? "" : __BASE__
}/invite?token=`

export const InviteUserForm = () => {
const { t } = useTranslation()
Expand Down Expand Up @@ -163,7 +164,7 @@ export const InviteUserForm = () => {
pageSize={PAGE_SIZE}
prefix={PREFIX}
pagination
search
search="autofocus"
isLoading={isLoading}
queryObject={raw}
orderBy={["email", "created_at", "updated_at"]}
Expand Down

0 comments on commit 28dc8d4

Please sign in to comment.