Skip to content

Commit

Permalink
Sort assets by modified date (#11820)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrFlashAccount authored Dec 24, 2024
1 parent e86e5e7 commit 5777fa6
Show file tree
Hide file tree
Showing 55 changed files with 1,402 additions and 673 deletions.
38 changes: 23 additions & 15 deletions app/common/src/services/Backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,7 @@ export function createSpecialLoadingAsset(directoryId: DirectoryId): SpecialLoad
return {
type: AssetType.specialLoading,
title: '',
id: LoadingAssetId(
createPlaceholderId(`${AssetType.specialLoading}-${uniqueString.uniqueString()}`),
),
id: LoadingAssetId(createPlaceholderId(`${AssetType.specialLoading}-${directoryId}`)),
modifiedAt: dateTime.toRfc3339(new Date()),
parentId: directoryId,
permissions: [],
Expand All @@ -998,7 +996,7 @@ export function createSpecialEmptyAsset(directoryId: DirectoryId): SpecialEmptyA
return {
type: AssetType.specialEmpty,
title: '',
id: EmptyAssetId(`${AssetType.specialEmpty}-${uniqueString.uniqueString()}`),
id: EmptyAssetId(`${AssetType.specialEmpty}-${directoryId}`),
modifiedAt: dateTime.toRfc3339(new Date()),
parentId: directoryId,
permissions: [],
Expand All @@ -1024,7 +1022,7 @@ export function createSpecialErrorAsset(directoryId: DirectoryId): SpecialErrorA
return {
type: AssetType.specialError,
title: '',
id: ErrorAssetId(`${AssetType.specialError}-${uniqueString.uniqueString()}`),
id: ErrorAssetId(`${AssetType.specialError}-${directoryId}`),
modifiedAt: dateTime.toRfc3339(new Date()),
parentId: directoryId,
permissions: [],
Expand Down Expand Up @@ -1514,18 +1512,28 @@ export function isNewTitleValid(
item: AnyAsset,
newTitle: string,
siblings?: readonly AnyAsset[] | null,
) {
return newTitle !== '' && newTitle !== item.title && isNewTitleUnique(item, newTitle, siblings)
}

/**
* Check whether a new title is unique among the siblings.
*/
export function isNewTitleUnique(
item: AnyAsset,
newTitle: string,
siblings?: readonly AnyAsset[] | null,
) {
siblings ??= []
return (
newTitle !== '' &&
newTitle !== item.title &&
siblings.every(sibling => {
const isSelf = sibling.id === item.id
const hasSameType = sibling.type === item.type
const hasSameTitle = sibling.title === newTitle
return !(!isSelf && hasSameType && hasSameTitle)
})
)

return siblings.every(sibling => {
if (sibling.id === item.id) {
return true
}

const hasSameTitle = sibling.title.toLowerCase() === newTitle.toLowerCase()
return !hasSameTitle
})
}

/** Network error class. */
Expand Down
3 changes: 3 additions & 0 deletions app/common/src/text/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
"otherUserIsUsingProjectError": "Someone else is using this project",
"localBackendNotDetectedError": "Could not detect the local backend",

"invalidInput": "Invalid input",
"nameShouldBeUnique": "Name must be unique",
"nameShouldNotContainInvalidCharacters": "Name should not contain invalid characters",
"invalidEmailValidationError": "Please enter a valid email address",

"projectHasNoSourceFilesPhrase": "project has no source files",
Expand Down
52 changes: 52 additions & 0 deletions app/common/src/text/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @file Functions related to displaying text. */

import { unsafeKeys } from '../utilities/data/object'
import ENGLISH from './english.json' with { type: 'json' }

// =============
Expand Down Expand Up @@ -159,3 +160,54 @@ export interface Replacements
export const TEXTS: Readonly<Record<Language, Texts>> = {
[Language.english]: ENGLISH,
}
/**
* A function that gets localized text for a given key, with optional replacements.
* @param key - The key of the text to get.
* @param replacements - The replacements to insert into the text.
* If the text contains placeholders like `$0`, `$1`, etc.,
* they will be replaced with the corresponding replacement.
*/
export type GetText = <K extends TextId>(
dictionary: Texts,
key: K,
...replacements: Replacements[K]
) => string

/**
* Resolves the language texts based on the user's preferred language.
*/
export function resolveUserLanguage() {
const locale = navigator.language
const language =
unsafeKeys(LANGUAGE_TO_LOCALE).find(language => locale === LANGUAGE_TO_LOCALE[language]) ??
Language.english

return language
}

/**
* Gets the dictionary for a given language.
* @param language - The language to get the dictionary for.
* @returns The dictionary for the given language.
*/
export function getDictionary(language: Language) {
return TEXTS[language]
}

/**
* Gets the text for a given key, with optional replacements.
* @param dictionary - The dictionary to get the text from.
* @param key - The key of the text to get.
* @param replacements - The replacements to insert into the text.
* If the text contains placeholders like `$0`, `$1`, etc.,
* they will be replaced with the corresponding replacement.
*/
export const getText: GetText = (dictionary, key, ...replacements) => {
const template = dictionary[key]

return replacements.length === 0 ?
template
: template.replace(/[$]([$]|\d+)/g, (_match, placeholder: string) =>
placeholder === '$' ? '$' : String(replacements[Number(placeholder)] ?? `$${placeholder}`),
)
}
7 changes: 7 additions & 0 deletions app/gui/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ declare global {
* ATM only affects the framer-motion animations.
*/
readonly DISABLE_ANIMATIONS?: boolean
readonly featureFlags: FeatureFlags
readonly setFeatureFlags: (flags: Partial<FeatureFlags>) => void
/**
* Feature flags that override the default or stored feature flags.
* This is used by integration tests to set feature flags.
*/
readonly overrideFeatureFlags: Partial<FeatureFlags>
}

namespace NodeJS {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ function locateAssetRows(page: Page) {

/** Find assets table placeholder rows. */
function locateNonAssetRows(page: Page) {
return locateAssetsTable(page).locator('tbody tr:not([data-testid="asset-row"])')
return locateAssetsTable(page).locator(
'tbody tr:not([data-testid="asset-row"]):not([data-testid="dummy-row"])',
)
}

/** Find a "new secret" icon. */
Expand Down
Loading

0 comments on commit 5777fa6

Please sign in to comment.