-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor(sorting): improve and centralize sorting logic
- Loading branch information
1 parent
429fd8c
commit bdba322
Showing
16 changed files
with
92 additions
and
204 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
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
This file was deleted.
Oops, something went wrong.
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
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
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 @@ | ||
export { usePortalExtendEntityFormConfig } from "./main"; |
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,17 @@ | ||
import { IAppliedSchemaFormConfig } from "shared/form-schemas/types"; | ||
import { noop } from "shared/lib/noop"; | ||
|
||
export const usePortalExtendEntityFormConfig = ( | ||
crudAction: "update" | "create" | ||
): | ||
| "loading" | ||
| (( | ||
formConfig: IAppliedSchemaFormConfig<any> | ||
) => IAppliedSchemaFormConfig<any>) => { | ||
noop(crudAction); | ||
return ( | ||
formConfig: IAppliedSchemaFormConfig<any> | ||
): IAppliedSchemaFormConfig<any> => { | ||
return formConfig; | ||
}; | ||
}; |
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,20 @@ | ||
function arrayMoveMutable<T>(array: T[], fromIndex: number, toIndex: number) { | ||
const startIndex = fromIndex < 0 ? array.length + fromIndex : fromIndex; | ||
|
||
if (startIndex >= 0 && startIndex < array.length) { | ||
const endIndex = toIndex < 0 ? array.length + toIndex : toIndex; | ||
|
||
const [item] = array.splice(fromIndex, 1); | ||
array.splice(endIndex, 0, item); | ||
} | ||
} | ||
|
||
export function arrayMoveImmutable<T>( | ||
array: T[], | ||
fromIndex: number, | ||
toIndex: number | ||
) { | ||
const newArray = [...array]; | ||
arrayMoveMutable(newArray, fromIndex, toIndex); | ||
return newArray; | ||
} |
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,17 @@ | ||
export function sortListByOrder<T, K extends keyof T>( | ||
order: string[], | ||
itemsToOrder: T[], | ||
key: K | ||
): T[] { | ||
const indexOf = (entry: T) => { | ||
const index = order.indexOf(entry[key] as unknown as string); | ||
if (index === -1) { | ||
return Infinity; | ||
} | ||
return index; | ||
}; | ||
|
||
return itemsToOrder.sort((a, b) => { | ||
return indexOf(a) - indexOf(b); | ||
}); | ||
} |
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
Oops, something went wrong.