Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show relative date in ocDatePicker #11534

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@
v-bind="$attrs"
:label="label"
type="date"
class="oc-date-picker"
:min="minDate?.toISODate()"
:fix-message-line="true"
:error-message="errorMessage"
:clear-button-enabled="isClearable"
:clear-button-accessible-label="$gettext('Clear date')"
class="oc-date-picker"
:error-message="inputErrorMessage"
:description-message="inputDescriptionMessage"
/>
</template>

<script lang="ts">
import { computed, defineComponent, onMounted, PropType, ref, unref, watch } from 'vue'
import { useGettext } from 'vue3-gettext'
import { DateTime } from 'luxon'

export default defineComponent({
name: 'OcDatepicker',
status: 'ready',
Expand All @@ -25,7 +27,8 @@ export default defineComponent({
label: { type: String, required: true },
isClearable: { type: Boolean, default: true },
currentDate: { type: Object as PropType<DateTime>, required: false, default: null },
minDate: { type: Object as PropType<DateTime>, required: false, default: null }
minDate: { type: Object as PropType<DateTime>, required: false, default: null },
errorMessage: { type: String, required: false, default: '' }
},
emits: ['dateChanged'],
setup(props, { emit }) {
Expand All @@ -37,14 +40,28 @@ export default defineComponent({
return date.isValid ? date : null
})

const inputDescriptionMessage = computed(() => {
if (!unref(date) || unref(inputErrorMessage)) {
return ''
}

return unref(date)
.setLocale((current || '').split('_')[0])
.toRelative()
})

const isMinDateUndercut = computed(() => {
if (!props.minDate || !unref(date)) {
return false
}
return unref(date) < props.minDate
})

const errorMessage = computed(() => {
const inputErrorMessage = computed(() => {
if (props.errorMessage) {
return props.errorMessage
}

if (unref(isMinDateUndercut)) {
return $gettext('The date must be after %{date}', {
date: props.minDate
Expand Down Expand Up @@ -74,7 +91,8 @@ export default defineComponent({

return {
dateInputString,
errorMessage
inputDescriptionMessage,
inputErrorMessage
}
}
})
Expand Down
5 changes: 2 additions & 3 deletions packages/web-pkg/src/components/CreateLinkModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
type="password"
:password-policy="!selectedLinkTypeIsInternal ? passwordPolicy : null"
:generate-password-method="generatePasswordMethod"
:error-message="password.error"
:description-message="
:error-message="
selectedLinkTypeIsInternal
? $gettext('Password cannot be set for internal links')
: undefined
Expand All @@ -53,7 +52,7 @@
:min-date="DateTime.now()"
:label="$gettext('Expiry date')"
:disabled="selectedLinkTypeIsInternal"
:description-message="
:error-message="
selectedLinkTypeIsInternal
? $gettext('Expiry date cannot be set for internal links')
: undefined
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.